This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to fix ICE with invalid cast (PR c++/84493)
- From: Marek Polacek <polacek at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 21 Feb 2018 11:36:07 +0100
- Subject: C++ PATCH to fix ICE with invalid cast (PR c++/84493)
- Authentication-results: sourceware.org; auth=none
Here we can prevent a crash on invalid by using require_open where '{' is
expected. require_open uses cp_parser_require whereas consume_open has
an assert:
gcc_assert (tok->type == traits_t::open_token_type);
which triggers here.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2018-02-21 Marek Polacek <polacek@redhat.com>
PR c++/84493
* parser.c (cp_parser_braced_list): Use require_open instead of
consume_open.
* g++.dg/parse/error59.C: New test.
diff --git gcc/cp/parser.c gcc/cp/parser.c
index 2bb0d2da5fe..4fa546a086c 100644
--- gcc/cp/parser.c
+++ gcc/cp/parser.c
@@ -21925,7 +21925,7 @@ cp_parser_braced_list (cp_parser* parser, bool* non_constant_p)
/* Consume the `{' token. */
matching_braces braces;
- braces.consume_open (parser);
+ braces.require_open (parser);
/* Create a CONSTRUCTOR to represent the braced-initializer. */
initializer = make_node (CONSTRUCTOR);
/* If it's not a `}', then there is a non-trivial initializer. */
diff --git gcc/testsuite/g++.dg/parse/error59.C gcc/testsuite/g++.dg/parse/error59.C
index e69de29bb2d..2c44e210366 100644
--- gcc/testsuite/g++.dg/parse/error59.C
+++ gcc/testsuite/g++.dg/parse/error59.C
@@ -0,0 +1,6 @@
+// PR c++/84493
+
+void foo()
+{
+ (struct {}x){}; // { dg-error "" }
+}
Marek