stdopen: Fix compilation error with IRIX cc.
[gnulib.git] / m4 / manywarnings.m4
blobe0488a5cb3866de5790bef13ed0527e14313d241
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],
16   gl_warn_set=
17   set x $2; shift
18   for gl_warn_item
19   do
20     case " $3 " in
21       *" $gl_warn_item "*)
22         ;;
23       *)
24         gl_warn_set="$gl_warn_set $gl_warn_item"
25         ;;
26     esac
27   done
28   $1=$gl_warn_set
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)],
45   AC_LANG_PUSH([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"
58        AC_COMPILE_IFELSE(
59          [AC_LANG_PROGRAM([[]], [[]])],
60          [gl_cv_cc_nomfi_supported=yes],
61          [gl_cv_cc_nomfi_supported=no])
62        CFLAGS="$gl_save_CFLAGS"
63       ])
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"
72          AC_COMPILE_IFELSE(
73            [AC_LANG_PROGRAM(
74               [[int f (void)
75                 {
76                   typedef struct { int a; int b; } s_t;
77                   s_t s1 = { 0, };
78                   return s1.b;
79                 }
80               ]],
81               [[]])],
82            [gl_cv_cc_nomfi_needed=no],
83            [gl_cv_cc_nomfi_needed=yes])
84          CFLAGS="$gl_save_CFLAGS"
85         ])
86     fi
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"
95        AC_COMPILE_IFELSE(
96          [AC_LANG_PROGRAM([[]], [[]])],
97          [gl_cv_cc_uninitialized_supported=yes],
98          [gl_cv_cc_uninitialized_supported=no])
99        CFLAGS="$gl_save_CFLAGS"
100       ])
102   fi
104   # List all gcc warning categories.
105   # To compare this list to your installed GCC's, run this Bash command:
106   #
107   # comm -3 \
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)
112   gl_manywarn_set=
113   for gl_manywarn_item in -fno-common \
114     -W \
115     -Waddress \
116     -Waggressive-loop-optimizations \
117     -Wall \
118     -Wattribute-alias \
119     -Wattributes \
120     -Wbad-function-cast \
121     -Wbool-compare \
122     -Wbool-operation \
123     -Wbuiltin-declaration-mismatch \
124     -Wbuiltin-macro-redefined \
125     -Wcast-align \
126     -Wcast-align=strict \
127     -Wcast-function-type \
128     -Wchar-subscripts \
129     -Wclobbered \
130     -Wcomment \
131     -Wcomments \
132     -Wcoverage-mismatch \
133     -Wcpp \
134     -Wdangling-else \
135     -Wdate-time \
136     -Wdeprecated \
137     -Wdeprecated-declarations \
138     -Wdesignated-init \
139     -Wdisabled-optimization \
140     -Wdiscarded-array-qualifiers \
141     -Wdiscarded-qualifiers \
142     -Wdiv-by-zero \
143     -Wdouble-promotion \
144     -Wduplicated-branches \
145     -Wduplicated-cond \
146     -Wduplicate-decl-specifier \
147     -Wempty-body \
148     -Wendif-labels \
149     -Wenum-compare \
150     -Wexpansion-to-defined \
151     -Wextra \
152     -Wformat-contains-nul \
153     -Wformat-extra-args \
154     -Wformat-nonliteral \
155     -Wformat-security \
156     -Wformat-signedness \
157     -Wformat-y2k \
158     -Wformat-zero-length \
159     -Wframe-address \
160     -Wfree-nonheap-object \
161     -Whsa \
162     -Wif-not-aligned \
163     -Wignored-attributes \
164     -Wignored-qualifiers \
165     -Wimplicit \
166     -Wimplicit-function-declaration \
167     -Wimplicit-int \
168     -Wincompatible-pointer-types \
169     -Winit-self \
170     -Winline \
171     -Wint-conversion \
172     -Wint-in-bool-context \
173     -Wint-to-pointer-cast \
174     -Winvalid-memory-model \
175     -Winvalid-pch \
176     -Wlogical-not-parentheses \
177     -Wlogical-op \
178     -Wmain \
179     -Wmaybe-uninitialized \
180     -Wmemset-elt-size \
181     -Wmemset-transposed-args \
182     -Wmisleading-indentation \
183     -Wmissing-attributes \
184     -Wmissing-braces \
185     -Wmissing-declarations \
186     -Wmissing-field-initializers \
187     -Wmissing-include-dirs \
188     -Wmissing-parameter-type \
189     -Wmissing-prototypes \
190     -Wmultichar \
191     -Wmultistatement-macros \
192     -Wnarrowing \
193     -Wnested-externs \
194     -Wnonnull \
195     -Wnonnull-compare \
196     -Wnull-dereference \
197     -Wodr \
198     -Wold-style-declaration \
199     -Wold-style-definition \
200     -Wopenmp-simd \
201     -Woverflow \
202     -Woverlength-strings \
203     -Woverride-init \
204     -Wpacked \
205     -Wpacked-bitfield-compat \
206     -Wpacked-not-aligned \
207     -Wparentheses \
208     -Wpointer-arith \
209     -Wpointer-compare \
210     -Wpointer-sign \
211     -Wpointer-to-int-cast \
212     -Wpragmas \
213     -Wpsabi \
214     -Wrestrict \
215     -Wreturn-local-addr \
216     -Wreturn-type \
217     -Wscalar-storage-order \
218     -Wsequence-point \
219     -Wshadow \
220     -Wshift-count-negative \
221     -Wshift-count-overflow \
222     -Wshift-negative-value \
223     -Wsizeof-array-argument \
224     -Wsizeof-pointer-div \
225     -Wsizeof-pointer-memaccess \
226     -Wstack-protector \
227     -Wstrict-aliasing \
228     -Wstrict-overflow \
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 \
239     -Wswitch \
240     -Wswitch-bool \
241     -Wswitch-unreachable \
242     -Wsync-nand \
243     -Wsystem-headers \
244     -Wtautological-compare \
245     -Wtrampolines \
246     -Wtrigraphs \
247     -Wtype-limits \
248     -Wuninitialized \
249     -Wunknown-pragmas \
250     -Wunsafe-loop-optimizations \
251     -Wunused \
252     -Wunused-but-set-parameter \
253     -Wunused-but-set-variable \
254     -Wunused-function \
255     -Wunused-label \
256     -Wunused-local-typedefs \
257     -Wunused-macros \
258     -Wunused-parameter \
259     -Wunused-result \
260     -Wunused-value \
261     -Wunused-variable \
262     -Wvarargs \
263     -Wvariadic-macros \
264     -Wvector-operation-performance \
265     -Wvla \
266     -Wvolatile-register-var \
267     -Wwrite-strings \
268     \
269     ; do
270     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
271   done
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
278   # a special case.
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)
282      ? -1
283      : PTRDIFF_MAX < (size_t) -1 ? (long) PTRDIFF_MAX : (long) (size_t) -1],
284     [[#include <limits.h>
285       #include <stddef.h>
286       #include <stdint.h>
287     ]],
288     [gl_alloc_max=2147483647])
289   case $gl_alloc_max in
290     -1) gl_alloc_max=9223372036854775807;;
291   esac
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"
311           ;;
312     esac
313   fi
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"
318   fi
320   if test "$gl_cv_cc_uninitialized_supported" = no; then
321     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
322   fi
324   $1=$gl_manywarn_set
326   AC_LANG_POP([C])
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])