diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 940751b5f05..dfc9b8251a7 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -28530,7 +28530,20 @@ cp_parser_constraint_requires_parens (cp_parser *parser, bool lambda_p) case CPP_PLUS_PLUS: case CPP_MINUS_MINUS: case CPP_DOT: + /* Unenclosed postfix operator. */ + return pce_maybe_postfix; + case CPP_DEREF: + /* A primary constraint that precedes the lambda-declarator of a + lambda expression is followed by trailing return type. + + [] requires C -> void {} + + Don't try to re-parse this as a postfix expression in + C++23 and later. In C++20 ( needs to come in between but we + allow it to be omitted with pedwarn. */ + if (lambda_p) + return pce_ok; /* Unenclosed postfix operator. */ return pce_maybe_postfix; } diff --git a/gcc/testsuite/g++.dg/cpp23/lambda-specifiers2.C b/gcc/testsuite/g++.dg/cpp23/lambda-specifiers2.C new file mode 100644 index 00000000000..0cc69bebc64 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/lambda-specifiers2.C @@ -0,0 +1,7 @@ +// PR c++/99850 +// P1102R2 - Down with ()! +// { dg-do compile { target c++23 } } + +auto l = [] requires true -> void {}; +template concept C = true; +auto m = [] requires (C && ...) -> void {};