From: Marek Polacek <polacek@redhat.com>
To: Jason Merrill <jason@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] c++: Fix ICE-on-invalid with broken attribute [PR93684]
Date: Tue, 11 Feb 2020 21:35:00 -0000 [thread overview]
Message-ID: <20200211213522.392020-1-polacek@redhat.com> (raw)
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.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
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/parser.c | 3 ++-
gcc/testsuite/g++.dg/parse/attr4.C | 3 +++
2 files changed, 5 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/parse/attr4.C
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 640affd8368..e8a536ae22f 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/g++.dg/parse/attr4.C b/gcc/testsuite/g++.dg/parse/attr4.C
new file mode 100644
index 00000000000..7713fc96c64
--- /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" }
base-commit: ad21e0072e20b7c8e4d7af5ca78f24cc6ae407d1
--
Marek Polacek • Red Hat, Inc. • 300 A St, Boston, MA
next reply other threads:[~2020-02-11 21:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 21:35 Marek Polacek [this message]
2020-02-12 0:30 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200211213522.392020-1-polacek@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).