1 # manywarnings.m4 serial 8
2 dnl Copyright (C) 2008-2017 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_warn_set="$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.
36 AC_DEFUN([gl_MANYWARN_ALL_GCC],
38 dnl First, check for some issues that only occur when combining multiple
39 dnl gcc warning categories.
40 AC_REQUIRE([AC_PROG_CC])
41 if test -n "$GCC"; then
43 dnl Check if -W -Werror -Wno-missing-field-initializers is supported
44 dnl with the current $CC $CFLAGS $CPPFLAGS.
45 AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
46 AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
47 gl_save_CFLAGS="$CFLAGS"
48 CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers"
50 [AC_LANG_PROGRAM([[]], [[]])],
51 [gl_cv_cc_nomfi_supported=yes],
52 [gl_cv_cc_nomfi_supported=no])
53 CFLAGS="$gl_save_CFLAGS"])
54 AC_MSG_RESULT([$gl_cv_cc_nomfi_supported])
56 if test "$gl_cv_cc_nomfi_supported" = yes; then
57 dnl Now check whether -Wno-missing-field-initializers is needed
58 dnl for the { 0, } construct.
59 AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed])
60 AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [
61 gl_save_CFLAGS="$CFLAGS"
62 CFLAGS="$CFLAGS -W -Werror"
67 typedef struct { int a; int b; } s_t;
73 [gl_cv_cc_nomfi_needed=no],
74 [gl_cv_cc_nomfi_needed=yes])
75 CFLAGS="$gl_save_CFLAGS"
77 AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
80 dnl Next, check if -Werror -Wuninitialized is useful with the
81 dnl user's choice of $CFLAGS; some versions of gcc warn that it
82 dnl has no effect if -O is not also used
83 AC_MSG_CHECKING([whether -Wuninitialized is supported])
84 AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [
85 gl_save_CFLAGS="$CFLAGS"
86 CFLAGS="$CFLAGS -Werror -Wuninitialized"
88 [AC_LANG_PROGRAM([[]], [[]])],
89 [gl_cv_cc_uninitialized_supported=yes],
90 [gl_cv_cc_uninitialized_supported=no])
91 CFLAGS="$gl_save_CFLAGS"])
92 AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
96 # List all gcc warning categories.
97 # To compare this list to your installed GCC's, run this Bash command:
100 # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
101 # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort |
102 # grep -v -x -F -f <(
103 # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
106 for gl_manywarn_item in -fno-common \
110 -Waggressive-loop-optimizations \
113 -Wbad-function-cast \
116 -Wbuiltin-declaration-mismatch \
117 -Wbuiltin-macro-redefined \
124 -Wcoverage-mismatch \
129 -Wdeprecated-declarations \
131 -Wdisabled-optimization \
132 -Wdiscarded-array-qualifiers \
133 -Wdiscarded-qualifiers \
136 -Wduplicated-branches \
138 -Wduplicate-decl-specifier \
142 -Wexpansion-to-defined \
144 -Wformat-contains-nul \
145 -Wformat-extra-args \
146 -Wformat-nonliteral \
148 -Wformat-signedness \
150 -Wformat-zero-length \
152 -Wfree-nonheap-object \
154 -Wignored-attributes \
155 -Wignored-qualifiers \
157 -Wimplicit-function-declaration \
159 -Wincompatible-pointer-types \
163 -Wint-in-bool-context \
164 -Wint-to-pointer-cast \
165 -Winvalid-memory-model \
168 -Wlogical-not-parentheses \
171 -Wmaybe-uninitialized \
173 -Wmemset-transposed-args \
174 -Wmisleading-indentation \
176 -Wmissing-declarations \
177 -Wmissing-field-initializers \
178 -Wmissing-include-dirs \
179 -Wmissing-parameter-type \
180 -Wmissing-prototypes \
188 -Wold-style-declaration \
189 -Wold-style-definition \
192 -Woverlength-strings \
195 -Wpacked-bitfield-compat \
200 -Wpointer-to-int-cast \
204 -Wreturn-local-addr \
206 -Wscalar-storage-order \
209 -Wshift-count-negative \
210 -Wshift-count-overflow \
211 -Wshift-negative-value \
212 -Wsizeof-array-argument \
213 -Wsizeof-pointer-memaccess \
217 -Wstrict-prototypes \
218 -Wsuggest-attribute=const \
219 -Wsuggest-attribute=format \
220 -Wsuggest-attribute=noreturn \
221 -Wsuggest-attribute=pure \
222 -Wsuggest-final-methods \
223 -Wsuggest-final-types \
227 -Wswitch-unreachable \
230 -Wtautological-compare \
236 -Wunsafe-loop-optimizations \
238 -Wunused-but-set-parameter \
239 -Wunused-but-set-variable \
242 -Wunused-local-typedefs \
250 -Wvector-operation-performance \
252 -Wvolatile-register-var \
256 gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
259 # gcc --help=warnings outputs an unusual form for these options; list
260 # them here so that the above 'comm' command doesn't report a false match.
261 # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal:
262 ptrdiff_max_max=9223372036854775807
263 gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$ptrdiff_max_max"
264 gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
265 gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
266 gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
267 gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
268 gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
269 gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
270 gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
271 gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
272 gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
274 # These are needed for older GCC versions.
275 if test -n "$GCC"; then
276 case `($CC --version) 2>/dev/null` in
277 'gcc (GCC) '[[0-3]].* | \
278 'gcc (GCC) '4.[[0-7]].*)
279 gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
280 gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
285 # Disable specific options as needed.
286 if test "$gl_cv_cc_nomfi_needed" = yes; then
287 gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
290 if test "$gl_cv_cc_uninitialized_supported" = no; then
291 gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"