From: Jakub Jelinek Date: Fri, 20 Dec 2019 17:01:08 +0000 (+0100) Subject: backport: re PR c++/92648 (Handling of unknown attributes) X-Git-Tag: releases/gcc-9.3.0~296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04b2ff5f756ff2da65afbf1101ac4bb1a698e9a6;p=thirdparty%2Fgcc.git backport: re PR c++/92648 (Handling of unknown attributes) Backported from mainline 2019-11-26 Jakub Jelinek PR c++/92648 * parser.c (cp_parser_std_attribute): For unknown attributes, skip balanced token seq instead of trying to parse attribute-argument-clause as expression list. * g++.dg/cpp0x/gen-attrs-71.C: New test. From-SVN: r279655 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 98aada542593..01dad30b3ef6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -3,6 +3,11 @@ Backported from mainline 2019-11-26 Jakub Jelinek + PR c++/92648 + * parser.c (cp_parser_std_attribute): For unknown attributes, + skip balanced token seq instead of trying to parse + attribute-argument-clause as expression list. + PR c++/61414 * class.c (enum_to_min_precision): New hash_map. (enum_min_precision): New function. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 91702a50324f..8b5fa4cbd5ff 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2650,6 +2650,7 @@ static bool cp_parser_init_statement_p (cp_parser *); static bool cp_parser_skip_to_closing_square_bracket (cp_parser *); +static size_t cp_parser_skip_balanced_tokens (cp_parser *, size_t); /* Concept-related syntactic transformations */ @@ -26189,6 +26190,17 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) /* A GNU attribute that takes an identifier in parameter. */ attr_flag = id_attr; + const attribute_spec *as + = lookup_attribute_spec (TREE_PURPOSE (attribute)); + if (as == NULL) + { + /* For unknown attributes, just skip balanced tokens instead of + trying to parse the arguments. */ + for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 1; n; --n) + cp_lexer_consume_token (parser->lexer); + return attribute; + } + vec = cp_parser_parenthesized_expression_list (parser, attr_flag, /*cast_p=*/false, /*allow_expansion_p=*/true, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 54cf7e5feb81..57d96f0439ca 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ Backported from mainline 2019-11-26 Jakub Jelinek + PR c++/92648 + * g++.dg/cpp0x/gen-attrs-71.C: New test. + PR c++/61414 * g++.dg/cpp0x/enum23.C: Remove xfail. * g++.dg/cpp0x/enum28.C: New test. diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C new file mode 100644 index 000000000000..7876a2fba30c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C @@ -0,0 +1,7 @@ +// PR c++/92648 +// { dg-do compile { target c++11 } } + +int a [[gnu::no_such_attribute(![!(!)!]!,;;)]]; // { dg-warning "ignored" } +int b [[no_such_namespace::nonexisting_attribute(linear(c, d : 2), reduction(*:e), linear(uval (f)))]]; // { dg-warning "ignored" } +int c [[gnu::nonexisting_attribute()]]; // { dg-warning "ignored" } +int d [[gnu::another_nonexistent_attr(1,"abcd",g+6)]]; // { dg-warning "ignored" }