Corrected rethrow_if_nested

llvm-svn: 104943
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: a391bc13235cc52893c8470bbc4ea1794b539a3c
diff --git a/include/exception b/include/exception
index 600b548..51e8313 100644
--- a/include/exception
+++ b/include/exception
@@ -211,19 +211,19 @@
 inline
 void
 rethrow_if_nested(const _E& __e, typename enable_if<
-                                   !is_same<_E, nested_exception>::value &&
-                                   is_convertible<_E*, nested_exception*>::value
+                                   is_polymorphic<_E>::value
                                                    >::type* = 0)
 {
-    static_cast<const nested_exception&>(__e).rethrow_nested();
+    const nested_exception* __nep = dynamic_cast<const nested_exception*>(&__e);
+    if (__nep)
+        __nep->rethrow_nested();
 }
 
 template <class _E>
 inline
 void
 rethrow_if_nested(const _E& __e, typename enable_if<
-                                   is_same<_E, nested_exception>::value ||
-                                   !is_convertible<_E*, nested_exception*>::value
+                                   !is_polymorphic<_E>::value
                                                    >::type* = 0)
 {
 }