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],
24 gl_AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"])
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)],
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"
58 [AC_LANG_PROGRAM([[]], [[]])],
59 [gl_cv_cc_nomfi_supported=yes],
60 [gl_cv_cc_nomfi_supported=no])
61 CFLAGS="$gl_save_CFLAGS"
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"
75 typedef struct { int a; int b; } s_t;
81 [gl_cv_cc_nomfi_needed=no],
82 [gl_cv_cc_nomfi_needed=yes])
83 CFLAGS="$gl_save_CFLAGS"
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"
95 [AC_LANG_PROGRAM([[]], [[]])],
96 [gl_cv_cc_uninitialized_supported=yes],
97 [gl_cv_cc_uninitialized_supported=no])
98 CFLAGS="$gl_save_CFLAGS"
103 # List all gcc warning categories.
104 # To compare this list to your installed GCC's, run this Bash command:
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)
112 for gl_manywarn_item in -fanalyzer -fno-common \
115 -Wbad-function-cast \
116 -Wcast-align=strict \
118 -Wdisabled-optimization \
120 -Wduplicated-branches \
123 -Wformat-signedness \
128 -Wmissing-declarations \
129 -Wmissing-include-dirs \
130 -Wmissing-prototypes \
133 -Wold-style-definition \
135 -Woverlength-strings \
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 \
155 -Wunsafe-loop-optimizations \
158 -Wvector-operation-performance \
163 gl_AS_VAR_APPEND([$1], [" $gl_manywarn_item"])
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'])
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'])
194 if test "$gl_cv_cc_uninitialized_supported" = no; then
195 gl_AS_VAR_APPEND([$1], [' -Wno-uninitialized'])
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'])
211 # Specialization for _AC_LANG = C++.
212 AC_DEFUN([gl_MANYWARN_ALL_GCC(C++)],
214 gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])