This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Handle final classes in std::throw_with_nested()


Stephan Lavavej pointed out some flaws in our std::nested_exception,
most of which I fixed with the recent rewrite for GCC 5, but I didn't
check for final classes.

Tested x86_64-linux, committed to trunk.
commit 7202d181bc2aa72432ef472ace1a37bc841b51c5
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Mon Mar 16 17:54:08 2015 +0000

    	* libsupc++/nested_exception.h: Do not try to derive from final
    	classes.
    	* testsuite/18_support/nested_exception/throw_with_nested.cc: Test
    	final class.

diff --git a/libstdc++-v3/libsupc++/nested_exception.h b/libstdc++-v3/libsupc++/nested_exception.h
index 7f7e14e..a716f75 100644
--- a/libstdc++-v3/libsupc++/nested_exception.h
+++ b/libstdc++-v3/libsupc++/nested_exception.h
@@ -108,7 +108,7 @@ namespace std
 	{ throw static_cast<_Up&&>(__t); }
     };
 
-  template<typename _Tp, bool = __is_class(_Tp)>
+  template<typename _Tp, bool = __is_class(_Tp) && !__is_final(_Tp)>
     struct _Throw_with_nested_helper : _Throw_with_nested_impl<_Tp>
     { };
 
diff --git a/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc b/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc
index f1a0e9a..7ebf3b7 100644
--- a/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc
+++ b/libstdc++-v3/testsuite/18_support/nested_exception/throw_with_nested.cc
@@ -26,6 +26,8 @@ struct derived : std::nested_exception { };
 struct not_derived { virtual ~not_derived() noexcept; };
 inline not_derived::~not_derived() noexcept = default;
 
+struct uninheritable final { };
+
 void test01() 
 {
   bool test __attribute__((unused)) = false;
@@ -72,9 +74,29 @@ void test02()
   VERIFY( test );
 }
 
+void test03()
+{
+  bool test __attribute__((unused)) = false;
+
+  try
+  {
+    std::throw_with_nested(uninheritable());
+  }
+  catch (const std::nested_exception&)
+  {
+    VERIFY( false );
+  }
+  catch(const uninheritable&)
+  {
+    test = true;
+  }
+  VERIFY( test );
+}
+
 int main()
 {
   test01();
   test02();
+  test03();
   return 0;
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]