From: Bruno Haible Date: Fri, 2 Jun 2023 21:41:47 +0000 (+0200) Subject: warnings: Add ability to inhibit all warnings. X-Git-Tag: v1.0~1262 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a601878fb65bcc8f80594d6700b24778926b9f56;p=gnulib.git 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/ChangeLog b/ChangeLog index f93c5e3ad2..3187128c1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-06-02 Bruno Haible + + 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 propername-lite: new module 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 @@ 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: