]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
options: Avoid -Wmissing-field-initializers warnings.
authorBruno Haible <bruno@clisp.org>
Sat, 28 Jun 2025 21:30:10 +0000 (23:30 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 28 Jun 2025 21:30:10 +0000 (23:30 +0200)
* lib/options.h (BEGIN_ALLOW_OMITTING_FIELD_INITIALIZERS,
END_ALLOW_OMITTING_FIELD_INITIALIZERS): New macros.

ChangeLog
lib/options.h

index a5be14e7fa69e57101a311a0a8d583cf87cd9f72..599f5d9621015b89eb129796a24e1319e355b3c7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-06-28  Bruno Haible  <bruno@clisp.org>
+
+       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  <collin.funk1@gmail.com>
 
        gnupload: adjust commentary regarding gnupg versions
index 6ac33a5ac7e5ffcdc1e3c1dbbb80490a44ae310e..044cc73265cd9e3c2ffca1d6078437ed14bce5d9 100644 (file)
@@ -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.