Do the Windows oldnames workaround through the C++ GNULIB_NAMESPACE.
[gnulib.git] / m4 / manywarnings.m4
bloba37cd15b69a48bd182b571970773b2f31fdb5231
1 # manywarnings.m4 serial 21
2 dnl Copyright (C) 2008-2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl From Simon Josefsson
9 # gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR)
10 # --------------------------------------------------
11 # Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR.
12 # Elements separated by whitespace.  In set logic terms, the function
13 # does OUTVAR = LISTVAR \ REMOVEVAR.
14 AC_DEFUN([gl_MANYWARN_COMPLEMENT],
16   gl_warn_set=
17   set x $2; shift
18   for gl_warn_item
19   do
20     case " $3 " in
21       *" $gl_warn_item "*)
22         ;;
23       *)
24         gl_AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"])
25         ;;
26     esac
27   done
28   $1=$gl_warn_set
31 # gl_MANYWARN_ALL_GCC(VARIABLE)
32 # -----------------------------
33 # Add all documented GCC warning parameters to variable VARIABLE.
34 # Note that you need to test them using gl_WARN_ADD if you want to
35 # make sure your gcc understands it.
37 # The effects of this macro depend on the current language (_AC_LANG).
38 AC_DEFUN([gl_MANYWARN_ALL_GCC],
39 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
41 # Specialization for _AC_LANG = C.
42 AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
44   AC_LANG_PUSH([C])
46   dnl First, check for some issues that only occur when combining multiple
47   dnl gcc warning categories.
48   AC_REQUIRE([AC_PROG_CC])
49   if test -n "$GCC"; then
51     dnl Check if -Wextra -Werror -Wno-missing-field-initializers is supported
52     dnl with the current $CC $CFLAGS $CPPFLAGS.
53     AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported],
54       [gl_cv_cc_nomfi_supported],
55       [gl_save_CFLAGS="$CFLAGS"
56        CFLAGS="$CFLAGS -Wextra -Werror -Wno-missing-field-initializers"
57        AC_COMPILE_IFELSE(
58          [AC_LANG_PROGRAM([[]], [[]])],
59          [gl_cv_cc_nomfi_supported=yes],
60          [gl_cv_cc_nomfi_supported=no])
61        CFLAGS="$gl_save_CFLAGS"
62       ])
64     if test "$gl_cv_cc_nomfi_supported" = yes; then
65       dnl Now check whether -Wno-missing-field-initializers is needed
66       dnl for the { 0, } construct.
67       AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
68         [gl_cv_cc_nomfi_needed],
69         [gl_save_CFLAGS="$CFLAGS"
70          CFLAGS="$CFLAGS -Wextra -Werror"
71          AC_COMPILE_IFELSE(
72            [AC_LANG_PROGRAM(
73               [[int f (void)
74                 {
75                   typedef struct { int a; int b; } s_t;
76                   s_t s1 = { 0, };
77                   return s1.b;
78                 }
79               ]],
80               [[]])],
81            [gl_cv_cc_nomfi_needed=no],
82            [gl_cv_cc_nomfi_needed=yes])
83          CFLAGS="$gl_save_CFLAGS"
84         ])
85     fi
87     dnl Next, check if -Werror -Wuninitialized is useful with the
88     dnl user's choice of $CFLAGS; some versions of gcc warn that it
89     dnl has no effect if -O is not also used
90     AC_CACHE_CHECK([whether -Wuninitialized is supported],
91       [gl_cv_cc_uninitialized_supported],
92       [gl_save_CFLAGS="$CFLAGS"
93        CFLAGS="$CFLAGS -Werror -Wuninitialized"
94        AC_COMPILE_IFELSE(
95          [AC_LANG_PROGRAM([[]], [[]])],
96          [gl_cv_cc_uninitialized_supported=yes],
97          [gl_cv_cc_uninitialized_supported=no])
98        CFLAGS="$gl_save_CFLAGS"
99       ])
101   fi
103   # List all gcc warning categories.
104   # To compare this list to your installed GCC's, run this Bash command:
105   #
106   # comm -3 \
107   #  <((sed -n 's/^  *\(-[^ 0-9][^ ]*\).*/\1/p' manywarnings.m4; \
108   #     awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \
109   #  <(LC_ALL=C gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort)
111   $1=
112   for gl_manywarn_item in -fanalyzer -fno-common \
113     -Wall \
114     -Warith-conversion \
115     -Wbad-function-cast \
116     -Wcast-align=strict \
117     -Wdate-time \
118     -Wdisabled-optimization \
119     -Wdouble-promotion \
120     -Wduplicated-branches \
121     -Wduplicated-cond \
122     -Wextra \
123     -Wformat-signedness \
124     -Winit-self \
125     -Winline \
126     -Winvalid-pch \
127     -Wlogical-op \
128     -Wmissing-declarations \
129     -Wmissing-include-dirs \
130     -Wmissing-prototypes \
131     -Wnested-externs \
132     -Wnull-dereference \
133     -Wold-style-definition \
134     -Wopenmp-simd \
135     -Woverlength-strings \
136     -Wpacked \
137     -Wpointer-arith \
138     -Wshadow \
139     -Wstack-protector \
140     -Wstrict-overflow \
141     -Wstrict-prototypes \
142     -Wsuggest-attribute=cold \
143     -Wsuggest-attribute=const \
144     -Wsuggest-attribute=format \
145     -Wsuggest-attribute=malloc \
146     -Wsuggest-attribute=noreturn \
147     -Wsuggest-attribute=pure \
148     -Wsuggest-final-methods \
149     -Wsuggest-final-types \
150     -Wsync-nand \
151     -Wsystem-headers \
152     -Wtrampolines \
153     -Wuninitialized \
154     -Wunknown-pragmas \
155     -Wunsafe-loop-optimizations \
156     -Wunused-macros \
157     -Wvariadic-macros \
158     -Wvector-operation-performance \
159     -Wvla \
160     -Wwrite-strings \
161     \
162     ; do
163     gl_AS_VAR_APPEND([$1], [" $gl_manywarn_item"])
164   done
166   # gcc --help=warnings outputs an unusual form for these options; list
167   # them here so that the above 'comm' command doesn't report a false match.
168   gl_AS_VAR_APPEND([$1], [' -Warray-bounds=2'])
169   gl_AS_VAR_APPEND([$1], [' -Wattribute-alias=2'])
170   gl_AS_VAR_APPEND([$1], [' -Wformat-overflow=2'])
171   gl_AS_VAR_APPEND([$1], [' -Wformat=2'])
172   gl_AS_VAR_APPEND([$1], [' -Wformat-truncation=2'])
173   gl_AS_VAR_APPEND([$1], [' -Wimplicit-fallthrough=5'])
174   gl_AS_VAR_APPEND([$1], [' -Wshift-overflow=2'])
175   gl_AS_VAR_APPEND([$1], [' -Wunused-const-variable=2'])
176   gl_AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031'])
178   # These are needed for older GCC versions.
179   if test -n "$GCC"; then
180     case `($CC --version) 2>/dev/null` in
181       'gcc (GCC) '[[0-3]].* | \
182       'gcc (GCC) '4.[[0-7]].*)
183         gl_AS_VAR_APPEND([$1], [' -fdiagnostics-show-option'])
184         gl_AS_VAR_APPEND([$1], [' -funit-at-a-time'])
185           ;;
186     esac
187   fi
189   # Disable specific options as needed.
190   if test "$gl_cv_cc_nomfi_needed" = yes; then
191     gl_AS_VAR_APPEND([$1], [' -Wno-missing-field-initializers'])
192   fi
194   if test "$gl_cv_cc_uninitialized_supported" = no; then
195     gl_AS_VAR_APPEND([$1], [' -Wno-uninitialized'])
196   fi
198   # Some warnings have too many false alarms in GCC 10.1.
199   # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93695
200   gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-double-free'])
201   # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94458
202   gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-malloc-leak'])
203   # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94851
204   gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-null-dereference'])
205   # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95758
206   gl_AS_VAR_APPEND([$1], [' -Wno-analyzer-use-after-free'])
208   AC_LANG_POP([C])
211 # Specialization for _AC_LANG = C++.
212 AC_DEFUN([gl_MANYWARN_ALL_GCC(C++)],
214   gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])