3 @@ -62,9 +62,9 @@ int in_typeof;
4 if expr.original_code == SIZEOF_EXPR. */
5 tree c_last_sizeof_arg;
7 -/* Nonzero if we've already printed a "missing braces around initializer"
8 - message within this initializer. */
9 -static int missing_braces_mentioned;
10 +/* Nonzero if we might need to print a "missing braces around
11 + initializer" message within this initializer. */
12 +static int found_missing_braces;
14 static int require_constant_value;
15 static int require_constant_elements;
16 @@ -6363,6 +6363,9 @@ static int constructor_nonconst;
17 /* 1 if this constructor is erroneous so far. */
18 static int constructor_erroneous;
20 +/* 1 if this constructor is the universal zero initializer { 0 }. */
21 +static int constructor_zeroinit;
23 /* Structure for managing pending initializer elements, organized as an
26 @@ -6524,7 +6527,7 @@ start_init (tree decl, tree asmspec_tree
27 constructor_stack = 0;
28 constructor_range_stack = 0;
30 - missing_braces_mentioned = 0;
31 + found_missing_braces = 0;
35 @@ -6619,6 +6622,7 @@ really_start_incremental_init (tree type
36 constructor_type = type;
37 constructor_incremental = 1;
38 constructor_designated = 0;
39 + constructor_zeroinit = 1;
41 designator_erroneous = 0;
43 @@ -6816,11 +6820,8 @@ push_init_level (int implicit, struct ob
44 set_nonincremental_init (braced_init_obstack);
47 - if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
49 - missing_braces_mentioned = 1;
50 - warning_init (OPT_Wmissing_braces, "missing braces around initializer");
53 + found_missing_braces = 1;
55 if (TREE_CODE (constructor_type) == RECORD_TYPE
56 || TREE_CODE (constructor_type) == UNION_TYPE)
57 @@ -6953,16 +6954,23 @@ pop_init_level (int implicit, struct obs
61 + if (vec_safe_length (constructor_elements) != 1)
62 + constructor_zeroinit = 0;
64 + /* Warn when some structs are initialized with direct aggregation. */
65 + if (!implicit && found_missing_braces && warn_missing_braces
66 + && !constructor_zeroinit)
68 + warning_init (OPT_Wmissing_braces,
69 + "missing braces around initializer");
72 /* Warn when some struct elements are implicitly initialized to zero. */
73 if (warn_missing_field_initializers
75 && TREE_CODE (constructor_type) == RECORD_TYPE
76 && constructor_unfilled_fields)
78 - bool constructor_zeroinit =
79 - (vec_safe_length (constructor_elements) == 1
80 - && integer_zerop ((*constructor_elements)[0].value));
82 /* Do not warn for flexible array members or zero-length arrays. */
83 while (constructor_unfilled_fields
84 && (!DECL_SIZE (constructor_unfilled_fields)
85 @@ -8077,6 +8085,9 @@ process_init_element (struct c_expr valu
87 designator_erroneous = 0;
89 + if (!implicit && value.value && !integer_zerop (value.value))
90 + constructor_zeroinit = 0;
92 /* Handle superfluous braces around string cst as in
93 char x[] = {"foo"}; */