From 2953da14ede8686f2ab85440a0b7cc928953f625 Mon Sep 17 00:00:00 2001
From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Sat, 30 Apr 2011 00:16:01 +0100
Subject: [PATCH] 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, },
which is the case with GCC before version 4.7
---
ChangeLog | 6 ++++++
m4/manywarnings.m4 | 51 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 9b56d719e0..1ee541c83e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2011-04-30 Pádraig Brady
+
+ 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
announce-gen: cosmetic improvement
diff --git a/m4/manywarnings.m4 b/m4/manywarnings.m4
index e928821952..88af0a6923 100644
--- a/m4/manywarnings.m4
+++ b/m4/manywarnings.m4
@@ -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
])
--
2.30.2