Use static pointer to member when catching nullptr
authorJonathan Wakely <jwakely@redhat.com>
Wed, 20 Jul 2016 18:21:48 +0000 (19:21 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 20 Jul 2016 18:21:48 +0000 (19:21 +0100)
libstdc++-v3:

* libsupc++/pbase_type_info.cc (__pbase_type_info::__do_catch): Use
static objects for catching nullptr as pointer to member types.

gcc/testsuite:

* g++.dg/cpp0x/nullptr35.C: Change expected result for catching as
pointer to member function and also test catching by reference.

From-SVN: r238532

gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/nullptr35.C
libstdc++-v3/ChangeLog
libstdc++-v3/libsupc++/pbase_type_info.cc

index ef0270ed6e12498fb1be513ec729e322e6ab7850..1fbf173ff469f90ed35d4076f40b52f8962d98ac 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-20  Jonathan Wakely  <jwakely@redhat.com>
+
+       * g++.dg/cpp0x/nullptr35.C: Change expected result for catching as
+       pointer to member function and also test catching by reference.
+
 2016-07-20  Dominik Vogt  <vogt@linux.vnet.ibm.com>
 
        * gcc.target/s390/pr67443.c: Fix test case.
index c84966f24fe6a45511efd62c54a47eee0e7e1037..d9321145e9a3c3d307c17a250fecfe11a45a42ca 100644 (file)
@@ -39,7 +39,7 @@ int main()
           caught(4);
         throw;
       }
-    } catch (int (A::*pmf)()) {  // FIXME: currently unsupported
+    } catch (int (A::*pmf)()) {
       if (pmf == nullptr)
         caught(8);
       throw;
@@ -47,6 +47,35 @@ int main()
   } catch (nullptr_t) {
   }
 
-  if (result != 7) // should be 15
+  try {
+    try {
+      try {
+        try {
+          try {
+            throw nullptr;
+          } catch (void* const& p) {
+            if (p == nullptr)
+              caught(16);
+            throw;
+          }
+        } catch (void(* const& pf)()) {
+          if (pf == nullptr)
+            caught(32);
+          throw;
+        }
+      } catch (int A::* const& pm) {
+        if (pm == nullptr)
+          caught(64);
+        throw;
+      }
+    } catch (int (A::* const& pmf)()) {
+      if (pmf == nullptr)
+        caught(128);
+      throw;
+    }
+  } catch (nullptr_t) {
+  }
+
+  if (result != 255)
     abort ();
 }
index e2bab6330ac16b32a7ef23b8bcd7eb21734238e2..40caba1244845de36cee12ce7947fd4f849db17a 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-20  Jonathan Wakely  <jwakely@redhat.com>
+
+       * libsupc++/pbase_type_info.cc (__pbase_type_info::__do_catch): Use
+       static objects for catching nullptr as pointer to member types.
+
 2016-07-18  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        Clean up optional's comments.
index a2993e431fe7826526940fb96de9266066514bee..ff6b756519b696c910bbbdad91733958dc506899 100644 (file)
@@ -50,14 +50,16 @@ __do_catch (const type_info *thr_type,
         {
           if (__pointee->__is_function_p ())
             {
-              // A pointer-to-member-function is two words <ptr,adj> but the
-              // nullptr_t exception object at *(nullptr_t*)*thr_obj is only
-              // one word, so we can't safely return it as a PMF. FIXME.
-              return false;
+              using pmf_type = void (__pbase_type_info::*)();
+              static const pmf_type pmf = nullptr;
+              *thr_obj = const_cast<pmf_type*>(&pmf);
+              return true;
             }
           else
             {
-              *(ptrdiff_t*)*thr_obj = -1; // null pointer to data member
+              using pm_type = int __pbase_type_info::*;
+              static const pm_type pm = nullptr;
+              *thr_obj = const_cast<pm_type*>(&pm);
               return true;
             }
         }