[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] warnings: check -Wfoo rather than -Wno-foo

From: Eric Blake
Subject: [PATCH] warnings: check -Wfoo rather than -Wno-foo
Date: Wed, 14 Aug 2013 17:33:07 -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

* 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 <address@hidden>
 ChangeLog      | 6 ++++++
 m4/warnings.m4 | 3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index ffbbeb6..5416541 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-08-14  Eric Blake  <address@hidden>
+       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-13  Paul Eggert  <address@hidden>

        xvasprintf-tests: port to GCC with hardening flags
diff --git a/m4/warnings.m4 b/m4/warnings.m4
index 1848732..afde4c5 100644
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -27,7 +27,8 @@ AC_DEFUN([gl_COMPILER_OPTION_IF],
 AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], m4_defn([gl_Warn]), [
-  gl_AS_VAR_APPEND(m4_defn([gl_Flags]), [" $gl_unknown_warnings_are_errors 
+  gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
+    [" $gl_unknown_warnings_are_errors ]m4_bpatsubst([$1], [^-Wno-], [-W])["])
   AC_COMPILE_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([])])],
                     [AS_VAR_SET(gl_Warn, [yes])],
                     [AS_VAR_SET(gl_Warn, [no])])

reply via email to

[Prev in Thread] Current Thread [Next in Thread]