public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
@ 2023-04-22  6:25 Nathaniel Shead
  2023-05-27  7:07 ` ping: " Nathaniel Shead
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Nathaniel Shead @ 2023-04-22  6:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathaniel Shead

Bootstrapped and tested on x86_64-pc-linux-gnu.

-- 8< --

This patch raises an error early when the decltype(auto) specifier is
used as a parameter of a function. This prevents any issues with an
unexpected tree type later on when performing the call.

	PR 103497

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_simple_type_specifier): Add check for
	decltype(auto) as function parameter.

gcc/testsuite/ChangeLog:

	* g++.dg/pr103497.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/parser.cc                | 10 ++++++++++
 gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/pr103497.C

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index e5f032f2330..1415e07e152 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
       && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
     {
       type = saved_checks_value (token->u.tree_check_value);
+      /* Within a function parameter declaration, decltype(auto) is always an
+	 error.  */
+      if (parser->auto_is_implicit_function_template_parm_p
+	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
+	  && AUTO_IS_DECLTYPE (type))
+	{
+	  error_at (token->location,
+		    "cannot declare a parameter with %<decltype(auto)%>");
+	  type = error_mark_node;
+	}
       if (decl_specs)
 	{
 	  cp_parser_set_decl_spec_type (decl_specs, type,
diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
new file mode 100644
index 00000000000..bcd421c2907
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr103497.C
@@ -0,0 +1,7 @@
+// { dg-do compile { target c++14 } }
+
+void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
+
+int main() {
+  foo();
+}
-- 
2.34.1


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

* ping: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-04-22  6:25 [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Nathaniel Shead
@ 2023-05-27  7:07 ` Nathaniel Shead
  2023-06-13 10:14 ` Nathaniel Shead
  2023-06-23 15:59 ` Patrick Palka
  2 siblings, 0 replies; 9+ messages in thread
From: Nathaniel Shead @ 2023-05-27  7:07 UTC (permalink / raw)
  To: gcc-patches

Ping: https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616465.html

