re PR c/63480 (-Wmissing-field-initializers should not warn about intentionally empty...
authorMarek Polacek <polacek@redhat.com>
Thu, 9 Oct 2014 08:25:50 +0000 (08:25 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 9 Oct 2014 08:25:50 +0000 (08:25 +0000)
PR c/63480
* c-typeck.c (pop_init_level): Don't warn about initializing
with { }.

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

From-SVN: r216031

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

index 3a09125b15d157a8e100b47c65a0f912e4e245d5..91ed9d21c69a1ef625dfd8e198c90aa5f6ccab88 100644 (file)
@@ -1,3 +1,9 @@
+2014-10-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c/63480
+       * c-typeck.c (pop_init_level): Don't warn about initializing
+       with { }.
+
 2014-10-07  Marek Polacek  <polacek@redhat.com>
 
        PR c/59717
index b3b82bba2cc4fdd48b300f2a54fa1545894b577a..5c0697a9643379428bc32aa91c958901cf20ee5b 100644 (file)
@@ -7436,7 +7436,11 @@ pop_init_level (location_t loc, int implicit,
        }
     }
 
-  if (vec_safe_length (constructor_elements) != 1)
+  /* Initialization with { } counts as zeroinit.  */
+  if (vec_safe_length (constructor_elements) == 0)
+    constructor_zeroinit = 1;
+  /* If the constructor has more than one element, it can't be { 0 }.  */
+  else if (vec_safe_length (constructor_elements) != 1)
     constructor_zeroinit = 0;
 
   /* Warn when some structs are initialized with direct aggregation.  */
@@ -7463,7 +7467,7 @@ pop_init_level (location_t loc, int implicit,
            /* Do not warn if this level of the initializer uses member
               designators; it is likely to be deliberate.  */
            && !constructor_designated
-           /* Do not warn about initializing with ` = {0}'.  */
+           /* Do not warn about initializing with { 0 } or with { }.  */
            && !constructor_zeroinit)
          {
            if (warning_at (input_location, OPT_Wmissing_field_initializers,
index a8870ea3de711dd7a11bf77663189f80544739b1..ea731bf0abd3240ddc4c36156573776714213d10 100644 (file)
@@ -1,3 +1,8 @@
+2014-10-09  Marek Polacek  <polacek@redhat.com>
+
+       PR c/63480
+       * gcc.dg/pr63480.c: New test.
+
 2014-10-09  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/63445
diff --git a/gcc/testsuite/gcc.dg/pr63480.c b/gcc/testsuite/gcc.dg/pr63480.c
new file mode 100644 (file)
index 0000000..e720e0d
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR c/63480 */
+/* { dg-do compile } */
+/* { dg-options "-Wmissing-field-initializers" } */
+
+/* Test that we don't warn about initializing with { }.  */
+
+struct S { int a, b, c; } s = { };
+
+void
+foo (void)
+{
+  struct S s = { }; 
+  struct S s2 = (struct S){ };
+}