re PR libstdc++/64241 (make_exception_ptr returns garbage with -fno-exceptions)
authorJonathan Wakely <jwakely@redhat.com>
Fri, 12 Dec 2014 15:10:08 +0000 (15:10 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 12 Dec 2014 15:10:08 +0000 (15:10 +0000)
PR libstdc++/64241
* libsupc++/exception_ptr.h: Return empty object when exceptions are
disabled.
* testsuite/18_support/exception_ptr/64241.cc: New.

From-SVN: r218675

libstdc++-v3/ChangeLog
libstdc++-v3/libsupc++/exception_ptr.h
libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc [new file with mode: 0644]

index ba9067270aa1c09e78e1011b9b72705619195348..52f6d009353f127a193792a0f8e1b133cddc1ec1 100644 (file)
@@ -1,3 +1,10 @@
+2014-12-12  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/64241
+       * libsupc++/exception_ptr.h: Return empty object when exceptions are
+       disabled.
+       * testsuite/18_support/exception_ptr/64241.cc: New.
+
 2014-12-12  Jonathan Wakely  <jwakely@redhat.com>
 
        * include/bits/stl_iterator.h (make_reverse_iterator): LWG DR 2285.
index 9ba0de4e390929a2b91fa5727037f7db0b3b9d34..8b27359357fa9de75b6a8ee8d2cdfeb1919e9700 100644 (file)
@@ -168,16 +168,18 @@ namespace std
     exception_ptr 
     make_exception_ptr(_Ex __ex) _GLIBCXX_USE_NOEXCEPT
     {
-      __try
-       {
 #ifdef __EXCEPTIONS
+      try
+       {
          throw __ex;
-#endif
        }
-      __catch(...)
+      catch(...)
        {
          return current_exception();
        }
+#else
+      return exception_ptr();
+#endif
     }
 
   // _GLIBCXX_RESOLVE_LIB_DEFECTS
diff --git a/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc b/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc
new file mode 100644 (file)
index 0000000..c7e1433
--- /dev/null
@@ -0,0 +1,39 @@
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11 -fno-exceptions -O0" }
+
+#include <exception>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+  bool test __attribute__((unused)) = true;
+  {
+    // Put some non-zero bytes on the stack
+    void* p __attribute__((unused)) = &test;
+  }
+  std::exception_ptr p = std::make_exception_ptr(1);
+  VERIFY( p == nullptr );
+}
+
+int
+main()
+{
+  test01();
+}