From 78cd6a63ee67ed854fbe54dd7c0a500dc138459a Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 17 Nov 2020 11:38:25 -0500 Subject: [PATCH] c++: Allow template lambdas without lambda-declarator [PR97839] Our implementation of template lambdas incorrectly requires the optional lambda-declarator. This was probably required by an early draft of generic lambdas, but now the production is [expr.prim.lambda.general]: lambda-expression: lambda-introducer lambda-declarator [opt] compound-statement lambda-introducer < template-parameter-list > requires-clause [opt] lambda-declarator [opt] compound-statement Therefore, we should accept the following test. gcc/cp/ChangeLog: PR c++/97839 * parser.c (cp_parser_lambda_declarator_opt): Don't require (). gcc/testsuite/ChangeLog: PR c++/97839 * g++.dg/cpp2a/lambda-generic8.C: New test. --- gcc/cp/parser.c | 14 ++++++-------- gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cf4e4aa1b75..ea5af709487 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10604,6 +10604,8 @@ cp_parser_trait_expr (cp_parser* parser, enum rid keyword) lambda-expression: lambda-introducer lambda-declarator [opt] compound-statement + lambda-introducer < template-parameter-list > requires-clause [opt] + lambda-declarator [opt] compound-statement Returns a representation of the expression. */ @@ -11061,13 +11063,11 @@ cp_parser_lambda_introducer (cp_parser* parser, tree lambda_expr) /* Parse the (optional) middle of a lambda expression. lambda-declarator: - < template-parameter-list [opt] > - requires-clause [opt] - ( parameter-declaration-clause [opt] ) - attribute-specifier [opt] + ( parameter-declaration-clause ) decl-specifier-seq [opt] - exception-specification [opt] - lambda-return-type-clause [opt] + noexcept-specifier [opt] + attribute-specifier-seq [opt] + trailing-return-type [opt] requires-clause [opt] LAMBDA_EXPR is the current representation of the lambda expression. */ @@ -11217,8 +11217,6 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) trailing-return-type in case of decltype. */ pop_bindings_and_leave_scope (); } - else if (template_param_list != NULL_TREE) // generate diagnostic - cp_parser_require (parser, CPP_OPEN_PAREN, RT_OPEN_PAREN); /* Create the function call operator. diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C b/gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C new file mode 100644 index 00000000000..f3c3809b36d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-generic8.C @@ -0,0 +1,9 @@ +// PR c++/97839 +// { dg-do compile { target c++20 } } +// Test that a lambda with doesn't require +// a lambda-declarator. + +int main() +{ + []{}.operator()(); +} -- 2.30.2