From: Jakub Jelinek Date: Sat, 2 Nov 2019 06:53:53 +0000 (+0100) Subject: re PR c++/89640 (g++ chokes on lambda with __attribute__) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=628be4ef7078d5fcbd0096f7b11fb9a24e4da08a;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 06a4e31578f..54ed775c2e9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-11-02 Jakub Jelinek + 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. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 516c14b5610..3ed282fd4b2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e8a3856afeb..ea529300761 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2019-11-02 Jakub Jelinek + 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. diff --git a/gcc/testsuite/g++.dg/cpp1z/attr-lambda1.C b/gcc/testsuite/g++.dg/cpp1z/attr-lambda1.C new file mode 100644 index 00000000000..f2234725b83 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/attr-lambda1.C @@ -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]] {}(); +} diff --git a/gcc/testsuite/g++.dg/ext/attr-lambda2.C b/gcc/testsuite/g++.dg/ext/attr-lambda2.C new file mode 100644 index 00000000000..2926adcc75b --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attr-lambda2.C @@ -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)) {}(); +}