re PR c++/61489 (Wrong warning with -Wmissing-field-initializers.)
authorPaolo Carlini <paolo.carlini@oracle.com>
Thu, 11 Sep 2014 18:08:24 +0000 (18:08 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 11 Sep 2014 18:08:24 +0000 (18:08 +0000)
2014-09-11  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/61489
* doc/invoke.texi ([-Wmissing-field-initializers]): Update.

/cp
2014-09-11  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/61489
* typeck2.c (process_init_constructor_record): Do not warn about
missing field initializer if EMPTY_CONSTRUCTOR_P (init).

/testsuite
2014-09-11  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/61489
* g++.dg/warn/Wmissing-field-initializers-1.C: New.
* g++.old-deja/g++.other/warn5.C: Adjust.

From-SVN: r215186

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-1.C [new file with mode: 0644]
gcc/testsuite/g++.old-deja/g++.other/warn5.C

index 5097819b0e76dd706d6e20e394d1d8d62ba5681a..82d70dfc551fc505e5a5ba2d9eec1d94c3daaf38 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/61489
+       * doc/invoke.texi ([-Wmissing-field-initializers]): Update.
+
 2014-09-11  Alan Lawrence  <alan.lawrence@arm.com>
 
        * config/aarch64/aarch64-builtins.c (aarch64_types_unop_su_qualifiers,
index 7ebc56b634295ce76ce96a0f1a8bab3ca1668af7..afefed4e62348480e7d1c979f11e9c147d10d2ed 100644 (file)
@@ -1,3 +1,9 @@
+2014-09-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/61489
+       * typeck2.c (process_init_constructor_record): Do not warn about
+       missing field initializer if EMPTY_CONSTRUCTOR_P (init).
+
 2014-09-11  Jason Merrill  <jason@redhat.com>
 
        PR c++/63139
index c985a4bf92c069494867daaabba6e99b00993879..c6306b519aae288e3021b06beb5e4af4741f25f1 100644 (file)
@@ -1359,7 +1359,8 @@ process_init_constructor_record (tree type, tree init,
          next = massage_init_elt (TREE_TYPE (field), next, complain);
 
          /* Warn when some struct elements are implicitly initialized.  */
-         if (complain & tf_warning)
+         if ((complain & tf_warning)
+             && !EMPTY_CONSTRUCTOR_P (init))
            warning (OPT_Wmissing_field_initializers,
                     "missing initializer for member %qD", field);
        }
@@ -1382,7 +1383,8 @@ process_init_constructor_record (tree type, tree init,
 
          /* Warn when some struct elements are implicitly initialized
             to zero.  */
-         if (complain & tf_warning)
+         if ((complain & tf_warning)
+             && !EMPTY_CONSTRUCTOR_P (init))
            warning (OPT_Wmissing_field_initializers,
                     "missing initializer for member %qD", field);
 
index 863b382e8684dd11e63384c1e591fee847c48389..68e992d1d50855e15077d50ed5d6e48b1645e715 100644 (file)
@@ -4912,6 +4912,14 @@ struct s @{ int f, g, h; @};
 struct s x = @{ .f = 3, .g = 4 @};
 @end smallexample
 
+In C++ this option does not warn either about the empty @{ @}
+initializer, for example:
+
+@smallexample
+struct s @{ int f, g, h; @};
+s x = @{ @};
+@end smallexample
+
 This warning is included in @option{-Wextra}.  To get other @option{-Wextra}
 warnings without this one, use @option{-Wextra -Wno-missing-field-initializers}.
 
index 60397bfbc16afaab9e585310c3c87c2f26589a97..3f88bb66c7ee64a43b7ffa84a296f24fe451527e 100644 (file)
@@ -1,3 +1,9 @@
+2014-09-11  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/61489
+       * g++.dg/warn/Wmissing-field-initializers-1.C: New.
+       * g++.old-deja/g++.other/warn5.C: Adjust.
+
 2014-09-11  Alan Lawrence  <alan.lawrence@arm.com>
 
        * gcc.target/aarch64/vset_lane_1.c: New test.
diff --git a/gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-1.C b/gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-1.C
new file mode 100644 (file)
index 0000000..47308d9
--- /dev/null
@@ -0,0 +1,31 @@
+// PR c++/61489
+// { dg-options "-Wmissing-field-initializers" }
+
+struct mystruct1 {
+  int a, b;
+};
+
+struct aux2 {
+  aux2();
+};
+
+struct mystruct2 {
+  aux2 a, b;
+};
+
+struct aux3 {
+  int x;
+};
+
+struct mystruct3 {
+  aux3 a, b;
+};
+
+mystruct1 obj11 = {};
+mystruct1 obj12 = {0};       // { dg-warning "missing initializer" }
+
+mystruct2 obj21 = {};
+mystruct2 obj22 = {aux2()};  // { dg-warning "missing initializer" }
+
+mystruct3 obj31 = {};
+mystruct3 obj32 = {0};       // { dg-warning "missing initializer" }
index 84fa3e426b2b4cacf7ef8b6dd292b81288b8ed9a..a4e07e8f2c57efa3562e8282fde748ae876e3487 100644 (file)
@@ -16,4 +16,4 @@ X *foo ()
   return new X ();  // gets bogus warning
 }
 
-X x = {};           // { dg-warning "" } missing initializer
+X x = {};