From: Paolo Carlini Date: Thu, 11 Sep 2014 18:08:24 +0000 (+0000) Subject: re PR c++/61489 (Wrong warning with -Wmissing-field-initializers.) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=450bfd7d5cd2a048edd1119bc5306b95d6386101;p=gcc.git re PR c++/61489 (Wrong warning with -Wmissing-field-initializers.) 2014-09-11 Paolo Carlini PR c++/61489 * doc/invoke.texi ([-Wmissing-field-initializers]): Update. /cp 2014-09-11 Paolo Carlini 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 PR c++/61489 * g++.dg/warn/Wmissing-field-initializers-1.C: New. * g++.old-deja/g++.other/warn5.C: Adjust. From-SVN: r215186 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5097819b0e7..82d70dfc551 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2014-09-11 Paolo Carlini + + PR c++/61489 + * doc/invoke.texi ([-Wmissing-field-initializers]): Update. + 2014-09-11 Alan Lawrence * config/aarch64/aarch64-builtins.c (aarch64_types_unop_su_qualifiers, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7ebc56b6342..afefed4e623 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2014-09-11 Paolo Carlini + + 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 PR c++/63139 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index c985a4bf92c..c6306b519aa 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -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); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 863b382e868..68e992d1d50 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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}. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 60397bfbc16..3f88bb66c7e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-09-11 Paolo Carlini + + 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 * 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 index 00000000000..47308d9d200 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wmissing-field-initializers-1.C @@ -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" } diff --git a/gcc/testsuite/g++.old-deja/g++.other/warn5.C b/gcc/testsuite/g++.old-deja/g++.other/warn5.C index 84fa3e426b2..a4e07e8f2c5 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/warn5.C +++ b/gcc/testsuite/g++.old-deja/g++.other/warn5.C @@ -16,4 +16,4 @@ X *foo () return new X (); // gets bogus warning } -X x = {}; // { dg-warning "" } missing initializer +X x = {};