1 # manywarnings.m4 serial 13
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.
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_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
55 AC_CACHE_VAL([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"])
63 AC_MSG_RESULT([$gl_cv_cc_nomfi_supported])
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_MSG_CHECKING([whether -Wno-missing-field-initializers is needed])
69 AC_CACHE_VAL([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"
86 AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
89 dnl Next, check if -Werror -Wuninitialized is useful with the
90 dnl user's choice of $CFLAGS; some versions of gcc warn that it
91 dnl has no effect if -O is not also used
92 AC_MSG_CHECKING([whether -Wuninitialized is supported])
93 AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [
94 gl_save_CFLAGS="$CFLAGS"
95 CFLAGS="$CFLAGS -Werror -Wuninitialized"
97 [AC_LANG_PROGRAM([[]], [[]])],
98 [gl_cv_cc_uninitialized_supported=yes],
99 [gl_cv_cc_uninitialized_supported=no])
100 CFLAGS="$gl_save_CFLAGS"])
101 AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
105 # List all gcc warning categories.
106 # To compare this list to your installed GCC's, run this Bash command:
109 # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
110 # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort |
111 # grep -v -x -F -f <(
112 # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
115 for gl_manywarn_item in -fno-common \
119 -Waggressive-loop-optimizations \
122 -Wbad-function-cast \
125 -Wbuiltin-declaration-mismatch \
126 -Wbuiltin-macro-redefined \
133 -Wcoverage-mismatch \
138 -Wdeprecated-declarations \
140 -Wdisabled-optimization \
141 -Wdiscarded-array-qualifiers \
142 -Wdiscarded-qualifiers \
145 -Wduplicated-branches \
147 -Wduplicate-decl-specifier \
151 -Wexpansion-to-defined \
153 -Wformat-contains-nul \
154 -Wformat-extra-args \
155 -Wformat-nonliteral \
157 -Wformat-signedness \
159 -Wformat-zero-length \
161 -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 \
177 -Wlogical-not-parentheses \
180 -Wmaybe-uninitialized \
182 -Wmemset-transposed-args \
183 -Wmisleading-indentation \
185 -Wmissing-declarations \
186 -Wmissing-field-initializers \
187 -Wmissing-include-dirs \
188 -Wmissing-parameter-type \
189 -Wmissing-prototypes \
197 -Wold-style-declaration \
198 -Wold-style-definition \
201 -Woverlength-strings \
204 -Wpacked-bitfield-compat \
209 -Wpointer-to-int-cast \
213 -Wreturn-local-addr \
215 -Wscalar-storage-order \
218 -Wshift-count-negative \
219 -Wshift-count-overflow \
220 -Wshift-negative-value \
221 -Wsizeof-array-argument \
222 -Wsizeof-pointer-memaccess \
226 -Wstrict-prototypes \
227 -Wsuggest-attribute=const \
228 -Wsuggest-attribute=format \
229 -Wsuggest-attribute=noreturn \
230 -Wsuggest-attribute=pure \
231 -Wsuggest-final-methods \
232 -Wsuggest-final-types \
236 -Wswitch-unreachable \
239 -Wtautological-compare \
245 -Wunsafe-loop-optimizations \
247 -Wunused-but-set-parameter \
248 -Wunused-but-set-variable \
251 -Wunused-local-typedefs \
259 -Wvector-operation-performance \
261 -Wvolatile-register-var \
265 gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
268 # gcc --help=warnings outputs an unusual form for these options; list
269 # them here so that the above 'comm' command doesn't report a false match.
270 # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal.
271 # Also, AC_COMPUTE_INT requires it to fit in a long; it is 2**63 on
272 # the only platforms where it does not fit in a long, so make that
274 AC_MSG_CHECKING([max safe object size])
275 AC_COMPUTE_INT([gl_alloc_max],
276 [LONG_MAX < (PTRDIFF_MAX < (size_t) -1 ? PTRDIFF_MAX : (size_t) -1)
278 : PTRDIFF_MAX < (size_t) -1 ? (long) PTRDIFF_MAX : (long) (size_t) -1],
279 [[#include <limits.h>
283 [gl_alloc_max=2147483647])
284 case $gl_alloc_max in
285 -1) gl_alloc_max=9223372036854775807;;
287 AC_MSG_RESULT([$gl_alloc_max])
288 gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$gl_alloc_max"
289 gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
290 gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
291 gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
292 gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
293 gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
294 gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
295 gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
296 gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
297 gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
299 # These are needed for older GCC versions.
300 if test -n "$GCC"; then
301 case `($CC --version) 2>/dev/null` in
302 'gcc (GCC) '[[0-3]].* | \
303 'gcc (GCC) '4.[[0-7]].*)
304 gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
305 gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
310 # Disable specific options as needed.
311 if test "$gl_cv_cc_nomfi_needed" = yes; then
312 gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
315 if test "$gl_cv_cc_uninitialized_supported" = no; then
316 gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
324 # Specialization for _AC_LANG = C++.
325 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
326 m4_defun([gl_MANYWARN_ALL_GCC(C++)],
328 gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])