diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index c52f90c2715..bb1499ab741 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -11391,7 +11391,12 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) omitted_parms_loc = UNKNOWN_LOCATION; } - std_attrs = cp_parser_std_attribute_spec_seq (parser); + /* GCC 8 accepted attributes here, and this is the place for standard C++11 + attributes that appertain to the function type. */ + if (cp_next_tokens_can_be_gnu_attribute_p (parser)) + gnu_attrs = cp_parser_gnu_attributes_opt (parser); + else + std_attrs = cp_parser_std_attribute_spec_seq (parser); /* Parse optional trailing return type. */ if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF)) @@ -11405,8 +11410,10 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) return_type = cp_parser_trailing_type_id (parser); } + /* Also allow GNU attributes at the very end of the declaration, the usual + place for GNU attributes. */ if (cp_next_tokens_can_be_gnu_attribute_p (parser)) - gnu_attrs = cp_parser_gnu_attributes_opt (parser); + gnu_attrs = chainon (gnu_attrs, cp_parser_gnu_attributes_opt (parser)); if (has_param_list) { diff --git a/gcc/testsuite/g++.dg/ext/attr-lambda3.C b/gcc/testsuite/g++.dg/ext/attr-lambda3.C new file mode 100644 index 00000000000..f9c3ec11fe9 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-lambda3.C @@ -0,0 +1,4 @@ +// PR c++/90333 +// { dg-do compile { target c++11 } } + +auto x = []() __attribute__((always_inline)) -> int { return 0; }