re PR c/60784 (Spurious -Wmissing-field-initializers warning for anonymous structure)
authorMarek Polacek <polacek@redhat.com>
Fri, 2 May 2014 05:40:38 +0000 (05:40 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 2 May 2014 05:40:38 +0000 (05:40 +0000)
PR c/60784
* c-typeck.c (push_init_level): Set constructor_designated to
p->designated for structures.

* gcc.dg/pr60784.c: New test.

From-SVN: r209998

gcc/c/ChangeLog
gcc/c/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr60784.c [new file with mode: 0644]

index a5b4f5f17a5e45aaef014c6c5a9b3c8787b0ae80..8fc20cf2c8133f76de53ba7763ef7b9c0ac7349e 100644 (file)
@@ -1,3 +1,9 @@
+2014-05-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60784
+       * c-typeck.c (push_init_level): Set constructor_designated to
+       p->designated for structures.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/60915
index 21d1006fb1aa3ec7b1f70b7fa200bba0d43cec52..98567b4281eb107ff27b3ad2ad8d65f67b931d00 100644 (file)
@@ -7270,6 +7270,9 @@ push_init_level (int implicit, struct obstack * braced_init_obstack)
          push_member_name (constructor_fields);
          constructor_depth++;
        }
+      /* If upper initializer is designated, then mark this as
+        designated too to prevent bogus warnings.  */
+      constructor_designated = p->designated;
     }
   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
     {
index f5976b9ace0b755d0ead801c089cba93383c33c9..1845daf7a6f0b03edbcc2545d949cfd16574fd5b 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-02  Marek Polacek  <polacek@redhat.com>
+
+       PR c/60784
+       * gcc.dg/pr60784.c: New test.
+
 2014-05-01  Marek Polacek  <polacek@redhat.com>
 
        PR c/60915
diff --git a/gcc/testsuite/gcc.dg/pr60784.c b/gcc/testsuite/gcc.dg/pr60784.c
new file mode 100644 (file)
index 0000000..82b512f
--- /dev/null
@@ -0,0 +1,25 @@
+/* PR c/60784 */
+/* { dg-do compile } */
+/* { dg-options "-Wextra -std=c99" } */
+
+struct A { int i, j; };
+struct B { struct A a; } b1 = { .a.i = 1, .a.j = 1 };
+struct B b2 = { .a.i = 1 };
+
+struct C { struct { int a, b; }; } c1 = { .a = 4, .b = 2 };
+struct C c2 = { .a = 4, .b = 2 };
+
+struct D { struct A a; };
+struct E { struct D d; };
+struct F { struct E e; } f1 = { .e.d.a.i = 8 };
+struct F f2 = { .e.d.a.i = 8, .e.d.a.j = 3 };
+
+struct G {
+  struct {
+    struct {
+      struct {
+        int a, b, c, d, e, f;
+      };
+    };
+  };
+} g = { .b = 2 };