manywarnings: add -Wno-missing-field-initializers if needed
authorPádraig Brady <P@draigBrady.com>
Fri, 29 Apr 2011 23:16:01 +0000 (00:16 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 30 Apr 2011 09:50:21 +0000 (10:50 +0100)
* m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Add the above
option if it's needed to allow initialization with { 0, },
which is the case with GCC before version 4.7

ChangeLog
m4/manywarnings.m4

index 9b56d71..1ee541c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-04-30  Pádraig Brady <P@draigBrady.com>
+
+       manywarnings: add -Wno-missing-field-initializers if needed.
+       * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Add the above
+       option if it's needed to allow initialization with { 0, }
+
 2011-04-29  Reuben Thomas  <rrt@sc3d.org>
 
        announce-gen: cosmetic improvement
index e928821..88af0a6 100644 (file)
@@ -35,6 +35,49 @@ AC_DEFUN([gl_MANYWARN_COMPLEMENT],
 # using gl_WARN_ADD if you want to make sure your gcc understands it.
 AC_DEFUN([gl_MANYWARN_ALL_GCC],
 [
+ dnl First, check if -Wno-missing-field-initializers is needed.
+ dnl -Wmissing-field-initializers is implied by -W, but that issues
+ dnl warnings with GCC version before 4.7, for the common idiom
+ dnl of initializing types on the stack to zero, using { 0, }
+ AC_REQUIRE([AC_PROG_CC])
+ if test -n "$GCC"; then
+
+   dnl First, check -W -Werror -Wno-missing-field-initializers is supported
+   dnl with the current $CC $CFLAGS $CPPFLAGS.
+   AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
+   AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
+     gl_save_CFLAGS="$CFLAGS"
+     CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers"
+     AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([[]], [[]])],
+       [gl_cv_cc_nomfi_supported=yes],
+       [gl_cv_cc_nomfi_supported=no])
+     CFLAGS="$gl_save_CFLAGS"])
+   AC_MSG_RESULT([$gl_cv_cc_nomfi_supported])
+
+   if test "$gl_cv_cc_nomfi_supported" = yes; then
+     dnl Now check whether -Wno-missing-field-initializers is needed
+     dnl for the { 0, } construct.
+     AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed])
+     AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [
+       gl_save_CFLAGS="$CFLAGS"
+       CFLAGS="$CFLAGS -W -Werror"
+       AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[void f (void)
+              {
+                typedef struct { int a; int b; } s_t;
+                s_t s1 = { 0, };
+              }
+            ]],
+            [[]])],
+         [gl_cv_cc_nomfi_needed=no],
+         [gl_cv_cc_nomfi_needed=yes])
+       CFLAGS="$gl_save_CFLAGS"])
+     AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
+   fi
+ fi
+
  gl_manywarn_set=
  for gl_manywarn_item in \
    -Wall \
@@ -104,5 +147,11 @@ AC_DEFUN([gl_MANYWARN_ALL_GCC],
   ; do
     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
   done
-  $1=$gl_manywarn_set
+
+ # Disable the missing-field-initializers warning if needed
+ if test "$gl_cv_cc_nomfi_needed" = yes; then
+   gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
+ fi
+
+ $1=$gl_manywarn_set
 ])