https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120860

            Bug ID: 120860
           Summary: add ability to silence -Wmissing-field-initializers
                    warnings on selected structs
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

The -Wmissing-field-initializers warning is generally useful: it helps
detecting programmer mistakes.

However, some struct types are designed to have mandatory and optional fields.
It would be useful to be able to silence the warning for such struct types.
Currently I have to write code like this:

     BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS
     static struct program_option const options[] =
     {
       { "width",   'w', required_argument },
       { NULL,      'x', no_argument       },
       { "help",    'h', no_argument,      &show_help, 1 },
       { "version", 'V', no_argument,      &show_version, 1 },
     };
     END_ALLOW_OMITTING_FIELD_INITIALIZERS

where the macros are defined like this:

#define BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS \
   _Pragma("GCC diagnostic push") \
   _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"")
#define END_ALLOW_OMITTING_FIELD_INITIALIZERS \
   _Pragma("GCC diagnostic pop")

I would prefer to be able to attach an attribute to the struct type definition,
and then get rid of the BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS and
END_ALLOW_OMITTING_FIELD_INITIALIZERS macros.

Reply via email to