[PATCH] c++: bogus error w/ variadic concept-id as if cond [PR98394]

Jason Merrill jason@redhat.com
Mon Nov 8 17:17:32 GMT 2021


On 11/8/21 10:35, Patrick Palka wrote:
> Here when tentatively parsing the if condition as a declaration, we try
> to treat C<1> as the start of a constrained placeholder type, which we
> quickly reject because C doesn't accept a type as its first argument.
> But since we're parsing tentatively, we shouldn't emit an error in this
> case.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for
> trunk/11?
> 
> 	PR c++/98394
> 
> gcc/cp/ChangeLog:
> 
> 	* parser.c (cp_parser_placeholder_type_specifier): Don't emit
> 	a "does not constrain a type" error when parsing tentatively.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp2a/concepts-pr98394.C: New test.
> ---
>   gcc/cp/parser.c                               |  7 +++++--
>   gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C | 14 ++++++++++++++
>   2 files changed, 19 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr98394.C
> 
> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
> index 4c2075742d6..f1498e28da4 100644
> --- a/gcc/cp/parser.c
> +++ b/gcc/cp/parser.c
> @@ -19909,8 +19909,11 @@ cp_parser_placeholder_type_specifier (cp_parser *parser, location_t loc,
>         if (!flag_concepts_ts
>   	  || !processing_template_parmlist)
>   	{
> -	  error_at (loc, "%qE does not constrain a type", DECL_NAME (con));
> -	  inform (DECL_SOURCE_LOCATION (con), "concept defined here");
> +	  if (!tentative)
> +	    {
> +	      error_at (loc, "%qE does not constrain a type", DECL_NAME (con));
> +	      inform (DECL_SOURCE_LOCATION (con), "concept defined here");
> +	    }

We probably want to cp_parser_simulate_error in the tentative case?

I also wonder why this code uses a "tentative" parameter instead of 
checking cp_parser_parsing_tentatively itself.

Jason



More information about the Gcc-patches mailing list