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]

Re: C++ PATCH to implement C++0x noexcept


On 06/04/2010 06:34 PM, Jason Merrill wrote:
I noticed a couple of issues with the patch right after I checked it in...

And discussion on the core reflector suggests that we want different behavior for merging throw() and noexcept; rather than have noexcept dominate, we should just use whichever is on the definition.


Tested x86_64-pc-linux-gnu, applied to trunk.
commit 02fe61a474a4f3850bf66fd2d0e08bfef37410b5
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Sat Jun 5 04:52:07 2010 +0000

    	* typeck2.c (merge_exception_specifiers): Adjust merging of
    	throw() and noexcept(true).
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@160308 138bc75d-0d04-0410-961f-82ee72b054a4

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 93ea70d..e7b97c4 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1721,17 +1721,14 @@ merge_exception_specifiers (tree list, tree add)
 {
   if (!list || !add)
     return NULL_TREE;
-  /* A noexcept(true) spec takes precedence over a throw() spec.
+  /* For merging noexcept(true) and throw(), take the more recent one (LIST).
      A throw(type-list) spec takes precedence over a noexcept(false) spec.
      Any other noexcept-spec should only be merged with an equivalent one.
-     So the !TREE_VALUE code is correct for the latter two cases.  */
-  else if (list == noexcept_true_spec
-	   || add == noexcept_true_spec)
-    return noexcept_true_spec;
-  else if (!TREE_VALUE (list))
-    return add;
+     So the !TREE_VALUE code below is correct for all cases.  */
   else if (!TREE_VALUE (add))
     return list;
+  else if (!TREE_VALUE (list))
+    return add;
   else
     {
       tree orig_list = list;
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept06.C b/gcc/testsuite/g++.dg/cpp0x/noexcept06.C
new file mode 100644
index 0000000..b0135ac
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept06.C
@@ -0,0 +1,29 @@
+// Test that checking of a nothrow specification uses the one on the
+// definition.
+// { dg-options "-std=c++0x" }
+// { dg-do run }
+
+#include <exception>
+#include <cstdlib>
+
+void my_unexpected ()
+{
+  std::abort ();
+}
+void my_terminate ()
+{
+  std::exit (0);
+}
+
+void f() throw();
+void f() noexcept
+{
+  throw 1;
+}
+
+int main()
+{
+  std::set_terminate (my_terminate);
+  f();
+  return 1;
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept07.C b/gcc/testsuite/g++.dg/cpp0x/noexcept07.C
new file mode 100644
index 0000000..0a5773f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept07.C
@@ -0,0 +1,25 @@
+// Test that checking of a nothrow specification uses the one on the
+// definition.
+// { dg-options "-std=c++0x" }
+// { dg-do run }
+
+#include <exception>
+#include <cstdlib>
+
+void my_unexpected ()
+{
+  std::exit (0);
+}
+
+void f() noexcept;
+void f() throw()
+{
+  throw 1;
+}
+
+int main()
+{
+  std::set_unexpected (my_unexpected);
+  f();
+  return 1;
+}

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