c++: Fix ICE-on-invalid with broken attribute [PR93684]
authorMarek Polacek <polacek@redhat.com>
Tue, 11 Feb 2020 20:29:24 +0000 (15:29 -0500)
committerMarek Polacek <polacek@redhat.com>
Wed, 12 Feb 2020 15:39:40 +0000 (10:39 -0500)
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.

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/parse/attr4.C [new file with mode: 0644]

index 7567bbe67224618386b25f4c4e3b22d3bbc29e17..c578cdbfe33444f4ed6a0de3dcbbc1e01b5beb74 100644 (file)
@@ -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
index 640affd836850939c367e25fd9d742c87990b1e4..e8a536ae22f57b7ee2bb2164117a59b68064f302 100644 (file)
@@ -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);
index 433b0af7874758512dc71321dcfcfe82bede3a54..968b903411d6586b2d93b918c40a6250713c791c 100644 (file)
@@ -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 (file)
index 0000000..7713fc9
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/93684 - ICE-on-invalid with broken attribute.
+
+[[a:: // { dg-error "expected|expected" }