[cfe-commits] [libcxx] r104943 - in /libcxx/trunk: include/exception test/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp

Howard Hinnant hhinnant at apple.com
Fri May 28 06:35:41 PDT 2010


Author: hhinnant
Date: Fri May 28 08:35:41 2010
New Revision: 104943

URL: http://llvm.org/viewvc/llvm-project?rev=104943&view=rev
Log:
Corrected rethrow_if_nested

Modified:
    libcxx/trunk/include/exception
    libcxx/trunk/test/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp

Modified: libcxx/trunk/include/exception
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/exception?rev=104943&r1=104942&r2=104943&view=diff
==============================================================================
--- libcxx/trunk/include/exception (original)
+++ libcxx/trunk/include/exception Fri May 28 08:35:41 2010
@@ -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)
 {
 }

Modified: libcxx/trunk/test/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp?rev=104943&r1=104942&r2=104943&view=diff
==============================================================================
--- libcxx/trunk/test/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp (original)
+++ libcxx/trunk/test/language.support/support.exception/except.nested/rethrow_if_nested.pass.cpp Fri May 28 08:35:41 2010
@@ -22,19 +22,18 @@
     int data_;
 public:
     explicit A(int data) : data_(data) {}
+    virtual ~A() {}
 
     friend bool operator==(const A& x, const A& y) {return x.data_ == y.data_;}
 };
 
 class B
-    : public std::nested_exception
+    : public std::nested_exception,
+      public A
 {
-    int data_;
 public:
-    explicit B(int data) : data_(data) {}
-    B(const B& b) : data_(b.data_) {}
-
-    friend bool operator==(const B& x, const B& y) {return x.data_ == y.data_;}
+    explicit B(int data) : A(data) {}
+    B(const B& b) : A(b) {}
 };
 
 int main()
@@ -56,18 +55,35 @@
         {
             throw B(5);
         }
-        catch (const B& b0)
+        catch (const B& b)
         {
             try
             {
-                B b = b0;
-                std::rethrow_if_nested(b);
-                assert(false);
+                throw b;
             }
-            catch (const B& b)
+            catch (const A& a)
             {
-                assert(b == B(5));
+                try
+                {
+                    std::rethrow_if_nested(a);
+                    assert(false);
+                }
+                catch (const B& b)
+                {
+                    assert(b == B(5));
+                }
             }
         }
     }
+    {
+        try
+        {
+            std::rethrow_if_nested(1);
+            assert(true);
+        }
+        catch (...)
+        {
+            assert(false);
+        }
+    }
 }





More information about the cfe-commits mailing list