From: Bruno Haible Date: Sat, 28 Jun 2025 21:30:10 +0000 (+0200) Subject: options: Avoid -Wmissing-field-initializers warnings. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d2aa9c2fa1dea0b638fa1031a56f690722052279;p=thirdparty%2Fgnulib.git options: Avoid -Wmissing-field-initializers warnings. * lib/options.h (BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS, END_ALLOW_OMITTING_FIELD_INITIALIZERS): New macros. --- diff --git a/ChangeLog b/ChangeLog index a5be14e7fa..599f5d9621 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-06-28 Bruno Haible + + options: Avoid -Wmissing-field-initializers warnings. + * lib/options.h (BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS, + END_ALLOW_OMITTING_FIELD_INITIALIZERS): New macros. + 2025-06-28 Collin Funk gnupload: adjust commentary regarding gnupg versions diff --git a/lib/options.h b/lib/options.h index 6ac33a5ac7..044cc73265 100644 --- a/lib/options.h +++ b/lib/options.h @@ -58,6 +58,7 @@ you write + BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS static struct program_option const options[] = { { "width", 'w', required_argument }, @@ -65,6 +66,7 @@ { "help", 'h', no_argument, &show_help, 1 }, { "version", 'V', no_argument, &show_version, 1 }, }; + END_ALLOW_OMITTING_FIELD_INITIALIZERS start_options (argc, argv, options, MOVE_OPTIONS_FIRST, 0); while ((optchar = get_next_option ()) != -1) @@ -180,6 +182,21 @@ struct program_option int value; }; +/* These macros silence '-Wmissing-field-initializers' warnings from GCC and + clang in the definition of a 'struct program_option' array. + To be placed before and after the declaration of a 'struct program_option' + array. */ +#if _GL_GNUC_PREREQ (4, 6) || defined __clang__ +# 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") +#else +# define BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS +# define END_ALLOW_OMITTING_FIELD_INITIALIZERS +#endif + /* Handling of non-option arguments. */ enum non_option_handling { /* Move options before non-option arguments.