re PR c++/89640 (g++ chokes on lambda with __attribute__)

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.

From-SVN: r277741
This commit is contained in:
Jakub Jelinek 2019-11-02 07:53:53 +01:00 committed by Jakub Jelinek
parent 1afe39ac14
commit 628be4ef70
5 changed files with 34 additions and 1 deletions

View file

@ -1,5 +1,9 @@
2019-11-02 Jakub Jelinek <jakub@redhat.com>
PR c++/89640
* parser.c (cp_parser_decl_specifier_seq): Don't parse attributes
if CP_PARSER_FLAGS_ONLY_MUTABLE_OR_CONSTEXPR.
PR c++/88335 - Implement P1073R3: Immediate functions
* cp-tree.h (struct lang_decl_fn): Add immediate_fn_p bit.
(DECL_IMMEDIATE_FUNCTION_P, SET_DECL_IMMEDIATE_FUNCTION_P): Define.

View file

@ -13994,7 +13994,8 @@ cp_parser_decl_specifier_seq (cp_parser* 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);

View file

@ -1,5 +1,9 @@
2019-11-02 Jakub Jelinek <jakub@redhat.com>
PR c++/89640
* g++.dg/cpp1z/attr-lambda1.C: New test.
* g++.dg/ext/attr-lambda2.C: New test.
* c-c++-common/gomp/declare-variant-6.c: Expect construct rather than
constructor in diagnostic messages.
* c-c++-common/gomp/declare-variant-7.c: Likewise.

View file

@ -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]] {}();
}

View file

@ -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)) {}();
}