On Wed, Nov 28, 2018 at 07:35:42PM +0100, Paolo Carlini wrote: > Hi, > > On 28/11/18 19:05, Marek Polacek wrote: > > Paolo's recent commit changed > > > > - pedwarn (input_location, OPT_Wpedantic, > > + pedwarn (declarator->id_loc, OPT_Wpedantic, > > > > but as this testcase shows, declarator might not always be present. So > > let's brace ourselves for that. > > Thanks Marek. Just to clarify a bit more, ultimately the reason why I missed > this case is that, when the declarator is null - for the testcase at issue, > that is - we end up printing something of the form: > > warning: ISO C++ forbids flexible array member ‘type name’ > > thus, all in all, I'm wondering if it wouldn't be a tad less cryptic to do > something like the attached., which avoids printing "type name".
I think you're right, so this is another version: 2018-11-28 Marek Polacek <pola...@redhat.com> PR c++/88222 - ICE with bit-field with invalid type. * decl.c (grokdeclarator): Check if declarator is null. * g++.dg/ext/flexary31.C: New test. diff --git gcc/cp/decl.c gcc/cp/decl.c index 1aaf51750ab..3734bfe39ac 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -12221,7 +12221,7 @@ grokdeclarator (const cp_declarator *declarator, if (in_system_header_at (input_location)) /* Do not warn on flexible array members in system headers because glibc uses them. */; - else if (name) + else if (name && declarator) pedwarn (declarator->id_loc, OPT_Wpedantic, "ISO C++ forbids flexible array member %qs", name); else diff --git gcc/testsuite/g++.dg/ext/flexary31.C gcc/testsuite/g++.dg/ext/flexary31.C new file mode 100644 index 00000000000..90f8431a2a4 --- /dev/null +++ gcc/testsuite/g++.dg/ext/flexary31.C @@ -0,0 +1,8 @@ +// PR c++/88222 +// { dg-options -Wno-pedantic } + +typedef char a[]; + +class S { + a : 4; // { dg-error "bit-field" } +};