re PR c++/89914 (ICE in nothrow_spec_p, at cp/except.c:1238)
authorPaolo Carlini <paolo.carlini@oracle.com>
Mon, 8 Apr 2019 08:13:50 +0000 (08:13 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Mon, 8 Apr 2019 08:13:50 +0000 (08:13 +0000)
/cp
2019-04-08  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/89914
* semantics.c (trait_expr_value): Don't use TYPE_NOTHROW_P
when maybe_instantiate_noexcept fails.
(classtype_has_nothrow_assign_or_copy_p): Likewise.
* method.c (implicitly_declare_fn): Avoid passing error_mark_node
to build_exception_variant.

/testsuite
2019-04-08  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/89914
* g++.dg/ext/has_nothrow_constructor-3.C: New.

From-SVN: r270201

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/has_nothrow_constructor-3.C [new file with mode: 0644]

index f766f476f10fb4aca9584fc6d147907ebaa92aa3..74e2b7d95c63b36aa6c0bb2397eb3da5bfbc3b22 100644 (file)
@@ -1,3 +1,12 @@
+2019-04-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/89914
+       * semantics.c (trait_expr_value): Don't use TYPE_NOTHROW_P
+       when maybe_instantiate_noexcept fails.
+       (classtype_has_nothrow_assign_or_copy_p): Likewise.
+       * method.c (implicitly_declare_fn): Avoid passing error_mark_node
+       to build_exception_variant.
+
 2019-04-05  Marek Polacek  <polacek@redhat.com>
 
        PR c++/87145 - bogus error converting class type in template arg list.
index da9600cd14326e5c3e69a5d689338d9a1c84f258..03eea408a8fe94a780e0a5fc91463644b744c00f 100644 (file)
@@ -2061,7 +2061,14 @@ implicitly_declare_fn (special_function_kind kind, tree type,
   /* Create the function.  */
   fn_type = build_method_type_directly (type, return_type, parameter_types);
   if (raises)
-    fn_type = build_exception_variant (fn_type, raises);
+    {
+      if (raises != error_mark_node)
+       fn_type = build_exception_variant (fn_type, raises);
+      else
+       /* Can happen, eg, in C++98 mode for an ill-formed non-static data
+          member initializer (c++/89914).  */
+       gcc_assert (seen_error ());
+    }
   fn = build_lang_decl (FUNCTION_DECL, name, fn_type);
   if (kind != sfk_inheriting_constructor)
     DECL_SOURCE_LOCATION (fn) = DECL_SOURCE_LOCATION (TYPE_NAME (type));
index 408675b80992bde555ec790592bc4d1b3411554b..3ae9cf050fb8155fa3fb7f60419c26cd7b93d353 100644 (file)
@@ -9551,8 +9551,8 @@ classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
       if (copy_fn_p (fn) > 0)
        {
          saw_copy = true;
-         maybe_instantiate_noexcept (fn);
-         if (!TYPE_NOTHROW_P (TREE_TYPE (fn)))
+         if (!maybe_instantiate_noexcept (fn)
+             || !TYPE_NOTHROW_P (TREE_TYPE (fn)))
            return false;
        }
     }
@@ -9594,8 +9594,8 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
       return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2) 
              || (CLASS_TYPE_P (type1)
                  && (t = locate_ctor (type1))
-                 && (maybe_instantiate_noexcept (t),
-                     TYPE_NOTHROW_P (TREE_TYPE (t)))));
+                 && maybe_instantiate_noexcept (t)
+                 && TYPE_NOTHROW_P (TREE_TYPE (t))));
 
     case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
       type1 = strip_array_types (type1);
index bf3f0d4afa21db4585b02d91292c172bef08a7df..6bcc177ccf63ff90828f964656fc5f8fe50da783 100644 (file)
@@ -1,3 +1,8 @@
+2019-04-08  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/89914
+       * g++.dg/ext/has_nothrow_constructor-3.C: New.
+
 2019-04-07  Uroš Bizjak  <ubizjak@gmail.com>
 
        PR target/89945
diff --git a/gcc/testsuite/g++.dg/ext/has_nothrow_constructor-3.C b/gcc/testsuite/g++.dg/ext/has_nothrow_constructor-3.C
new file mode 100644 (file)
index 0000000..6306d72
--- /dev/null
@@ -0,0 +1,9 @@
+// PR c++/89914
+
+struct A
+{
+  int i = ;  // { dg-error "expected" }
+  // { dg-error "non-static data member" "" { target c++98_only } .-1 }
+};
+
+bool b = __has_nothrow_constructor (A);