This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

--- 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" } */
+};

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]