http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39589
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |manu at gcc dot gnu.org --- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> --- (In reply to Szikra István from comment #1) > I have the same (or similar) problem, and would like to have an option to > enable warnings for incomplete structure initialization with designated > initializers, where not all fields were explicitly assigned. I don't think GCC devs would be against this in principle if someone provided a sensible patch: http://gcc.gnu.org/contribute.html The relevant code is at gcc/c/c-typeck.c: pop_init_level /* Warn when some struct elements are implicitly initialized to zero. */ if (warn_missing_field_initializers && constructor_type && TREE_CODE (constructor_type) == RECORD_TYPE && constructor_unfilled_fields) { bool constructor_zeroinit = (vec_safe_length (constructor_elements) == 1 && integer_zerop ((*constructor_elements)[0].value)); /* Do not warn for flexible array members or zero-length arrays. */ while (constructor_unfilled_fields && (!DECL_SIZE (constructor_unfilled_fields) || integer_zerop (DECL_SIZE (constructor_unfilled_fields)))) constructor_unfilled_fields = DECL_CHAIN (constructor_unfilled_fields); if (constructor_unfilled_fields /* 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}'. */ && !constructor_zeroinit) { if (warning_at (input_location, OPT_Wmissing_field_initializers, "missing initializer for field %qD of %qT", constructor_unfilled_fields, constructor_type)) inform (DECL_SOURCE_LOCATION (constructor_unfilled_fields), "%qD declared here", constructor_unfilled_fields); } } Perhaps sinking the !constructor_designated check into the if, and adding an 'else'? Or simply deleting the check and doing: if (warning_at (input_location, !constructor_designated check ? OPT_Wmissing_field_initializers : OPT_Wmissing_field_initializers_2, where OPT_Wmissing_field_initializers_2 corresponds to a new option Wmissing-field-initializers=2 that needs to be added to c.opt (and documented in doc/invoke.texi).