1 # manywarnings.m4 serial 17
2 dnl Copyright (C) 2008-2019 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.
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 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
43 m4_defun([gl_MANYWARN_ALL_GCC(C)],
47 dnl First, check for some issues that only occur when combining multiple
48 dnl gcc warning categories.
49 AC_REQUIRE([AC_PROG_CC])
50 if test -n "$GCC"; then
52 dnl Check if -W -Werror -Wno-missing-field-initializers is supported
53 dnl with the current $CC $CFLAGS $CPPFLAGS.
54 AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported],
55 [gl_cv_cc_nomfi_supported],
56 [gl_save_CFLAGS="$CFLAGS"
57 CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers"
59 [AC_LANG_PROGRAM([[]], [[]])],
60 [gl_cv_cc_nomfi_supported=yes],
61 [gl_cv_cc_nomfi_supported=no])
62 CFLAGS="$gl_save_CFLAGS"
65 if test "$gl_cv_cc_nomfi_supported" = yes; then
66 dnl Now check whether -Wno-missing-field-initializers is needed
67 dnl for the { 0, } construct.
68 AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
69 [gl_cv_cc_nomfi_needed],
70 [gl_save_CFLAGS="$CFLAGS"
71 CFLAGS="$CFLAGS -W -Werror"
76 typedef struct { int a; int b; } s_t;
82 [gl_cv_cc_nomfi_needed=no],
83 [gl_cv_cc_nomfi_needed=yes])
84 CFLAGS="$gl_save_CFLAGS"
88 dnl Next, check if -Werror -Wuninitialized is useful with the
89 dnl user's choice of $CFLAGS; some versions of gcc warn that it
90 dnl has no effect if -O is not also used
91 AC_CACHE_CHECK([whether -Wuninitialized is supported],
92 [gl_cv_cc_uninitialized_supported],
93 [gl_save_CFLAGS="$CFLAGS"
94 CFLAGS="$CFLAGS -Werror -Wuninitialized"
96 [AC_LANG_PROGRAM([[]], [[]])],
97 [gl_cv_cc_uninitialized_supported=yes],
98 [gl_cv_cc_uninitialized_supported=no])
99 CFLAGS="$gl_save_CFLAGS"
104 # List all gcc warning categories.
105 # To compare this list to your installed GCC's, run this Bash command:
108 # <((sed -n 's/^ *\(-[^ 0-9][^ ]*\) .*/\1/p' manywarnings.m4; \
109 # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \
110 # <(LC_ALL=C gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort)
113 for gl_manywarn_item in -fno-common \
116 -Waggressive-loop-optimizations \
120 -Wbad-function-cast \
123 -Wbuiltin-declaration-mismatch \
124 -Wbuiltin-macro-redefined \
126 -Wcast-align=strict \
127 -Wcast-function-type \
132 -Wcoverage-mismatch \
137 -Wdeprecated-declarations \
139 -Wdisabled-optimization \
140 -Wdiscarded-array-qualifiers \
141 -Wdiscarded-qualifiers \
144 -Wduplicated-branches \
146 -Wduplicate-decl-specifier \
150 -Wexpansion-to-defined \
152 -Wformat-contains-nul \
153 -Wformat-extra-args \
154 -Wformat-nonliteral \
156 -Wformat-signedness \
158 -Wformat-zero-length \
160 -Wfree-nonheap-object \
163 -Wignored-attributes \
164 -Wignored-qualifiers \
166 -Wimplicit-function-declaration \
168 -Wincompatible-pointer-types \
172 -Wint-in-bool-context \
173 -Wint-to-pointer-cast \
174 -Winvalid-memory-model \
176 -Wlogical-not-parentheses \
179 -Wmaybe-uninitialized \
181 -Wmemset-transposed-args \
182 -Wmisleading-indentation \
183 -Wmissing-attributes \
185 -Wmissing-declarations \
186 -Wmissing-field-initializers \
187 -Wmissing-include-dirs \
188 -Wmissing-parameter-type \
189 -Wmissing-prototypes \
191 -Wmultistatement-macros \
198 -Wold-style-declaration \
199 -Wold-style-definition \
202 -Woverlength-strings \
205 -Wpacked-bitfield-compat \
206 -Wpacked-not-aligned \
211 -Wpointer-to-int-cast \
215 -Wreturn-local-addr \
217 -Wscalar-storage-order \
220 -Wshift-count-negative \
221 -Wshift-count-overflow \
222 -Wshift-negative-value \
223 -Wsizeof-array-argument \
224 -Wsizeof-pointer-div \
225 -Wsizeof-pointer-memaccess \
229 -Wstrict-prototypes \
230 -Wstringop-truncation \
231 -Wsuggest-attribute=cold \
232 -Wsuggest-attribute=const \
233 -Wsuggest-attribute=format \
234 -Wsuggest-attribute=malloc \
235 -Wsuggest-attribute=noreturn \
236 -Wsuggest-attribute=pure \
237 -Wsuggest-final-methods \
238 -Wsuggest-final-types \
241 -Wswitch-unreachable \
244 -Wtautological-compare \
250 -Wunsafe-loop-optimizations \
252 -Wunused-but-set-parameter \
253 -Wunused-but-set-variable \
256 -Wunused-local-typedefs \
264 -Wvector-operation-performance \
266 -Wvolatile-register-var \
270 gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
273 # gcc --help=warnings outputs an unusual form for these options; list
274 # them here so that the above 'comm' command doesn't report a false match.
275 # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal.
276 # Also, AC_COMPUTE_INT requires it to fit in a long; it is 2**63 on
277 # the only platforms where it does not fit in a long, so make that
279 AC_MSG_CHECKING([max safe object size])
280 AC_COMPUTE_INT([gl_alloc_max],
281 [LONG_MAX < (PTRDIFF_MAX < (size_t) -1 ? PTRDIFF_MAX : (size_t) -1)
283 : PTRDIFF_MAX < (size_t) -1 ? (long) PTRDIFF_MAX : (long) (size_t) -1],
284 [[#include <limits.h>
288 [gl_alloc_max=2147483647])
289 case $gl_alloc_max in
290 -1) gl_alloc_max=9223372036854775807;;
292 AC_MSG_RESULT([$gl_alloc_max])
293 gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$gl_alloc_max"
294 gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
295 gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
296 gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
297 gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
298 gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
299 gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
300 gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
301 gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
302 gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
304 # These are needed for older GCC versions.
305 if test -n "$GCC"; then
306 case `($CC --version) 2>/dev/null` in
307 'gcc (GCC) '[[0-3]].* | \
308 'gcc (GCC) '4.[[0-7]].*)
309 gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
310 gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
315 # Disable specific options as needed.
316 if test "$gl_cv_cc_nomfi_needed" = yes; then
317 gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
320 if test "$gl_cv_cc_uninitialized_supported" = no; then
321 gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
329 # Specialization for _AC_LANG = C++.
330 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
331 m4_defun([gl_MANYWARN_ALL_GCC(C++)],
333 gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])