@@ -1,3 +1,7 @@
+2020-06-07 Asher Gordon <AsDaGo@posteo.net>
+
+ * doc/invoke.texi: Document -Wuniversal-initializer.
+
2020-06-06 Jan Hubicka <hubicka@ucw.cz>
PR lto/95548
@@ -1,3 +1,7 @@
+2020-06-07 Asher Gordon <AsDaGo@posteo.net>
+
+ * c.opt: Add -Wuniversal-initializer
+
2020-06-05 Jason Merrill <jason@redhat.com>
* c-pretty-print.c (pp_c_additive_expression): Handle negative
@@ -1191,6 +1191,10 @@ Wuninitialized
C ObjC C++ ObjC++ LTO LangEnabledBy(C ObjC C++ ObjC++ LTO,Wall)
;
+Wuniversal-initializer
+C ObjC C++ ObjC++ Var(warn_zero_init) Init(1) Warning
+Don't suppress warnings about { 0 }.
+
Wmaybe-uninitialized
C ObjC C++ ObjC++ LTO LangEnabledBy(C ObjC C++ ObjC++ LTO,Wall)
;
@@ -1,3 +1,8 @@
+2020-06-07 Asher Gordon <AsDaGo@posteo.net>
+
+ * c-typeck.c (pop_init_level): Don't suppress warnings about { 0 }
+ if warn_zero_init.
+
2020-06-05 Mark Wielaard <mark@klomp.org>
* c-decl.c (implicit_decl_warning): When warned and olddecl is
@@ -8724,7 +8724,7 @@ pop_init_level (location_t loc, int implicit,
/* Warn when some structs are initialized with direct aggregation. */
if (!implicit && found_missing_braces && warn_missing_braces
- && !constructor_zeroinit)
+ && (!constructor_zeroinit || warn_zero_init))
{
gcc_assert (initializer_stack->missing_brace_richloc);
warning_at (initializer_stack->missing_brace_richloc,
@@ -8748,8 +8748,9 @@ 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 } or with { }. */
- && !constructor_zeroinit)
+ /* Do not warn about initializing with { 0 } or with { }
+ unless warn_zero_init. */
+ && (!constructor_zeroinit || warn_zero_init))
{
if (warning_at (input_location, OPT_Wmissing_field_initializers,
"missing initializer for field %qD of %qT",
@@ -8766,7 +8767,7 @@ pop_init_level (location_t loc, int implicit,
{
struct location_list *loc = initializer_stack->positional_init_locs;
- if (!constructor_zeroinit)
+ if (!constructor_zeroinit || warn_zero_init)
warning_init (loc->loc,
OPT_Wdesignated_init,
"positional initialization of field in %<struct%> "
@@ -369,7 +369,7 @@ Objective-C and Objective-C++ Dialects}.
-Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @gol
-Wsystem-headers -Wtautological-compare -Wtrampolines -Wtrigraphs @gol
-Wtype-limits -Wundef @gol
--Wuninitialized -Wunknown-pragmas @gol
+-Wuninitialized -Wno-universal-initializer -Wunknown-pragmas @gol
-Wunsuffixed-float-constants -Wunused @gol
-Wunused-but-set-parameter -Wunused-but-set-variable @gol
-Wunused-const-variable -Wunused-const-variable=@var{n} @gol
@@ -6453,6 +6453,26 @@ to compute a value that itself is never used, because such
computations may be deleted by data flow analysis before the warnings
are printed.
+@item -Wuniversal-initializer
+@opindex Wuniversal-initializer
+@opindex Wno-universal-initializer
+Do not suppress warnings about the universal zero initializer,
+@code{@{ 0 @}}, where a warning would otherwise be produced. For
+example, even with @option{-Wmissing-braces}, the following would not
+warn, because an exception is made for the universal initializer:
+
+@smallexample
+int a[1][1] = @{ 0 @};
+@end smallexample
+
+However, if @code{-Wuniversal-initializer} is used, that code would
+produce a warning (caused by @option{-Wmissing-braces}).
+
+This warning is not enabled by default, nor is it enabled by any other
+options. If you don't want to suppress warnings about the universal
+zero initializer, you must specify @option{-Wuniversal-initializer}
+explicitly.
+
@item -Wno-invalid-memory-model
@opindex Winvalid-memory-model
@opindex Wno-invalid-memory-model
@@ -1,3 +1,7 @@
+2020-06-07 Asher Gordon <AsDaGo@posteo.net>
+
+ * gcc.dg/Wuniversal-initializer.c: New test.
+
2020-06-06 Jan Hubicka <hubicka@ucw.cz>
* g++.dg/torture/pr95548.C: New test.
new file mode 100644
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wmissing-field-initializers -Wuniversal-initializer" } */
+
+struct Pok {
+ int x;
+ int y;
+};
+
+struct Nest {
+ struct Pok p;
+};
+
+struct Des {
+ int a;
+} __attribute__((designated_init));
+
+struct Pok p = { 0 }; /* { dg-warning "missing initializer for field" } */
+struct Nest n = { 0 }; /* { dg-warning "missing braces around initializer" } */
+struct Des d = { 0 }; /* { dg-warning "(positional|near initialization)" } */
+int a[1][1] = { 0 }; /* { dg-warning "missing braces around initializer" } */