re PR c++/68475 (ICE: in merge_exception_specifiers, at cp/typeck2.c:2115 with -fno...
authorNathan Sidwell <nathan@acm.org>
Fri, 1 Apr 2016 12:10:17 +0000 (12:10 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Fri, 1 Apr 2016 12:10:17 +0000 (12:10 +0000)
PR c++/68475
* decl.c (check_redeclaration_exception_specification): Check
regardless of -fno-exceptions.
* typeck2.c (merge_exception_specifiers): Relax assert by checking
flag_exceptions too.

* g++.dg/g++.dg/cpp0x/noexcept29.C: New.

From-SVN: r234667

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/noexcept29.C [new file with mode: 0644]

index d457acc3f3321f98d66621a9c76367b68e9a1cc0..e44818dc42dce9823897dadd790a27af1ff40aca 100644 (file)
@@ -1,3 +1,11 @@
+2016-04-01  Nathan Sidwell  <nathan@acm.org>
+
+       PR c++/68475
+       * decl.c (check_redeclaration_exception_specification): Check
+       regardless of -fno-exceptions.
+       * typeck2.c (merge_exception_specifiers): Relax assert by checking
+       flag_exceptions too.
+
 2016-03-31  Nathan Sidwell  <nathan@acm.org>
 
        * decl.c (start_preparsed_function): Remove unnecessary bracing.
index a6c585515d5aec06bed7d6da71df0377360450e6..9260f4c4254f9a7a523237ea8baffa587708aa49 100644 (file)
@@ -1202,16 +1202,19 @@ check_redeclaration_exception_specification (tree new_decl,
      specialization, of that function shall have an
      exception-specification with the same set of type-ids.  */
   if (! DECL_IS_BUILTIN (old_decl)
-      && flag_exceptions
       && !comp_except_specs (new_exceptions, old_exceptions, ce_normal))
     {
       const char *msg
        = "declaration of %q+F has a different exception specifier";
       bool complained = true;
-      if (! DECL_IN_SYSTEM_HEADER (old_decl))
-       error (msg, new_decl);
-      else
+      if (DECL_IN_SYSTEM_HEADER (old_decl))
        complained = pedwarn (0, OPT_Wsystem_headers, msg, new_decl);
+      else if (!flag_exceptions)
+       /* We used to silently permit mismatched eh specs with
+          -fno-exceptions, so make them a pedwarn now.  */
+       complained = pedwarn (0, OPT_Wpedantic, msg, new_decl);
+      else
+       error (msg, new_decl);
       if (complained)
        inform (0, "from previous declaration %q+F", old_decl);
     }
index 4ab77cda387cb12cf33fa2952ad4a07693cd3e3b..b921689808a174199d73bc4534c9725c1a290a0b 100644 (file)
@@ -2143,7 +2143,7 @@ merge_exception_specifiers (tree list, tree add)
     return add;
   noex = TREE_PURPOSE (list);
   gcc_checking_assert (!TREE_PURPOSE (add)
-                      || errorcount
+                      || errorcount || !flag_exceptions
                       || cp_tree_equal (noex, TREE_PURPOSE (add)));
 
   /* Combine the dynamic-exception-specifiers, if any.  */
index 8f6210a5bfadac57c2d56ad7537832a5bd2f14ff..519a926092b2467227232b4267e313f24f1cc4a5 100644 (file)
@@ -1,3 +1,5 @@
+2016-04-01  Nathan Sidwell  <nathan@acm.org>
+
 2016-04-01  Ilya Enkovich  <enkovich.gnu@gmail.com>
 
        PR target/69890
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept29.C b/gcc/testsuite/g++.dg/cpp0x/noexcept29.C
new file mode 100644 (file)
index 0000000..8b920c5
--- /dev/null
@@ -0,0 +1,19 @@
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-fno-exceptions" }
+
+// PR68475 we used to not check eh spec matching with -fno-exceptions,
+// but this could lead to ICEs.
+
+template <typename> struct traits;
+
+template <typename T> struct X
+{
+  void Foo () noexcept (traits <T>::foo ()); // { dg-message "previous declaration" }
+};
+
+template <typename T>
+void
+X<T>::Foo () noexcept (traits <T>::bar ()) // { dg-error "different exception specifier" }
+{
+}
+