bug-gnulib
[Top][All Lists]
Advanced

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

warnings: Add ability to inhibit all warnings


From: Bruno Haible
Subject: warnings: Add ability to inhibit all warnings
Date: Fri, 02 Jun 2023 23:47:16 +0200

In GNU gettext and other packages, some source files are being compiled twice.
It's not useful to see the warnings twice, only once. Therefore a way to
inhibit all warnings in a particular compiler invocation is useful.

This patch adds this ability to the 'warnings' module. (Creating a separate
module just for these autoconf macros feels like overkill.)


2023-06-02  Bruno Haible  <bruno@clisp.org>

        warnings: Add ability to inhibit all warnings.
        * m4/warnings.m4 (gl_CC_INHIBIT_WARNINGS, gl_CXX_INHIBIT_WARNINGS): New
        macros, based on gl_CC_ALLOW_WARNINGS and gl_CXX_ALLOW_WARNINGS in
        m4/gnulib-common.m4.

diff --git a/m4/warnings.m4 b/m4/warnings.m4
index 76e97907b5..1a3107f846 100644
--- a/m4/warnings.m4
+++ b/m4/warnings.m4
@@ -1,4 +1,4 @@
-# warnings.m4 serial 17
+# warnings.m4 serial 18
 dnl Copyright (C) 2008-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -98,6 +98,67 @@ AC_DEFUN([gl_WARN_ADD]
          [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
 ])
 
+
+# gl_CC_INHIBIT_WARNINGS
+# sets and substitutes a variable GL_CFLAG_INHIBIT_WARNINGS, to a $(CC) option
+# that reverts all preceding -W* options, if available.
+# This is expected to be '-w' at least on gcc, clang, AIX xlc, xlclang, Sun cc,
+# "compile cl" (MSVC), "compile clang-cl" (MSVC-compatible clang). Or it can be
+# empty.
+AC_DEFUN([gl_CC_INHIBIT_WARNINGS],
+[
+  AC_REQUIRE([AC_PROG_CC])
+  AC_CACHE_CHECK([for C compiler option to inhibit all warnings],
+    [gl_cv_cc_winhibit],
+    [rm -f conftest*
+     echo 'int dummy;' > conftest.c
+     AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -c conftest.c 
2>conftest1.err]) >/dev/null
+     AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS -w -c conftest.c 
2>conftest2.err]) >/dev/null
+     if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < conftest2.err`; 
then
+       gl_cv_cc_winhibit='-w'
+     else
+       gl_cv_cc_winhibit=none
+     fi
+     rm -f conftest*
+    ])
+  case "$gl_cv_cc_winhibit" in
+    none) GL_CFLAG_INHIBIT_WARNINGS='' ;;
+    *)    GL_CFLAG_INHIBIT_WARNINGS="$gl_cv_cc_winhibit" ;;
+  esac
+  AC_SUBST([GL_CFLAG_INHIBIT_WARNINGS])
+])
+
+# gl_CXX_INHIBIT_WARNINGS
+# sets and substitutes a variable GL_CXXFLAG_INHIBIT_WARNINGS, to a $(CC) 
option
+# that reverts all preceding -W* options, if available.
+AC_DEFUN([gl_CXX_INHIBIT_WARNINGS],
+[
+  dnl Requires AC_PROG_CXX or gl_PROG_ANSI_CXX.
+  if test -n "$CXX" && test "$CXX" != no; then
+    AC_CACHE_CHECK([for C++ compiler option to inhibit all warnings],
+      [gl_cv_cxx_winhibit],
+      [rm -f conftest*
+       echo 'int dummy;' > conftest.cc
+       AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -c conftest.cc 
2>conftest1.err]) >/dev/null
+       AC_TRY_COMMAND([${CXX-c++} $CXXFLAGS $CPPFLAGS -w -c conftest.cc 
2>conftest2.err]) >/dev/null
+       if test $? = 0 && test `wc -l < conftest1.err` = `wc -l < 
conftest2.err`; then
+         gl_cv_cxx_winhibit='-w'
+       else
+         gl_cv_cxx_winhibit=none
+       fi
+       rm -f conftest*
+      ])
+    case "$gl_cv_cxx_winhibit" in
+      none) GL_CXXFLAG_INHIBIT_WARNINGS='' ;;
+      *)    GL_CXXFLAG_INHIBIT_WARNINGS="$gl_cv_cxx_winhibit" ;;
+    esac
+  else
+    GL_CXXFLAG_INHIBIT_WARNINGS=''
+  fi
+  AC_SUBST([GL_CXXFLAG_INHIBIT_WARNINGS])
+])
+
+
 # Local Variables:
 # mode: autoconf
 # End:






reply via email to

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