public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/88222, ICE with bit-field with invalid type
@ 2018-11-28 18:04 Marek Polacek
  2018-11-28 18:35 ` Paolo Carlini
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2018-11-28 18:04 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

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.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2018-11-28  Marek Polacek  <polacek@redhat.com>

	PR c++/88222 - ICE with bit-field with invalid type.
	* decl.c (grokdeclarator): Fall back to input_location if declarator
	is null.

	* g++.dg/ext/flexary31.C: New test.

diff --git gcc/cp/decl.c gcc/cp/decl.c
index 1aaf51750ab..8049a71c6f3 100644
--- gcc/cp/decl.c
+++ gcc/cp/decl.c
@@ -12222,7 +12222,8 @@ grokdeclarator (const cp_declarator *declarator,
 		  /* Do not warn on flexible array members in system
 		     headers because glibc uses them.  */;
 		else if (name)
-		  pedwarn (declarator->id_loc, OPT_Wpedantic,
+		  pedwarn ((declarator ? declarator->id_loc : input_location),
+			   OPT_Wpedantic,
 			   "ISO C++ forbids flexible array member %qs", name);
 		else
 		  pedwarn (input_location, OPT_Wpedantic,
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" }
+};

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++ PATCH for c++/88222, ICE with bit-field with invalid type
  2018-11-28 18:04 C++ PATCH for c++/88222, ICE with bit-field with invalid type Marek Polacek
@ 2018-11-28 18:35 ` Paolo Carlini
  2018-11-28 18:48   ` Marek Polacek
  0 siblings, 1 reply; 4+ messages in thread
From: Paolo Carlini @ 2018-11-28 18:35 UTC (permalink / raw)
  To: Marek Polacek, Jason Merrill, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 752 bytes --]

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".

Cheers, Paolo.

///////////////



[-- Attachment #2: pppp --]
[-- Type: text/plain, Size: 523 bytes --]

Index: decl.c
===================================================================
--- decl.c	(revision 266555)
+++ decl.c	(working copy)
@@ -12221,7 +12219,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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++ PATCH for c++/88222, ICE with bit-field with invalid type
  2018-11-28 18:35 ` Paolo Carlini
@ 2018-11-28 18:48   ` Marek Polacek
  2018-11-28 19:49     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2018-11-28 18:48 UTC (permalink / raw)
  To: Paolo Carlini; +Cc: Jason Merrill, GCC Patches

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  <polacek@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" }
+};

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++ PATCH for c++/88222, ICE with bit-field with invalid type
  2018-11-28 18:48   ` Marek Polacek
@ 2018-11-28 19:49     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2018-11-28 19:49 UTC (permalink / raw)
  To: Marek Polacek; +Cc: Paolo Carlini, gcc-patches List

OK.
On Wed, Nov 28, 2018 at 1:48 PM Marek Polacek <polacek@redhat.com> wrote:
>
> 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  <polacek@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" }
> +};

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-11-28 19:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-28 18:04 C++ PATCH for c++/88222, ICE with bit-field with invalid type Marek Polacek
2018-11-28 18:35 ` Paolo Carlini
2018-11-28 18:48   ` Marek Polacek
2018-11-28 19:49     ` Jason Merrill

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).