]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: NSDMI instantiation during overload resolution [PR110468]
authorPatrick Palka <ppalka@redhat.com>
Thu, 29 Jun 2023 20:10:18 +0000 (16:10 -0400)
committerPatrick Palka <ppalka@redhat.com>
Wed, 12 Jul 2023 19:27:07 +0000 (15:27 -0400)
Here we find ourselves instantiating the NSDMI for A<1>::m when
computing argument conversions during overload resolution, and
thus tf_conv is set.  The flag causes mark_used for the constructor
used in the NSDMI to exit early and not instantiate its noexcept-spec,
which eventually leads to an ICE from nothrow_spec_p.

This patch fixes this by clearing any special tsubst flags during
instantiation of an NSDMI, since the result should be independent of
the context that requires the instantiation.

PR c++/110468

gcc/cp/ChangeLog:

* init.cc (maybe_instantiate_nsdmi_init): Mask out all
tsubst flags except for tf_warning_or_error.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/noexcept79.C: New test.

(cherry picked from commit 9479da4515f7d019b4ef282d0e21536431c44f71)

gcc/cp/init.cc
gcc/testsuite/g++.dg/cpp0x/noexcept79.C [new file with mode: 0644]

index 36dcd70e15209e5c68954c59230d4df6b5a3d517..b32ec2ed247262ee359ec32ca4e6876dffe96dea 100644 (file)
@@ -579,6 +579,10 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain)
   tree init = DECL_INITIAL (member);
   if (init && DECL_LANG_SPECIFIC (member) && DECL_TEMPLATE_INFO (member))
     {
+      /* Clear any special tsubst flags; the result of NSDMI instantiation
+        should be independent of the substitution context.  */
+      complain &= tf_warning_or_error;
+
       init = DECL_INITIAL (DECL_TI_TEMPLATE (member));
       location_t expr_loc
        = cp_expr_loc_or_loc (init, DECL_SOURCE_LOCATION (member));
diff --git a/gcc/testsuite/g++.dg/cpp0x/noexcept79.C b/gcc/testsuite/g++.dg/cpp0x/noexcept79.C
new file mode 100644 (file)
index 0000000..d1f54d1
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/110468
+// { dg-do compile { target c++11 } }
+
+template<int T>
+struct variant {
+  variant() noexcept(T > 0);
+};
+
+template<int N>
+struct A {
+  variant<N> m = {};
+};
+
+struct B {
+  B(A<1>);
+};
+
+B b = {{}};