[PATCH] c++: Add C++23 consteval if support - P1938R3 [PR100974]

Jakub Jelinek jakub@redhat.com
Thu Jun 10 17:25:58 GMT 2021


On Thu, Jun 10, 2021 at 04:44:09PM +0200, Jakub Jelinek wrote:
> > Maybe use cp_parser_compound_statement directly instead of this and checking
> > CPP_OPEN_BRACE above?  Either way is fine.
> 
> I thought doing it this way will provide better diagnostics for what I think
> can be a common bug - people so used to normal if not requiring compound
> statements forgetting those {}s from time to time.

What the patch currently diagnoses is:
consteval-if2.C:13:6: error: ‘if consteval’ requires compound statement
   13 |   if consteval if (true) {}     // { dg-error "'if consteval' requires compound statement" }
      |      ^~~~~~~~~
while with cp_parser_compound_statement directly it diagnoses:
consteval-if2.C:13:16: error: expected ‘{’ before ‘if’
   13 |   if consteval if (true) {}     // { dg-error "'if consteval' requires compound statement" }
      |                ^~
What do you prefer?
Dunno if the fine detail that in the grammar only one of the statements
is compound-statement and then there is a requirement that the other
statement has to be a compound-statement shouldn't affect how it is
reported.

	Jakub



More information about the Gcc-patches mailing list