1 # manywarnings.m4 serial 7
2 dnl Copyright (C) 2008-2016 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;
72 [gl_cv_cc_nomfi_needed=no],
73 [gl_cv_cc_nomfi_needed=yes])
74 CFLAGS="$gl_save_CFLAGS"
76 AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
79 dnl Next, check if -Werror -Wuninitialized is useful with the
80 dnl user's choice of $CFLAGS; some versions of gcc warn that it
81 dnl has no effect if -O is not also used
82 AC_MSG_CHECKING([whether -Wuninitialized is supported])
83 AC_CACHE_VAL([gl_cv_cc_uninitialized_supported], [
84 gl_save_CFLAGS="$CFLAGS"
85 CFLAGS="$CFLAGS -Werror -Wuninitialized"
87 [AC_LANG_PROGRAM([[]], [[]])],
88 [gl_cv_cc_uninitialized_supported=yes],
89 [gl_cv_cc_uninitialized_supported=no])
90 CFLAGS="$gl_save_CFLAGS"])
91 AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
95 # List all gcc warning categories.
96 # To compare this list to your installed GCC's, run this Bash command:
99 # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
100 # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort |
102 # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
105 for gl_manywarn_item in \
109 -Waggressive-loop-optimizations \
112 -Wbad-function-cast \
114 -Wbuiltin-macro-redefined \
121 -Wcoverage-mismatch \
125 -Wdeprecated-declarations \
127 -Wdisabled-optimization \
128 -Wdiscarded-array-qualifiers \
129 -Wdiscarded-qualifiers \
136 -Wformat-contains-nul \
137 -Wformat-extra-args \
138 -Wformat-nonliteral \
140 -Wformat-signedness \
142 -Wformat-zero-length \
143 -Wfree-nonheap-object \
144 -Wignored-qualifiers \
146 -Wimplicit-function-declaration \
148 -Wincompatible-pointer-types \
152 -Wint-to-pointer-cast \
153 -Winvalid-memory-model \
156 -Wlogical-not-parentheses \
159 -Wmaybe-uninitialized \
160 -Wmemset-transposed-args \
162 -Wmissing-declarations \
163 -Wmissing-field-initializers \
164 -Wmissing-include-dirs \
165 -Wmissing-parameter-type \
166 -Wmissing-prototypes \
172 -Wold-style-declaration \
173 -Wold-style-definition \
176 -Woverlength-strings \
179 -Wpacked-bitfield-compat \
183 -Wpointer-to-int-cast \
185 -Wreturn-local-addr \
189 -Wshift-count-negative \
190 -Wshift-count-overflow \
191 -Wsizeof-array-argument \
192 -Wsizeof-pointer-memaccess \
196 -Wstrict-prototypes \
197 -Wsuggest-attribute=const \
198 -Wsuggest-attribute=format \
199 -Wsuggest-attribute=noreturn \
200 -Wsuggest-attribute=pure \
201 -Wsuggest-final-methods \
202 -Wsuggest-final-types \
213 -Wunsafe-loop-optimizations \
215 -Wunused-but-set-parameter \
216 -Wunused-but-set-variable \
219 -Wunused-local-typedefs \
227 -Wvector-operation-performance \
229 -Wvolatile-register-var \
233 gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
236 # gcc --help=warnings outputs an unusual form for these options; list
237 # them here so that the above 'comm' command doesn't report a false match.
238 gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
239 gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
241 # These are needed for older GCC versions.
242 if test -n "$GCC"; then
243 case `($CC --version) 2>/dev/null` in
244 'gcc (GCC) '[[0-3]].* | \
245 'gcc (GCC) '4.[[0-7]].*)
246 gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
247 gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
252 # Disable specific options as needed.
253 if test "$gl_cv_cc_nomfi_needed" = yes; then
254 gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
257 if test "$gl_cv_cc_uninitialized_supported" = no; then
258 gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"