]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/88368 - wrong 'use of deleted function'
authorJason Merrill <jason@redhat.com>
Wed, 20 Feb 2019 02:00:29 +0000 (21:00 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 20 Feb 2019 02:00:29 +0000 (21:00 -0500)
Since my patch for 81359 allowed us to signal failure on return from
maybe_instantiate_noexcept, we no longer need to turn an error into
noexcept(false).  We also need to handle NSDMI instantiation errors under
synthesized_method_walk.  This change caused some instantiation context
notes to be lost in the testsuite, so I added push_tinst_level to
get_defaulted_eh_spec to restore that context.

* method.c (walk_field_subobs): Remember errors from get_nsdmi.
(get_defaulted_eh_spec): Call push_tinst_level.
* pt.c (maybe_instantiate_noexcept): Keep error_mark_node.
* typeck2.c (merge_exception_specifiers): Handle error_mark_node.

From-SVN: r269032

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/cp/pt.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp0x/nsdmi3.C
gcc/testsuite/g++.dg/ext/is_constructible3.C [new file with mode: 0644]

index 9c42190f04a8c96e07682558d8e497c482e81cc7..3fe0cedb0e321987d1b3a7bd5ebeed92cb0ab66c 100644 (file)
@@ -1,3 +1,11 @@
+2019-02-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/88368 - wrong 'use of deleted function'
+       * method.c (walk_field_subobs): Remember errors from get_nsdmi.
+       (get_defaulted_eh_spec): Call push_tinst_level.
+       * pt.c (maybe_instantiate_noexcept): Keep error_mark_node.
+       * typeck2.c (merge_exception_specifiers): Handle error_mark_node.
+
 2019-02-19  Chung-Lin Tang <cltang@codesourcery.com>
 
        PR c/87924
index a5f2304d49c51cee2ea01b25019bca649091f405..6e0df68273efab1f0f2cebf06fcd0fcb21074424 100644 (file)
@@ -1367,7 +1367,10 @@ walk_field_subobs (tree fields, special_function_kind sfk, tree fnname,
              if (spec_p)
                {
                  tree nsdmi = get_nsdmi (field, /*ctor*/false, complain);
-                 if (!expr_noexcept_p (nsdmi, complain))
+                 if (nsdmi == error_mark_node)
+                   *spec_p = error_mark_node;
+                 else if (*spec_p != error_mark_node
+                          && !expr_noexcept_p (nsdmi, complain))
                    *spec_p = noexcept_false_spec;
                }
              /* Don't do the normal processing.  */
@@ -1753,8 +1756,13 @@ get_defaulted_eh_spec (tree decl, tsubst_flags_t complain)
   if (SFK_DTOR_P (sfk) && DECL_VIRTUAL_P (decl))
     /* We have to examine virtual bases even if abstract.  */
     sfk = sfk_virtual_destructor;
+  bool pushed = false;
+  if (CLASSTYPE_TEMPLATE_INSTANTIATION (ctype))
+    pushed = push_tinst_level (decl);
   synthesized_method_walk (ctype, sfk, const_p, &spec, NULL, NULL,
                           NULL, diag, &inh, parms);
+  if (pushed)
+    pop_tinst_level ();
   return spec;
 }
 
index d8be92ddca49a72f4746b39514609aa48e0da8d5..a69a17ad3b2b24fd00bc4a2f7903207081f981ba 100644 (file)
@@ -24199,8 +24199,6 @@ maybe_instantiate_noexcept (tree fn, tsubst_flags_t complain)
          pop_deferring_access_checks ();
          pop_access_scope (fn);
          pop_tinst_level ();
-         if (spec == error_mark_node)
-           spec = noexcept_false_spec;
        }
       else
        spec = noexcept_false_spec;
index ac2c253196b3bb2e559550b7bcbf760867e3ea81..4e4b1f03b7cda511b208ef127884fedf8c01cf07 100644 (file)
@@ -2363,6 +2363,9 @@ merge_exception_specifiers (tree list, tree add)
 {
   tree noex, orig_list;
 
+  if (list == error_mark_node || add == error_mark_node)
+    return error_mark_node;
+
   /* No exception-specifier or noexcept(false) are less strict than
      anything else.  Prefer the newer variant (LIST).  */
   if (!list || list == noexcept_false_spec)
index d2e74392487558a6140240ae904d22d618d70a14..8276eab8f8056f57614e8b74b6fd400792251ab8 100644 (file)
@@ -13,6 +13,7 @@ struct B
   A a3 = { 3 };                        // { dg-error "explicit" }
 };
 
-constexpr B b;                 // { dg-error "B::B" }
+constexpr B b;
 
+// { dg-prune-output "B::B. is not usable" }
 // { dg-prune-output "B::a1" }
diff --git a/gcc/testsuite/g++.dg/ext/is_constructible3.C b/gcc/testsuite/g++.dg/ext/is_constructible3.C
new file mode 100644 (file)
index 0000000..c7c5874
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/88368
+// { dg-do compile { target c++11 } }
+
+struct A {
+
+  struct B {
+    int I = 1;
+    B() = default;
+  };
+
+  static constexpr bool v = __is_constructible (B);
+
+};
+
+void print()  {
+  A::B BB;
+}