re PR c/46889 (Missing diagnosis on duplicate struct member with anonymous union)
authorJoseph Myers <joseph@codesourcery.com>
Thu, 30 Dec 2010 18:24:03 +0000 (18:24 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Thu, 30 Dec 2010 18:24:03 +0000 (18:24 +0000)
PR c/46889
* c-decl.c (detect_field_duplicates): Ensure hash is used for
finding duplicates when first field is anonymous.

testsuite:
* gcc.dg/anon-struct-15.c: New test.

From-SVN: r168348

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/anon-struct-15.c [new file with mode: 0644]

index fbe61e348a4ae861b39cee36380a066a83b5fe11..8eff4b36dc1c93accb105d386dc0ac93318c3788 100644 (file)
@@ -1,3 +1,9 @@
+2010-12-30  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/46889
+       * c-decl.c (detect_field_duplicates): Ensure hash is used for
+       finding duplicates when first field is anonymous.
+
 2010-12-30  Nathan Froyd  <froydnj@codesourcery.com>
 
         PR target/44606
index 40fccbe554cd702653b659e5b5d2b7eff8c5f029..4d24c602b54ad17ee9b36f7f152203be08b90543 100644 (file)
@@ -6805,11 +6805,9 @@ detect_field_duplicates (tree fieldlist)
 
   /* First, see if there are more than "a few" fields.
      This is trivially true if there are zero or one fields.  */
-  if (!fieldlist)
-    return;
-  x = DECL_CHAIN (fieldlist);
-  if (!x)
+  if (!fieldlist || !DECL_CHAIN (fieldlist))
     return;
+  x = fieldlist;
   do {
     timeout--;
     if (DECL_NAME (x) == NULL_TREE
index 25c2b8ebc370d4e0b2c27f87063f73e886e2eeae..a14d4160c67c17366003815743624edf987d0595 100644 (file)
@@ -1,3 +1,8 @@
+2010-12-30  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/46889
+       * gcc.dg/anon-struct-15.c: New test.
+
 2010-12-30  Nathan Froyd  <froydnj@codesourcery.com>
 
         PR target/44606
diff --git a/gcc/testsuite/gcc.dg/anon-struct-15.c b/gcc/testsuite/gcc.dg/anon-struct-15.c
new file mode 100644 (file)
index 0000000..d9e786a
--- /dev/null
@@ -0,0 +1,16 @@
+/* Test diagnostics for duplicate field names involving anonymous
+   struct or union as first field.  PR 46889.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct foo {
+  union {
+    struct {
+      unsigned long time_stamp;
+    };
+    struct {
+      int *page;
+    };
+  };
+  int *page; /* { dg-error "duplicate member" } */
+};