The newly added diagnostic causes an ICE because the new grokdeclarator call returned error_mark_node and DECL_SOURCE_LOCATION crashes on that. So don't attempt to print the new diagnostic if we've encountered something not resembling a bit-field.
Bootstrapped/regtested on x86_64-linux, ok for trunk? 2019-11-18 Marek Polacek <pola...@redhat.com> PR c++/92450 - ICE with invalid nested name specifier. * parser.c (cp_parser_member_declaration): Bail out for invalid code. * g++.dg/parse/crash71.C: New test. diff --git gcc/cp/parser.c gcc/cp/parser.c index c473e7fd92f..caed6946977 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -25052,6 +25052,9 @@ cp_parser_member_declaration (cp_parser* parser) tree d = grokdeclarator (declarator, &decl_specifiers, BITFIELD, /*initialized=*/false, &attributes); + /* Hopelessly invalid code, give up. */ + if (error_operand_p (d)) + goto out; error_at (DECL_SOURCE_LOCATION (d), "bit-field %qD has non-integral type %qT", d, TREE_TYPE (d)); diff --git gcc/testsuite/g++.dg/parse/crash71.C gcc/testsuite/g++.dg/parse/crash71.C new file mode 100644 index 00000000000..13f484801fe --- /dev/null +++ gcc/testsuite/g++.dg/parse/crash71.C @@ -0,0 +1,11 @@ +// PR c++/92450 - ICE with invalid nested name specifier. + +typedef int C2; +struct B1 { + struct B2 { + }; +}; + +struct S6g { + C2 : B1:B2; // { dg-error "" } +};