]> Savannah Git Hosting - gnulib.git/commitdiff
warnings: Add ability to inhibit all warnings.
authorBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 21:41:47 +0000 (23:41 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 2 Jun 2023 21:48:19 +0000 (23:48 +0200)
* 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.

ChangeLog
m4/warnings.m4

index f93c5e3ad24e0a1f591c01d47feca0c155a9ebbd..3187128c1f25c17c31b8122a6f383a283e3942fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
 2023-06-02  Paul Eggert  <eggert@cs.ucla.edu>
 
        propername-lite: new module
index 76e97907b5c54c3312aad7036cd1a9b89482ccb7..1a3107f846d5c501cb42c0d72cfaccd800885255 100644 (file)
@@ -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 @@ m4_ifval([$2],
          [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: