public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: NSDMI instantiation during overload resolution [PR110468]
@ 2023-06-29 15:22 Patrick Palka
  2023-06-29 17:43 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2023-06-29 15:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, Patrick Palka

Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
trunk/13/12?

-- >8 --

Here we find ourselves instantiating the NSDMI for A<1>::m when
computing argument conversions during overload resolution, and
thus tf_conv is set.  This causes mark_used for the constructor
used in the NSDMI to exit early and not instantiate its noexcept-spec,
leading to an ICE from nothrow_spec_p.

This patch fixes this by clearing any unusual 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.
---
 gcc/cp/init.cc                          |  4 ++++
 gcc/testsuite/g++.dg/cpp0x/noexcept79.C | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept79.C

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index af6e30f511e..f01a11c5299 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -579,6 +579,10 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain)
   /* tsubst_decl uses void_node to indicate an uninstantiated DMI.  */
   if (init == void_node)
     {
+      /* The result of NSDMI instantiation should be independent of
+	 the tsubst flags we're given.  */
+      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
index 00000000000..d1f54d14431
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/noexcept79.C
@@ -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 = {{}};
-- 
2.41.0.199.ga9e066fa63


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: NSDMI instantiation during overload resolution [PR110468]
  2023-06-29 15:22 [PATCH] c++: NSDMI instantiation during overload resolution [PR110468] Patrick Palka
@ 2023-06-29 17:43 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-06-29 17:43 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 6/29/23 11:22, Patrick Palka wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/13/12?

OK.

> -- >8 --
> 
> Here we find ourselves instantiating the NSDMI for A<1>::m when
> computing argument conversions during overload resolution, and
> thus tf_conv is set.  This causes mark_used for the constructor
> used in the NSDMI to exit early and not instantiate its noexcept-spec,
> leading to an ICE from nothrow_spec_p.
> 
> This patch fixes this by clearing any unusual 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.
> ---
>   gcc/cp/init.cc                          |  4 ++++
>   gcc/testsuite/g++.dg/cpp0x/noexcept79.C | 18 ++++++++++++++++++
>   2 files changed, 22 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp0x/noexcept79.C
> 
> diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
> index af6e30f511e..f01a11c5299 100644
> --- a/gcc/cp/init.cc
> +++ b/gcc/cp/init.cc
> @@ -579,6 +579,10 @@ maybe_instantiate_nsdmi_init (tree member, tsubst_flags_t complain)
>     /* tsubst_decl uses void_node to indicate an uninstantiated DMI.  */
>     if (init == void_node)
>       {
> +      /* The result of NSDMI instantiation should be independent of
> +	 the tsubst flags we're given.  */
> +      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
> index 00000000000..d1f54d14431
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp0x/noexcept79.C
> @@ -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 = {{}};


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-06-29 17:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-29 15:22 [PATCH] c++: NSDMI instantiation during overload resolution [PR110468] Patrick Palka
2023-06-29 17:43 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).