public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] libstdc++/64241 fix std::make_exception_ptr() for -fno-exceptions
@ 2014-12-12 15:10 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2014-12-12 15:10 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 236 bytes --]

It's not clear to me that std::make_exception_ptr() is actually useful
with -fno-exceptions, but we might as well return something
well-defined rather than garbage that might crash the program.

Tested x86_64-linux, committed to trunk.

[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 2321 bytes --]

commit ab57ab82fb2f5eec3bbb081f63d7a53de26bc7c8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Dec 12 14:33:04 2014 +0000

    	PR libstdc++/64241
    	* libsupc++/exception_ptr.h: Return empty object when exceptions are
    	disabled.
    	* testsuite/18_support/exception_ptr/64241.cc: New.

diff --git a/libstdc++-v3/libsupc++/exception_ptr.h b/libstdc++-v3/libsupc++/exception_ptr.h
index 9ba0de4..8b27359 100644
--- a/libstdc++-v3/libsupc++/exception_ptr.h
+++ b/libstdc++-v3/libsupc++/exception_ptr.h
@@ -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
index 0000000..c7e1433
--- /dev/null
+++ b/libstdc++-v3/testsuite/18_support/exception_ptr/64241.cc
@@ -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();
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-12-12 15:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-12 15:10 [patch] libstdc++/64241 fix std::make_exception_ptr() for -fno-exceptions Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).