public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE during aggr CTAD for member tmpl [PR105476]
@ 2022-05-04 14:09 Patrick Palka
  2022-05-04 19:54 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Patrick Palka @ 2022-05-04 14:09 UTC (permalink / raw)
  To: gcc-patches

Here we're crashing from maybe_aggr_guide ultimately because
processing_template_decl isn't set when partially instantiating the
guide's parameter list.  This causes us to prematurely force completion
of the dependent type Visitor_functior<Fn>, which fails and results in
an unexpected error_mark_node.

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

	PR c++/105476

gcc/cp/ChangeLog:

	* pt.cc (maybe_aggr_guide): Set processing_template_decl when
	partially instantiating the guide's parameter list.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/class-deduction-aggr13.C: New test.
	* g++.dg/cpp2a/class-deduction-aggr13a.C: New test.
---
 gcc/cp/pt.cc                                   |  6 +++++-
 .../g++.dg/cpp2a/class-deduction-aggr13.C      | 11 +++++++++++
 .../g++.dg/cpp2a/class-deduction-aggr13a.C     | 18 ++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ac002907a41..2bec47dc295 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -29569,7 +29569,11 @@ maybe_aggr_guide (tree tmpl, tree init, vec<tree,va_gc> *args)
 	 PARMS, so that its template level is properly reduced and we don't get
 	 mismatches when deducing types using the guide with PARMS.  */
       if (member_template_p)
-	parms = tsubst (parms, DECL_TI_ARGS (tmpl), complain, init);
+	{
+	  ++processing_template_decl;
+	  parms = tsubst (parms, DECL_TI_ARGS (tmpl), complain, init);
+	  --processing_template_decl;
+	}
     }
   else if (TREE_CODE (init) == TREE_LIST)
     {
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C
new file mode 100644
index 00000000000..aa8032c60b5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C
@@ -0,0 +1,11 @@
+// PR c++/105476
+// { dg-do compile { target c++20 } }
+
+template<class> struct Visitor_functor;
+
+template<class> struct Events {
+  template<class... Fn> struct Visitor : Visitor_functor<Fn>::type_t... { };
+};
+
+using ev_t = Events<int>;
+ev_t::Visitor v = { {} }; // { dg-error "too many initializers" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C
new file mode 100644
index 00000000000..69ae5dd4b60
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C
@@ -0,0 +1,18 @@
+// PR c++/105476
+// { dg-do compile { target c++20 } }
+// A valid version of class-deduction-aggr13.C.
+
+template<class> struct Visitor_functor;
+
+template<> struct Visitor_functor<int> {
+  using type_t = int;
+};
+
+template<class T> struct Events {
+  template<class Fn=T> struct Visitor {
+    Visitor_functor<Fn>::type_t t;
+  };
+};
+
+using ev_t = Events<int>;
+ev_t::Visitor v = { {} };
-- 
2.36.0.44.g0f828332d5


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

* Re: [PATCH] c++: ICE during aggr CTAD for member tmpl [PR105476]
  2022-05-04 14:09 [PATCH] c++: ICE during aggr CTAD for member tmpl [PR105476] Patrick Palka
@ 2022-05-04 19:54 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-05-04 19:54 UTC (permalink / raw)
  To: Patrick Palka, gcc-patches

On 5/4/22 10:09, Patrick Palka wrote:
> Here we're crashing from maybe_aggr_guide ultimately because
> processing_template_decl isn't set when partially instantiating the
> guide's parameter list.  This causes us to prematurely force completion
> of the dependent type Visitor_functior<Fn>, which fails and results in
> an unexpected error_mark_node.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/12.2?

OK.

> 	PR c++/105476
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (maybe_aggr_guide): Set processing_template_decl when
> 	partially instantiating the guide's parameter list.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/class-deduction-aggr13.C: New test.
> 	* g++.dg/cpp2a/class-deduction-aggr13a.C: New test.
> ---
>   gcc/cp/pt.cc                                   |  6 +++++-
>   .../g++.dg/cpp2a/class-deduction-aggr13.C      | 11 +++++++++++
>   .../g++.dg/cpp2a/class-deduction-aggr13a.C     | 18 ++++++++++++++++++
>   3 files changed, 34 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index ac002907a41..2bec47dc295 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -29569,7 +29569,11 @@ maybe_aggr_guide (tree tmpl, tree init, vec<tree,va_gc> *args)
>   	 PARMS, so that its template level is properly reduced and we don't get
>   	 mismatches when deducing types using the guide with PARMS.  */
>         if (member_template_p)
> -	parms = tsubst (parms, DECL_TI_ARGS (tmpl), complain, init);
> +	{
> +	  ++processing_template_decl;
> +	  parms = tsubst (parms, DECL_TI_ARGS (tmpl), complain, init);
> +	  --processing_template_decl;
> +	}
>       }
>     else if (TREE_CODE (init) == TREE_LIST)
>       {
> diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C
> new file mode 100644
> index 00000000000..aa8032c60b5
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13.C
> @@ -0,0 +1,11 @@
> +// PR c++/105476
> +// { dg-do compile { target c++20 } }
> +
> +template<class> struct Visitor_functor;
> +
> +template<class> struct Events {
> +  template<class... Fn> struct Visitor : Visitor_functor<Fn>::type_t... { };
> +};
> +
> +using ev_t = Events<int>;
> +ev_t::Visitor v = { {} }; // { dg-error "too many initializers" }
> diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C
> new file mode 100644
> index 00000000000..69ae5dd4b60
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-aggr13a.C
> @@ -0,0 +1,18 @@
> +// PR c++/105476
> +// { dg-do compile { target c++20 } }
> +// A valid version of class-deduction-aggr13.C.
> +
> +template<class> struct Visitor_functor;
> +
> +template<> struct Visitor_functor<int> {
> +  using type_t = int;
> +};
> +
> +template<class T> struct Events {
> +  template<class Fn=T> struct Visitor {
> +    Visitor_functor<Fn>::type_t t;
> +  };
> +};
> +
> +using ev_t = Events<int>;
> +ev_t::Visitor v = { {} };


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

end of thread, other threads:[~2022-05-04 19:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04 14:09 [PATCH] c++: ICE during aggr CTAD for member tmpl [PR105476] Patrick Palka
2022-05-04 19:54 ` 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).