changeset 17473:1175d52f956a

warnings: check -Wfoo rather than -Wno-foo As reported by Christophe Fergeau and others, use of the warnings modules is awkward when probing for negative warning flags. For example, clang recognizes -Wno-unused-command-line-argument, but gcc does not; gcc silently ignores unknown warnings in isolation, but when something else also causes a compilation problem, gcc then compounds the overall message by also complaining about the unrecongized command line option at that time. The gcc manual documents that this behavior is intentional so that someone can add a -Wno-foo silencer to CFLAGS for a warning that older gcc does not understand, and where the warning is undesired under newer gcc; it also documents that probing for the -Wfoo positive form of the error is a reliable way to tell if the negative form will actually suppress anything. Clang will warn for both positive and negative forms of an unknown option. Since common usage includes: for w in $list; do gl_WARN_ADD([$w]) done the solution must be polymorphic to work on both m4 literals and shell variables (similar to AS_VAR_SET polymorphism). * m4/warnings.m4 (gl_COMPILER_OPTION_IF): If name begins with -Wno-, test if the compiler recognizes the positive form instead. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Wed, 14 Aug 2013 17:02:58 -0600
parents 08139590730c
children 88b6cb053cd7
files ChangeLog m4/warnings.m4
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-08-15  Eric Blake  <eblake@redhat.com>
+
+	warnings: check -Wfoo rather than -Wno-foo
+	* m4/warnings.m4 (gl_COMPILER_OPTION_IF): If name begins with
+	-Wno-, test if the compiler recognizes the positive form instead.
+
 2013-08-15  Karl Berry  <karl@gnu.org>
 
 	* config/srclist-update: add option "doclicense" to placate
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -1,4 +1,4 @@
-# warnings.m4 serial 8
+# warnings.m4 serial 9
 dnl Copyright (C) 2008-2013 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -25,15 +25,24 @@
 AC_DEFUN([gl_COMPILER_OPTION_IF],
 [AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
 AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
+AS_LITERAL_IF([$1],
+  [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
+  [gl_positive="$1"
+case $gl_positive in
+  -Wno-*) gl_positive=`echo ".$gl_positive" | sed 's/^.//; s/^-Wno-/-W/'`;;
+esac
+m4_pushdef([gl_Positive], [$gl_positive])])dnl
 AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
   gl_save_compiler_FLAGS="$gl_Flags"
-  gl_AS_VAR_APPEND(m4_defn([gl_Flags]), [" $gl_unknown_warnings_are_errors $1"])
+  gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
+    [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
   AC_COMPILE_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
                     [AS_VAR_SET(gl_Warn, [yes])],
                     [AS_VAR_SET(gl_Warn, [no])])
   gl_Flags="$gl_save_compiler_FLAGS"
 ])
 AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
+m4_popdef([gl_Positive])dnl
 AS_VAR_POPDEF([gl_Flags])dnl
 AS_VAR_POPDEF([gl_Warn])dnl
 ])