warnings: check -Wfoo rather than -Wno-foo
authorEric Blake <eblake@redhat.com>
Wed, 14 Aug 2013 23:02:58 +0000 (17:02 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 15 Aug 2013 19:39:28 +0000 (13:39 -0600)
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>
ChangeLog
m4/warnings.m4

index 5d17fbd..beb2c80 100644 (file)
--- 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
index 1848732..cbe08b5 100644 (file)
@@ -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 @@ m4_ifdef([AS_VAR_APPEND],
 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
 ])