aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-02-11 15:29:24 -0500
committerMarek Polacek <polacek@redhat.com>2020-02-12 10:39:40 -0500
commite428a9cf85a8bdde9d031a215e10bd96eb3b789a (patch)
treef1114cb0ec663b33cfd430fac74b4857059c98ff /gcc
parent62fc0a6ce28c502fc6a7b7c09157840bf98f945f (diff)
downloadgcc-e428a9cf85a8bdde9d031a215e10bd96eb3b789a.zip
gcc-e428a9cf85a8bdde9d031a215e10bd96eb3b789a.tar.gz
gcc-e428a9cf85a8bdde9d031a215e10bd96eb3b789a.tar.bz2
c++: Fix ICE-on-invalid with broken attribute [PR93684]
We crash when parsing [[a:: because we see a CPP_SCOPE and then we're trying to consume a CPP_EOF token. So peek before consuming it. PR c++/93684 - ICE-on-invalid with broken attribute. * parser.c (cp_parser_std_attribute): Peek a token first before consuming it. * g++.dg/parse/attr4.C: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/parser.c3
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/parse/attr4.C3
4 files changed, 16 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 7567bbe..c578cdb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2020-02-12 Marek Polacek <polacek@redhat.com>
+
+ PR c++/93684 - ICE-on-invalid with broken attribute.
+ * parser.c (cp_parser_std_attribute): Peek a token first before
+ consuming it.
+
2020-02-11 Jason Merrill <jason@redhat.com>
PR c++/93675
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 640affd..e8a536a 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -26720,7 +26720,7 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns)
"with scoped attribute token");
attr_ns = attr_id;
- token = cp_lexer_consume_token (parser->lexer);
+ token = cp_lexer_peek_token (parser->lexer);
if (token->type == CPP_NAME)
attr_id = token->u.value;
else if (token->type == CPP_KEYWORD)
@@ -26733,6 +26733,7 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns)
"expected an identifier for the attribute name");
return error_mark_node;
}
+ cp_lexer_consume_token (parser->lexer);
attr_ns = canonicalize_attr_name (attr_ns);
attr_id = canonicalize_attr_name (attr_id);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 433b0af..968b903 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-02-12 Marek Polacek <polacek@redhat.com>
+
+ PR c++/93684 - ICE-on-invalid with broken attribute.
+ * g++.dg/parse/attr4.C: New test.
+
2020-02-12 Jakub Jelinek <jakub@redhat.com>
PR target/93670
diff --git a/gcc/testsuite/g++.dg/parse/attr4.C b/gcc/testsuite/g++.dg/parse/attr4.C
new file mode 100644
index 0000000..7713fc9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/attr4.C
@@ -0,0 +1,3 @@
+// PR c++/93684 - ICE-on-invalid with broken attribute.
+
+[[a:: // { dg-error "expected|expected" }