Message ID | 20180221103607.GK2629@redhat.com |
---|---|
State | New |
Headers | show |
Series | C++ PATCH to fix ICE with invalid cast (PR c++/84493) | expand |
OK. On Wed, Feb 21, 2018 at 5:36 AM, Marek Polacek <polacek@redhat.com> wrote: > 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
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 "" } +}