diff mbox

[C] Fix -Wc++-compat (PR c/44772)

Message ID 20101105174731.GK29412@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Nov. 5, 2010, 5:47 p.m. UTC
Hi!

pointer_set_contains is documented that it must not be called with NULL.
We don't try to store NULL into tset (which doesn't work either), but
pointer_set_contains (tset, NULL) just always returns 1.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-11-05  Jakub Jelinek  <jakub@redhat.com>

	PR c/44772
	* c-decl.c (warn_cxx_compat_finish_struct): Don't call
	pointer_set_contains if DECL_NAME is NULL.

	* gcc.dg/Wcxx-compat-21.c: New test.


	Jakub

Comments

Joseph Myers Nov. 5, 2010, 11:39 p.m. UTC | #1
On Fri, 5 Nov 2010, Jakub Jelinek wrote:

> Hi!
> 
> pointer_set_contains is documented that it must not be called with NULL.
> We don't try to store NULL into tset (which doesn't work either), but
> pointer_set_contains (tset, NULL) just always returns 1.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?

OK.
diff mbox

Patch

--- gcc/c-decl.c.jj	2010-11-01 09:07:22.000000000 +0100
+++ gcc/c-decl.c	2010-11-05 14:35:08.000000000 +0100
@@ -6877,7 +6877,8 @@  warn_cxx_compat_finish_struct (tree fiel
 
       for (x = fieldlist; x != NULL_TREE; x = DECL_CHAIN (x))
 	{
-	  if (pointer_set_contains (tset, DECL_NAME (x)))
+	  if (DECL_NAME (x) != NULL_TREE
+	      && pointer_set_contains (tset, DECL_NAME (x)))
 	    {
 	      warning_at (DECL_SOURCE_LOCATION (x), OPT_Wc___compat,
 			  ("using %qD as both field and typedef name is "
--- gcc/testsuite/gcc.dg/Wcxx-compat-21.c.jj	2010-11-05 14:37:35.000000000 +0100
+++ gcc/testsuite/gcc.dg/Wcxx-compat-21.c	2010-11-05 14:41:11.000000000 +0100
@@ -0,0 +1,25 @@ 
+/* PR c/44772 */
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+typedef enum { E1, E2 } E;
+
+typedef struct
+{
+  E e;
+  union
+  {
+    int i;
+    char *c;
+  };			/* { dg-bogus "as both field and typedef name" } */
+} S;
+
+S s;
+
+typedef int T;
+
+struct U
+{
+  T t;
+  union { int i; };	/* { dg-bogus "as both field and typedef name" } */
+};