diff options
author | Jason Merrill <jason@redhat.com> | 2018-11-05 02:46:52 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2018-11-05 02:46:52 -0500 |
commit | c24c8a4b003f81734c2a94e0980008c2c24659d9 (patch) | |
tree | f6903db115aff5c17547f7a29decc584021ecb1f /gcc | |
parent | ac27459299b143bcd3998193530b8b69f682e778 (diff) | |
download | gcc-c24c8a4b003f81734c2a94e0980008c2c24659d9.zip gcc-c24c8a4b003f81734c2a94e0980008c2c24659d9.tar.gz gcc-c24c8a4b003f81734c2a94e0980008c2c24659d9.tar.bz2 |
PR c++/60503 - wrong lambda attribute syntax.
This patch fixes two issues with lambda attribute handling: First, it was in
the wrong place in the grammar. Second, it was treating attributes as
applying to the whole declaration rather than to the function type, as
specified by the standard.
* parser.c (cp_parser_lambda_declarator_opt): Fix attribute
handling.
From-SVN: r265787
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/parser.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr1.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr2.C | 5 |
4 files changed, 19 insertions, 6 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bb77e0b..7e9c0e2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-11-04 Jason Merrill <jason@redhat.com> + + PR c++/60503 - wrong lambda attribute syntax. + * parser.c (cp_parser_lambda_declarator_opt): Fix attribute + handling. + 2018-11-02 Nathan Sidwell <nathan@acm.org> * decl.c (duplicate_decls): Refactor checks. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index d01c924..5ea8e8c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -10596,8 +10596,6 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) parens.require_close (parser); - attributes = cp_parser_attributes_opt (parser); - /* In the decl-specifier-seq of the lambda-declarator, each decl-specifier shall either be mutable or constexpr. */ int declares_class_or_enum; @@ -10618,6 +10616,8 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) /* Parse optional exception specification. */ exception_spec = cp_parser_exception_specification_opt (parser); + attributes = cp_parser_std_attribute_spec_seq (parser); + /* Parse optional trailing return type. */ if (cp_lexer_next_token_is (parser->lexer, CPP_DEREF)) { @@ -10668,15 +10668,14 @@ cp_parser_lambda_declarator_opt (cp_parser* parser, tree lambda_expr) REF_QUAL_NONE, tx_qual, exception_spec, - /*late_return_type=*/NULL_TREE, + return_type, /*requires_clause*/NULL_TREE); declarator->id_loc = LAMBDA_EXPR_LOCATION (lambda_expr); - if (return_type) - declarator->u.function.late_return_type = return_type; + declarator->std_attributes = attributes; fco = grokmethod (&return_type_specs, declarator, - attributes); + NULL_TREE); if (fco != error_mark_node) { DECL_INITIALIZED_IN_CLASS_P (fco) = 1; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr1.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr1.C new file mode 100644 index 0000000..9aa6506 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr1.C @@ -0,0 +1,3 @@ +// { dg-do compile { target c++11 } } + +auto l = []() [[noreturn]] {}; // { dg-warning "ignored" } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr2.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr2.C new file mode 100644 index 0000000..82d88f3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-attr2.C @@ -0,0 +1,5 @@ +// PR c++/60503 +// { dg-do compile { target c++11 } } + +auto l = []() mutable noexcept [[ ]] {}; +auto m = []() [[ ]] mutable noexcept {}; // { dg-error "" } |