On Fri, Nov 01, 2019 at 09:56:44PM +0100, Jakub Jelinek wrote: > Ah, used 8.x to test it. There have been r265787 and r269775 changes in > between. > Though > auto d = [] () mutable __attribute__((noreturn)) constexpr {}; > auto e = [] () mutable [[noreturn]] constexpr {}; > is still accepted. I bet incorrectly though, I can try to fix it in a > follow-up patch, but can remove the attribute skipping from the consteval > patch then.
Perhaps like this (untested so far)? Though, I have to wonder about the other callers of cp_parser_decl_specifier_seq, whether attributes should be accepted anywhere in between specifiers or not. 2019-11-01 Jakub Jelinek <ja...@redhat.com> PR c++/89640 * parser.c (cp_parser_decl_specifier_seq): Don't parse attributes if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR. * g++.dg/cpp1z/attr-lambda1.C: New test. * g++.dg/ext/attr-lambda2.C: New test. --- gcc/cp/parser.c.jj 2019-10-31 17:33:19.864518279 +0100 +++ gcc/cp/parser.c 2019-11-01 22:05:24.684037804 +0100 @@ -13965,7 +13965,8 @@ cp_parser_decl_specifier_seq (cp_parser* if (!start_token) start_token = token; /* Handle attributes. */ - if (cp_next_tokens_can_be_attribute_p (parser)) + if ((flags & CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR) == 0 + && cp_next_tokens_can_be_attribute_p (parser)) { /* Parse the attributes. */ tree attrs = cp_parser_attributes_opt (parser); --- gcc/testsuite/g++.dg/cpp1z/attr-lambda1.C.jj 2019-11-01 22:15:57.264378908 +0100 +++ gcc/testsuite/g++.dg/cpp1z/attr-lambda1.C 2019-11-01 22:16:11.143167034 +0100 @@ -0,0 +1,12 @@ +// PR c++/89640 +// { dg-options "-Wno-attributes" } +// { dg-do compile { target c++17 } } + +void test() { + []() mutable [[gnu::cold]] constexpr {}(); // { dg-error "expected" } + []() constexpr [[gnu::cold]] mutable {}(); // { dg-error "expected" } + []() [[gnu::cold]] mutable constexpr {}(); // { dg-error "expected" } + []() [[gnu::cold]] constexpr mutable {}(); // { dg-error "expected" } + []() mutable constexpr [[gnu::cold]] {}(); + []() constexpr mutable [[gnu::cold]] {}(); +} --- gcc/testsuite/g++.dg/ext/attr-lambda2.C.jj 2019-11-01 22:16:25.784943505 +0100 +++ gcc/testsuite/g++.dg/ext/attr-lambda2.C 2019-11-01 22:16:42.736684714 +0100 @@ -0,0 +1,12 @@ +// PR c++/89640 +// { dg-options "-Wno-attributes" } +// { dg-do compile { target c++17 } } + +void test() { + []() mutable __attribute__((cold)) constexpr {}(); // { dg-error "expected" } + []() constexpr __attribute__((cold)) mutable {}(); // { dg-error "expected" } + []() __attribute__((cold)) mutable constexpr {}(); // { dg-error "expected" } + []() __attribute__((cold)) constexpr mutable {}(); // { dg-error "expected" } + []() mutable constexpr __attribute__((cold)) {}(); + []() constexpr mutable __attribute__((cold)) {}(); +} Jakub