On Sat, Apr 22, 2023 at 04:25:13PM +1000, Nathaniel Shead wrote:
> Bootstrapped and tested on x86_64-pc-linux-gnu.
> 
> -- 8< --
> 
> This patch raises an error early when the decltype(auto) specifier is
> used as a parameter of a function. This prevents any issues with an
> unexpected tree type later on when performing the call.
> 
> 	PR 103497
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_simple_type_specifier): Add check for
> 	decltype(auto) as function parameter.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/pr103497.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>  gcc/cp/parser.cc                | 10 ++++++++++
>  gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
>  2 files changed, 17 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index e5f032f2330..1415e07e152 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>        && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
>      {
>        type = saved_checks_value (token->u.tree_check_value);
> +      /* Within a function parameter declaration, decltype(auto) is always an
> +	 error.  */
> +      if (parser->auto_is_implicit_function_template_parm_p
> +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
> +	  && AUTO_IS_DECLTYPE (type))
> +	{
> +	  error_at (token->location,
> +		    "cannot declare a parameter with %<decltype(auto)%>");
> +	  type = error_mark_node;
> +	}
>        if (decl_specs)
>  	{
>  	  cp_parser_set_decl_spec_type (decl_specs, type,
> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> new file mode 100644
> index 00000000000..bcd421c2907
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr103497.C
> @@ -0,0 +1,7 @@
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
> +
> +int main() {
> +  foo();
> +}
> -- 
> 2.34.1
> 

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

* [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-04-22  6:25 [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Nathaniel Shead
  2023-05-27  7:07 ` ping: " Nathaniel Shead
@ 2023-06-13 10:14 ` Nathaniel Shead
  2023-06-23 15:59 ` Patrick Palka
  2 siblings, 0 replies; 9+ messages in thread
From: Nathaniel Shead @ 2023-06-13 10:14 UTC (permalink / raw)
  To: gcc-patches

(Another) ping.

https://gcc.gnu.org/pipermail/gcc-patches/2023-April/616465.html

On Sat, Apr 22, 2023 at 04:25:13PM +1000, Nathaniel Shead wrote:
> Bootstrapped and tested on x86_64-pc-linux-gnu.
> 
> -- 8< --
> 
> This patch raises an error early when the decltype(auto) specifier is
> used as a parameter of a function. This prevents any issues with an
> unexpected tree type later on when performing the call.
> 
> 	PR 103497
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_simple_type_specifier): Add check for
> 	decltype(auto) as function parameter.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/pr103497.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>  gcc/cp/parser.cc                | 10 ++++++++++
>  gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
>  2 files changed, 17 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index e5f032f2330..1415e07e152 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>        && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
>      {
>        type = saved_checks_value (token->u.tree_check_value);
> +      /* Within a function parameter declaration, decltype(auto) is always an
> +	 error.  */
> +      if (parser->auto_is_implicit_function_template_parm_p
> +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
> +	  && AUTO_IS_DECLTYPE (type))
> +	{
> +	  error_at (token->location,
> +		    "cannot declare a parameter with %<decltype(auto)%>");
> +	  type = error_mark_node;
> +	}
>        if (decl_specs)
>  	{
>  	  cp_parser_set_decl_spec_type (decl_specs, type,
> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> new file mode 100644
> index 00000000000..bcd421c2907
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr103497.C
> @@ -0,0 +1,7 @@
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
> +
> +int main() {
> +  foo();
> +}
> -- 
> 2.34.1
> 

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

* Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-04-22  6:25 [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Nathaniel Shead
  2023-05-27  7:07 ` ping: " Nathaniel Shead
  2023-06-13 10:14 ` Nathaniel Shead
@ 2023-06-23 15:59 ` Patrick Palka
  2023-06-24 13:24   ` Nathaniel Shead
  2 siblings, 1 reply; 9+ messages in thread
From: Patrick Palka @ 2023-06-23 15:59 UTC (permalink / raw)
  To: Nathaniel Shead; +Cc: gcc-patches, jason

Hi,

On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote:

> Bootstrapped and tested on x86_64-pc-linux-gnu.
> 
> -- 8< --
> 
> This patch raises an error early when the decltype(auto) specifier is
> used as a parameter of a function. This prevents any issues with an
> unexpected tree type later on when performing the call.

Thanks very much for the patch!  Some minor comments below.

> 
> 	PR 103497

We should include the bug component name when referring to the PR in the
commit message (i.e. PR c++/103497) so that upon pushing the patch the
post-commit hook automatically adds a comment to the PR reffering to the
commit.  I could be wrong but AFAIK the hook only performs this when the
component name is included.

> 
> gcc/cp/ChangeLog:
> 
> 	* parser.cc (cp_parser_simple_type_specifier): Add check for
> 	decltype(auto) as function parameter.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/pr103497.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>  gcc/cp/parser.cc                | 10 ++++++++++
>  gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
>  2 files changed, 17 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> 
> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> index e5f032f2330..1415e07e152 100644
> --- a/gcc/cp/parser.cc
> +++ b/gcc/cp/parser.cc
> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>        && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
>      {
>        type = saved_checks_value (token->u.tree_check_value);
> +      /* Within a function parameter declaration, decltype(auto) is always an
> +	 error.  */
> +      if (parser->auto_is_implicit_function_template_parm_p
> +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM

We could check is_auto (type) here instead, to avoid any confusion with
checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM.

> +	  && AUTO_IS_DECLTYPE (type))
> +	{
> +	  error_at (token->location,
> +		    "cannot declare a parameter with %<decltype(auto)%>");
> +	  type = error_mark_node;
> +	}
>        if (decl_specs)
>  	{
>  	  cp_parser_set_decl_spec_type (decl_specs, type,
> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> new file mode 100644
> index 00000000000..bcd421c2907
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/pr103497.C
> @@ -0,0 +1,7 @@
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }

I noticed for

  void foo(decltype(auto) arg);

we already issue an identical error from grokdeclarator.  Perhaps we could
instead extend the error handling there to detect decltype(auto)... as well,
rather than adding new error handling in cp_parser_simple_type_specifier?

> +
> +int main() {
> +  foo();
> +}
> -- 
> 2.34.1
> 
> 


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

* Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-06-23 15:59 ` Patrick Palka
@ 2023-06-24 13:24   ` Nathaniel Shead
  2023-06-28 17:54     ` Patrick Palka
  2023-06-29 17:43     ` Jason Merrill
  0 siblings, 2 replies; 9+ messages in thread
From: Nathaniel Shead @ 2023-06-24 13:24 UTC (permalink / raw)
  To: Patrick Palka; +Cc: gcc-patches, jason

On Fri, Jun 23, 2023 at 11:59:51AM -0400, Patrick Palka wrote:
> Hi,
> 
> On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote:
> 
> > Bootstrapped and tested on x86_64-pc-linux-gnu.
> > 
> > -- 8< --
> > 
> > This patch raises an error early when the decltype(auto) specifier is
> > used as a parameter of a function. This prevents any issues with an
> > unexpected tree type later on when performing the call.
> 
> Thanks very much for the patch!  Some minor comments below.
> 
> > 
> > 	PR 103497
> 
> We should include the bug component name when referring to the PR in the
> commit message (i.e. PR c++/103497) so that upon pushing the patch the
> post-commit hook automatically adds a comment to the PR reffering to the
> commit.  I could be wrong but AFAIK the hook only performs this when the
> component name is included.

Thanks for the review! Fixed.

> > 
> > gcc/cp/ChangeLog:
> > 
> > 	* parser.cc (cp_parser_simple_type_specifier): Add check for
> > 	decltype(auto) as function parameter.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 	* g++.dg/pr103497.C: New test.
> > 
> > Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> > ---
> >  gcc/cp/parser.cc                | 10 ++++++++++
> >  gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
> >  2 files changed, 17 insertions(+)
> >  create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> > 
> > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> > index e5f032f2330..1415e07e152 100644
> > --- a/gcc/cp/parser.cc
> > +++ b/gcc/cp/parser.cc
> > @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
> >        && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
> >      {
> >        type = saved_checks_value (token->u.tree_check_value);
> > +      /* Within a function parameter declaration, decltype(auto) is always an
> > +	 error.  */
> > +      if (parser->auto_is_implicit_function_template_parm_p
> > +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
> 
> We could check is_auto (type) here instead, to avoid any confusion with
> checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM.
> 
> > +	  && AUTO_IS_DECLTYPE (type))
> > +	{
> > +	  error_at (token->location,
> > +		    "cannot declare a parameter with %<decltype(auto)%>");
> > +	  type = error_mark_node;
> > +	}
> >        if (decl_specs)
> >  	{
> >  	  cp_parser_set_decl_spec_type (decl_specs, type,
> > diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> > new file mode 100644
> > index 00000000000..bcd421c2907
> > --- /dev/null
> > +++ b/gcc/testsuite/g++.dg/pr103497.C
> > @@ -0,0 +1,7 @@
> > +// { dg-do compile { target c++14 } }
> > +
> > +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
> 
> I noticed for
> 
>   void foo(decltype(auto) arg);
> 
> we already issue an identical error from grokdeclarator.  Perhaps we could
> instead extend the error handling there to detect decltype(auto)... as well,
> rather than adding new error handling in cp_parser_simple_type_specifier?

Ah thanks, I didn't notice this; this simplifies the change a fair bit.
How about this patch instead?

Regtested on x86_64-pc-linux-gnu.

-- 8< --

This patch ensures that checks for usages of 'auto' in function
parameters also consider parameter packs, since 'type_uses_auto' does
not seem to consider this case.

	PR c++/103497

gcc/cp/ChangeLog:

	* decl.cc (grokdeclarator): Check for decltype(auto) in
	parameter pack.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/decltype-auto-103497.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/decl.cc                                    | 3 +++
 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
 2 files changed, 11 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 60f107d50c4..aaf691fce68 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -14044,6 +14044,9 @@ grokdeclarator (const cp_declarator *declarator,
 	error ("cannot use %<::%> in parameter declaration");
 
       tree auto_node = type_uses_auto (type);
+      if (!auto_node && parameter_pack_p)
+	auto_node = type_uses_auto (PACK_EXPANSION_PATTERN (type));
+
       if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
 	{
 	  if (cxx_dialect >= cxx14)
diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
new file mode 100644
index 00000000000..cedd661710c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
@@ -0,0 +1,8 @@
+// PR c++/103497
+// { dg-do compile { target c++14 } }
+
+void foo(decltype(auto)... args);  // { dg-error "cannot declare a parameter with .decltype.auto.." }
+
+int main() {
+  foo();
+}
-- 
2.41.0


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

* Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-06-24 13:24   ` Nathaniel Shead
@ 2023-06-28 17:54     ` Patrick Palka
  2023-06-29 17:43     ` Jason Merrill
  1 sibling, 0 replies; 9+ messages in thread
From: Patrick Palka @ 2023-06-28 17:54 UTC (permalink / raw)
  To: Nathaniel Shead; +Cc: gcc-patches, jason

On Sat, Jun 24, 2023 at 9:24 AM Nathaniel Shead
<nathanieloshead@gmail.com> wrote:
>
> On Fri, Jun 23, 2023 at 11:59:51AM -0400, Patrick Palka wrote:
> > Hi,
> >
> > On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote:
> >
> > > Bootstrapped and tested on x86_64-pc-linux-gnu.
> > >
> > > -- 8< --
> > >
> > > This patch raises an error early when the decltype(auto) specifier is
> > > used as a parameter of a function. This prevents any issues with an
> > > unexpected tree type later on when performing the call.
> >
> > Thanks very much for the patch!  Some minor comments below.
> >
> > >
> > >     PR 103497
> >
> > We should include the bug component name when referring to the PR in the
> > commit message (i.e. PR c++/103497) so that upon pushing the patch the
> > post-commit hook automatically adds a comment to the PR reffering to the
> > commit.  I could be wrong but AFAIK the hook only performs this when the
> > component name is included.
>
> Thanks for the review! Fixed.
>
> > >
> > > gcc/cp/ChangeLog:
> > >
> > >     * parser.cc (cp_parser_simple_type_specifier): Add check for
> > >     decltype(auto) as function parameter.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > >     * g++.dg/pr103497.C: New test.
> > >
> > > Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> > > ---
> > >  gcc/cp/parser.cc                | 10 ++++++++++
> > >  gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
> > >  2 files changed, 17 insertions(+)
> > >  create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> > >
> > > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> > > index e5f032f2330..1415e07e152 100644
> > > --- a/gcc/cp/parser.cc
> > > +++ b/gcc/cp/parser.cc
> > > @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
> > >        && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
> > >      {
> > >        type = saved_checks_value (token->u.tree_check_value);
> > > +      /* Within a function parameter declaration, decltype(auto) is always an
> > > +    error.  */
> > > +      if (parser->auto_is_implicit_function_template_parm_p
> > > +     && TREE_CODE (type) == TEMPLATE_TYPE_PARM
> >
> > We could check is_auto (type) here instead, to avoid any confusion with
> > checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM.
> >
> > > +     && AUTO_IS_DECLTYPE (type))
> > > +   {
> > > +     error_at (token->location,
> > > +               "cannot declare a parameter with %<decltype(auto)%>");
> > > +     type = error_mark_node;
> > > +   }
> > >        if (decl_specs)
> > >     {
> > >       cp_parser_set_decl_spec_type (decl_specs, type,
> > > diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> > > new file mode 100644
> > > index 00000000000..bcd421c2907
> > > --- /dev/null
> > > +++ b/gcc/testsuite/g++.dg/pr103497.C
> > > @@ -0,0 +1,7 @@
> > > +// { dg-do compile { target c++14 } }
> > > +
> > > +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
> >
> > I noticed for
> >
> >   void foo(decltype(auto) arg);
> >
> > we already issue an identical error from grokdeclarator.  Perhaps we could
> > instead extend the error handling there to detect decltype(auto)... as well,
> > rather than adding new error handling in cp_parser_simple_type_specifier?
>
> Ah thanks, I didn't notice this; this simplifies the change a fair bit.
> How about this patch instead?

LGTM! Though I can't approve the patch myself.

>
> Regtested on x86_64-pc-linux-gnu.
>
> -- 8< --
>
> This patch ensures that checks for usages of 'auto' in function
> parameters also consider parameter packs, since 'type_uses_auto' does
> not seem to consider this case.
>
>         PR c++/103497
>
> gcc/cp/ChangeLog:
>
>         * decl.cc (grokdeclarator): Check for decltype(auto) in
>         parameter pack.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/cpp1y/decltype-auto-103497.C: New test.
>
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>  gcc/cp/decl.cc                                    | 3 +++
>  gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
>  2 files changed, 11 insertions(+)
>  create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 60f107d50c4..aaf691fce68 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -14044,6 +14044,9 @@ grokdeclarator (const cp_declarator *declarator,
>         error ("cannot use %<::%> in parameter declaration");
>
>        tree auto_node = type_uses_auto (type);
> +      if (!auto_node && parameter_pack_p)
> +       auto_node = type_uses_auto (PACK_EXPANSION_PATTERN (type));
> +
>        if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
>         {
>           if (cxx_dialect >= cxx14)
> diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> new file mode 100644
> index 00000000000..cedd661710c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> @@ -0,0 +1,8 @@
> +// PR c++/103497
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "cannot declare a parameter with .decltype.auto.." }
> +
> +int main() {
> +  foo();
> +}
> --
> 2.41.0
>


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

* Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-06-24 13:24   ` Nathaniel Shead
  2023-06-28 17:54     ` Patrick Palka
@ 2023-06-29 17:43     ` Jason Merrill
  2023-06-30  7:05       ` Nathaniel Shead
  1 sibling, 1 reply; 9+ messages in thread
From: Jason Merrill @ 2023-06-29 17:43 UTC (permalink / raw)
  To: Nathaniel Shead, Patrick Palka; +Cc: gcc-patches

On 6/24/23 09:24, Nathaniel Shead wrote:
> On Fri, Jun 23, 2023 at 11:59:51AM -0400, Patrick Palka wrote:
>> Hi,
>>
>> On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote:
>>
>>> Bootstrapped and tested on x86_64-pc-linux-gnu.
>>>
>>> -- 8< --
>>>
>>> This patch raises an error early when the decltype(auto) specifier is
>>> used as a parameter of a function. This prevents any issues with an
>>> unexpected tree type later on when performing the call.
>>
>> Thanks very much for the patch!  Some minor comments below.
>>
>>>
>>> 	PR 103497
>>
>> We should include the bug component name when referring to the PR in the
>> commit message (i.e. PR c++/103497) so that upon pushing the patch the
>> post-commit hook automatically adds a comment to the PR reffering to the
>> commit.  I could be wrong but AFAIK the hook only performs this when the
>> component name is included.
> 
> Thanks for the review! Fixed.
> 
>>>
>>> gcc/cp/ChangeLog:
>>>
>>> 	* parser.cc (cp_parser_simple_type_specifier): Add check for
>>> 	decltype(auto) as function parameter.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 	* g++.dg/pr103497.C: New test.
>>>
>>> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
>>> ---
>>>   gcc/cp/parser.cc                | 10 ++++++++++
>>>   gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
>>>   2 files changed, 17 insertions(+)
>>>   create mode 100644 gcc/testsuite/g++.dg/pr103497.C
>>>
>>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
>>> index e5f032f2330..1415e07e152 100644
>>> --- a/gcc/cp/parser.cc
>>> +++ b/gcc/cp/parser.cc
>>> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>>>         && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
>>>       {
>>>         type = saved_checks_value (token->u.tree_check_value);
>>> +      /* Within a function parameter declaration, decltype(auto) is always an
>>> +	 error.  */
>>> +      if (parser->auto_is_implicit_function_template_parm_p
>>> +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
>>
>> We could check is_auto (type) here instead, to avoid any confusion with
>> checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM.
>>
>>> +	  && AUTO_IS_DECLTYPE (type))
>>> +	{
>>> +	  error_at (token->location,
>>> +		    "cannot declare a parameter with %<decltype(auto)%>");
>>> +	  type = error_mark_node;
>>> +	}
>>>         if (decl_specs)
>>>   	{
>>>   	  cp_parser_set_decl_spec_type (decl_specs, type,
>>> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
>>> new file mode 100644
>>> index 00000000000..bcd421c2907
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/pr103497.C
>>> @@ -0,0 +1,7 @@
>>> +// { dg-do compile { target c++14 } }
>>> +
>>> +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
>>
>> I noticed for
>>
>>    void foo(decltype(auto) arg);
>>
>> we already issue an identical error from grokdeclarator.  Perhaps we could
>> instead extend the error handling there to detect decltype(auto)... as well,
>> rather than adding new error handling in cp_parser_simple_type_specifier?
> 
> Ah thanks, I didn't notice this; this simplifies the change a fair bit.
> How about this patch instead?
> 
> Regtested on x86_64-pc-linux-gnu.
> 
> -- 8< --
> 
> This patch ensures that checks for usages of 'auto' in function
> parameters also consider parameter packs, since 'type_uses_auto' does
> not seem to consider this case.
> 
> 	PR c++/103497
> 
> gcc/cp/ChangeLog:
> 
> 	* decl.cc (grokdeclarator): Check for decltype(auto) in
> 	parameter pack.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp1y/decltype-auto-103497.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>   gcc/cp/decl.cc                                    | 3 +++
>   gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
>   2 files changed, 11 insertions(+)
>   create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> 
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 60f107d50c4..aaf691fce68 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -14044,6 +14044,9 @@ grokdeclarator (const cp_declarator *declarator,
>   	error ("cannot use %<::%> in parameter declaration");
>   
>         tree auto_node = type_uses_auto (type);
> +      if (!auto_node && parameter_pack_p)
> +	auto_node = type_uses_auto (PACK_EXPANSION_PATTERN (type));

Hmm, I wonder if type_uses_auto should look into PACK_EXPANSION_PATTERN 
itself.  Would that break anything?

> +
>         if (auto_node && !(cxx_dialect >= cxx17 && template_parm_flag))
>   	{
>   	  if (cxx_dialect >= cxx14)
> diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> new file mode 100644
> index 00000000000..cedd661710c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> @@ -0,0 +1,8 @@
> +// PR c++/103497
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "cannot declare a parameter with .decltype.auto.." }
> +
> +int main() {
> +  foo();
> +}


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

* [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-06-29 17:43     ` Jason Merrill
@ 2023-06-30  7:05       ` Nathaniel Shead
  2023-07-27  3:47         ` Jason Merrill
  0 siblings, 1 reply; 9+ messages in thread
From: Nathaniel Shead @ 2023-06-30  7:05 UTC (permalink / raw)
  To: Jason Merrill; +Cc: Patrick Palka, gcc-patches

On Thu, Jun 29, 2023 at 01:43:07PM -0400, Jason Merrill wrote:
> On 6/24/23 09:24, Nathaniel Shead wrote:
> > On Fri, Jun 23, 2023 at 11:59:51AM -0400, Patrick Palka wrote:
> > > Hi,
> > > 
> > > On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote:
> > > 
> > > > Bootstrapped and tested on x86_64-pc-linux-gnu.
> > > > 
> > > > -- 8< --
> > > > 
> > > > This patch raises an error early when the decltype(auto) specifier is
> > > > used as a parameter of a function. This prevents any issues with an
> > > > unexpected tree type later on when performing the call.
> > > 
> > > Thanks very much for the patch!  Some minor comments below.
> > > 
> > > > 
> > > > 	PR 103497
> > > 
> > > We should include the bug component name when referring to the PR in the
> > > commit message (i.e. PR c++/103497) so that upon pushing the patch the
> > > post-commit hook automatically adds a comment to the PR reffering to the
> > > commit.  I could be wrong but AFAIK the hook only performs this when the
> > > component name is included.
> > 
> > Thanks for the review! Fixed.
> > 
> > > > 
> > > > gcc/cp/ChangeLog:
> > > > 
> > > > 	* parser.cc (cp_parser_simple_type_specifier): Add check for
> > > > 	decltype(auto) as function parameter.
> > > > 
> > > > gcc/testsuite/ChangeLog:
> > > > 
> > > > 	* g++.dg/pr103497.C: New test.
> > > > 
> > > > Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> > > > ---
> > > >   gcc/cp/parser.cc                | 10 ++++++++++
> > > >   gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
> > > >   2 files changed, 17 insertions(+)
> > > >   create mode 100644 gcc/testsuite/g++.dg/pr103497.C
> > > > 
> > > > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
> > > > index e5f032f2330..1415e07e152 100644
> > > > --- a/gcc/cp/parser.cc
> > > > +++ b/gcc/cp/parser.cc
> > > > @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
> > > >         && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
> > > >       {
> > > >         type = saved_checks_value (token->u.tree_check_value);
> > > > +      /* Within a function parameter declaration, decltype(auto) is always an
> > > > +	 error.  */
> > > > +      if (parser->auto_is_implicit_function_template_parm_p
> > > > +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
> > > 
> > > We could check is_auto (type) here instead, to avoid any confusion with
> > > checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM.
> > > 
> > > > +	  && AUTO_IS_DECLTYPE (type))
> > > > +	{
> > > > +	  error_at (token->location,
> > > > +		    "cannot declare a parameter with %<decltype(auto)%>");
> > > > +	  type = error_mark_node;
> > > > +	}
> > > >         if (decl_specs)
> > > >   	{
> > > >   	  cp_parser_set_decl_spec_type (decl_specs, type,
> > > > diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
> > > > new file mode 100644
> > > > index 00000000000..bcd421c2907
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/g++.dg/pr103497.C
> > > > @@ -0,0 +1,7 @@
> > > > +// { dg-do compile { target c++14 } }
> > > > +
> > > > +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
> > > 
> > > I noticed for
> > > 
> > >    void foo(decltype(auto) arg);
> > > 
> > > we already issue an identical error from grokdeclarator.  Perhaps we could
> > > instead extend the error handling there to detect decltype(auto)... as well,
> > > rather than adding new error handling in cp_parser_simple_type_specifier?
> > 
> > Ah thanks, I didn't notice this; this simplifies the change a fair bit.
> > How about this patch instead?
> > 
> > Regtested on x86_64-pc-linux-gnu.
> > 
> > -- 8< --
> > 
> > This patch ensures that checks for usages of 'auto' in function
> > parameters also consider parameter packs, since 'type_uses_auto' does
> > not seem to consider this case.
> > 
> > 	PR c++/103497
> > 
> > gcc/cp/ChangeLog:
> > 
> > 	* decl.cc (grokdeclarator): Check for decltype(auto) in
> > 	parameter pack.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 	* g++.dg/cpp1y/decltype-auto-103497.C: New test.
> > 
> > Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> > ---
> >   gcc/cp/decl.cc                                    | 3 +++
> >   gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
> >   2 files changed, 11 insertions(+)
> >   create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> > 
> > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> > index 60f107d50c4..aaf691fce68 100644
> > --- a/gcc/cp/decl.cc
> > +++ b/gcc/cp/decl.cc
> > @@ -14044,6 +14044,9 @@ grokdeclarator (const cp_declarator *declarator,
> >   	error ("cannot use %<::%> in parameter declaration");
> >         tree auto_node = type_uses_auto (type);
> > +      if (!auto_node && parameter_pack_p)
> > +	auto_node = type_uses_auto (PACK_EXPANSION_PATTERN (type));
> 
> Hmm, I wonder if type_uses_auto should look into PACK_EXPANSION_PATTERN
> itself.  Would that break anything?

I gave that a try and it seems to work fine.

Regtested on x86_64-pc-linux-gnu.

-- 8< --

This patch ensures 'type_uses_auto' also checks for usages of 'auto' in
parameter packs.

	PR c++/103497

gcc/cp/ChangeLog:

	* pt.cc (type_uses_auto): Check inside parameter packs.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1y/decltype-auto-103497.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
---
 gcc/cp/pt.cc                                      | 7 ++++++-
 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 2345a18becc..2a3ba5ab67d 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -31083,7 +31083,12 @@ type_uses_auto (tree type)
 {
   if (type == NULL_TREE)
     return NULL_TREE;
-  else if (flag_concepts_ts)
+
+  /* For parameter packs, check the contents of the pack.  */
+  if (PACK_EXPANSION_P (type))
+    type = PACK_EXPANSION_PATTERN (type);
+
+  if (flag_concepts_ts)
     {
       /* The Concepts TS allows multiple autos in one type-specifier; just
 	 return the first one we find, do_auto_deduction will collect all of
diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
new file mode 100644
index 00000000000..cedd661710c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
@@ -0,0 +1,8 @@
+// PR c++/103497
+// { dg-do compile { target c++14 } }
+
+void foo(decltype(auto)... args);  // { dg-error "cannot declare a parameter with .decltype.auto.." }
+
+int main() {
+  foo();
+}
-- 
2.41.0


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

* Re: [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497]
  2023-06-30  7:05       ` Nathaniel Shead
@ 2023-07-27  3:47         ` Jason Merrill
  0 siblings, 0 replies; 9+ messages in thread
From: Jason Merrill @ 2023-07-27  3:47 UTC (permalink / raw)
  To: Nathaniel Shead; +Cc: Patrick Palka, gcc-patches

On 6/30/23 03:05, Nathaniel Shead wrote:
> On Thu, Jun 29, 2023 at 01:43:07PM -0400, Jason Merrill wrote:
>> On 6/24/23 09:24, Nathaniel Shead wrote:
>>> On Fri, Jun 23, 2023 at 11:59:51AM -0400, Patrick Palka wrote:
>>>> Hi,
>>>>
>>>> On Sat, 22 Apr 2023, Nathaniel Shead via Gcc-patches wrote:
>>>>
>>>>> Bootstrapped and tested on x86_64-pc-linux-gnu.
>>>>>
>>>>> -- 8< --
>>>>>
>>>>> This patch raises an error early when the decltype(auto) specifier is
>>>>> used as a parameter of a function. This prevents any issues with an
>>>>> unexpected tree type later on when performing the call.
>>>>
>>>> Thanks very much for the patch!  Some minor comments below.
>>>>
>>>>>
>>>>> 	PR 103497
>>>>
>>>> We should include the bug component name when referring to the PR in the
>>>> commit message (i.e. PR c++/103497) so that upon pushing the patch the
>>>> post-commit hook automatically adds a comment to the PR reffering to the
>>>> commit.  I could be wrong but AFAIK the hook only performs this when the
>>>> component name is included.
>>>
>>> Thanks for the review! Fixed.
>>>
>>>>>
>>>>> gcc/cp/ChangeLog:
>>>>>
>>>>> 	* parser.cc (cp_parser_simple_type_specifier): Add check for
>>>>> 	decltype(auto) as function parameter.
>>>>>
>>>>> gcc/testsuite/ChangeLog:
>>>>>
>>>>> 	* g++.dg/pr103497.C: New test.
>>>>>
>>>>> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
>>>>> ---
>>>>>    gcc/cp/parser.cc                | 10 ++++++++++
>>>>>    gcc/testsuite/g++.dg/pr103497.C |  7 +++++++
>>>>>    2 files changed, 17 insertions(+)
>>>>>    create mode 100644 gcc/testsuite/g++.dg/pr103497.C
>>>>>
>>>>> diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
>>>>> index e5f032f2330..1415e07e152 100644
>>>>> --- a/gcc/cp/parser.cc
>>>>> +++ b/gcc/cp/parser.cc
>>>>> @@ -19884,6 +19884,16 @@ cp_parser_simple_type_specifier (cp_parser* parser,
>>>>>          && cp_lexer_peek_nth_token (parser->lexer, 2)->type != CPP_SCOPE)
>>>>>        {
>>>>>          type = saved_checks_value (token->u.tree_check_value);
>>>>> +      /* Within a function parameter declaration, decltype(auto) is always an
>>>>> +	 error.  */
>>>>> +      if (parser->auto_is_implicit_function_template_parm_p
>>>>> +	  && TREE_CODE (type) == TEMPLATE_TYPE_PARM
>>>>
>>>> We could check is_auto (type) here instead, to avoid any confusion with
>>>> checking AUTO_IS_DECLTYPE for a non-auto TEMPLATE_TYPE_PARM.
>>>>
>>>>> +	  && AUTO_IS_DECLTYPE (type))
>>>>> +	{
>>>>> +	  error_at (token->location,
>>>>> +		    "cannot declare a parameter with %<decltype(auto)%>");
>>>>> +	  type = error_mark_node;
>>>>> +	}
>>>>>          if (decl_specs)
>>>>>    	{
>>>>>    	  cp_parser_set_decl_spec_type (decl_specs, type,
>>>>> diff --git a/gcc/testsuite/g++.dg/pr103497.C b/gcc/testsuite/g++.dg/pr103497.C
>>>>> new file mode 100644
>>>>> index 00000000000..bcd421c2907
>>>>> --- /dev/null
>>>>> +++ b/gcc/testsuite/g++.dg/pr103497.C
>>>>> @@ -0,0 +1,7 @@
>>>>> +// { dg-do compile { target c++14 } }
>>>>> +
>>>>> +void foo(decltype(auto)... args);  // { dg-error "parameter with .decltype.auto..|no parameter packs" }
>>>>
>>>> I noticed for
>>>>
>>>>     void foo(decltype(auto) arg);
>>>>
>>>> we already issue an identical error from grokdeclarator.  Perhaps we could
>>>> instead extend the error handling there to detect decltype(auto)... as well,
>>>> rather than adding new error handling in cp_parser_simple_type_specifier?
>>>
>>> Ah thanks, I didn't notice this; this simplifies the change a fair bit.
>>> How about this patch instead?
>>>
>>> Regtested on x86_64-pc-linux-gnu.
>>>
>>> -- 8< --
>>>
>>> This patch ensures that checks for usages of 'auto' in function
>>> parameters also consider parameter packs, since 'type_uses_auto' does
>>> not seem to consider this case.
>>>
>>> 	PR c++/103497
>>>
>>> gcc/cp/ChangeLog:
>>>
>>> 	* decl.cc (grokdeclarator): Check for decltype(auto) in
>>> 	parameter pack.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 	* g++.dg/cpp1y/decltype-auto-103497.C: New test.
>>>
>>> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
>>> ---
>>>    gcc/cp/decl.cc                                    | 3 +++
>>>    gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
>>>    2 files changed, 11 insertions(+)
>>>    create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
>>>
>>> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
>>> index 60f107d50c4..aaf691fce68 100644
>>> --- a/gcc/cp/decl.cc
>>> +++ b/gcc/cp/decl.cc
>>> @@ -14044,6 +14044,9 @@ grokdeclarator (const cp_declarator *declarator,
>>>    	error ("cannot use %<::%> in parameter declaration");
>>>          tree auto_node = type_uses_auto (type);
>>> +      if (!auto_node && parameter_pack_p)
>>> +	auto_node = type_uses_auto (PACK_EXPANSION_PATTERN (type));
>>
>> Hmm, I wonder if type_uses_auto should look into PACK_EXPANSION_PATTERN
>> itself.  Would that break anything?
> 
> I gave that a try and it seems to work fine.
> 
> Regtested on x86_64-pc-linux-gnu.

Pushed, thanks.

> -- 8< --
> 
> This patch ensures 'type_uses_auto' also checks for usages of 'auto' in
> parameter packs.
> 
> 	PR c++/103497
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (type_uses_auto): Check inside parameter packs.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp1y/decltype-auto-103497.C: New test.
> 
> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
> ---
>   gcc/cp/pt.cc                                      | 7 ++++++-
>   gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C | 8 ++++++++
>   2 files changed, 14 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 2345a18becc..2a3ba5ab67d 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -31083,7 +31083,12 @@ type_uses_auto (tree type)
>   {
>     if (type == NULL_TREE)
>       return NULL_TREE;
> -  else if (flag_concepts_ts)
> +
> +  /* For parameter packs, check the contents of the pack.  */
> +  if (PACK_EXPANSION_P (type))
> +    type = PACK_EXPANSION_PATTERN (type);
> +
> +  if (flag_concepts_ts)
>       {
>         /* The Concepts TS allows multiple autos in one type-specifier; just
>   	 return the first one we find, do_auto_deduction will collect all of
> diff --git a/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> new file mode 100644
> index 00000000000..cedd661710c
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp1y/decltype-auto-103497.C
> @@ -0,0 +1,8 @@
> +// PR c++/103497
> +// { dg-do compile { target c++14 } }
> +
> +void foo(decltype(auto)... args);  // { dg-error "cannot declare a parameter with .decltype.auto.." }
> +
> +int main() {
> +  foo();
> +}


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

end of thread, other threads:[~2023-07-27  3:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-22  6:25 [PATCH] c++: Fix ICE with parameter pack of decltype(auto) [PR103497] Nathaniel Shead
2023-05-27  7:07 ` ping: " Nathaniel Shead
2023-06-13 10:14 ` Nathaniel Shead
2023-06-23 15:59 ` Patrick Palka
2023-06-24 13:24   ` Nathaniel Shead
2023-06-28 17:54     ` Patrick Palka
2023-06-29 17:43     ` Jason Merrill
2023-06-30  7:05       ` Nathaniel Shead
2023-07-27  3:47         ` 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).