[gcc(refs/vendors/redhat/heads/gcc-8-branch)] backport: re PR c++/92648 (Handling of unknown attributes)
Jakub Jelinek
jakub@gcc.gnu.org
Thu Sep 17 16:39:31 GMT 2020
https://gcc.gnu.org/g:e9eb1e4611bc59b981f2be0d863a706e7e1d956a
commit e9eb1e4611bc59b981f2be0d863a706e7e1d956a
Author: Jakub Jelinek <jakub@redhat.com>
Date: Fri Feb 14 12:48:05 2020 +0100
backport: re PR c++/92648 (Handling of unknown attributes)
Backported from mainline
2019-11-26 Jakub Jelinek <jakub@redhat.com>
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.
Diff:
---
gcc/cp/ChangeLog | 5 +++++
gcc/cp/parser.c | 12 ++++++++++++
gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C | 7 +++++++
3 files changed, 24 insertions(+)
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index dc658330588..b7f28bb8191 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -3,6 +3,11 @@
Backported from mainline
2019-11-26 Jakub Jelinek <jakub@redhat.com>
+ 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 f523c87a9ae..cd71e149f81 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -2646,6 +2646,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 */
@@ -25400,6 +25401,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/g++.dg/cpp0x/gen-attrs-71.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-71.C
new file mode 100644
index 00000000000..7876a2fba30
--- /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" }
More information about the Gcc-cvs
mailing list