From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id C4B02388E83A; Fri, 16 Apr 2021 07:35:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4B02388E83A MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8210] c++: Fix up C++23 [] <...> requires primary -> type {} parsing [PR99850] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 20eb7a1891cfd7fa85295a236cebe0322d041edd X-Git-Newrev: 784de5292c34e287c848b382b431599b818ea76e Message-Id: <20210416073514.C4B02388E83A@sourceware.org> Date: Fri, 16 Apr 2021 07:35:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2021 07:35:14 -0000 https://gcc.gnu.org/g:784de5292c34e287c848b382b431599b818ea76e commit r11-8210-g784de5292c34e287c848b382b431599b818ea76e Author: Jakub Jelinek Date: Fri Apr 16 09:34:26 2021 +0200 c++: Fix up C++23 [] <...> requires primary -> type {} parsing [PR99850] The requires clause parsing has code to suggest users wrapping non-primary expressions in (), so if it e.g. parses a primary expression and sees it is followed by ++, --, ., ( or -> among other things it will try to reparse it as assignment expression or what and if that works suggests wrapping it inside of parens. When it is requires-clause that is after etc. it already has an exception from that as ( can occur in valid C++20 expression there - starting the parameters of the lambda. In C++23 another case can occur, as the parameters with the ()s can be omitted, requires C can be followed immediately by -> which starts a trailing return type. Even in that case, we don't want to parse that as C->... 2021-04-16 Jakub Jelinek PR c++/99850 * parser.c (cp_parser_constraint_requires_parens) : If lambda_p, return pce_ok instead of pce_maybe_postfix. * g++.dg/cpp23/lambda-specifiers2.C: New test. Diff: --- gcc/cp/parser.c | 13 +++++++++++++ gcc/testsuite/g++.dg/cpp23/lambda-specifiers2.C | 7 +++++++ 2 files changed, 20 insertions(+) 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 {};