; * src/json.c: Fix typo in license statement
[emacs.git] / m4 / manywarnings.m4
blob516c5874765804f7a60a74f2bdbf2314e4ed2e72
1 # manywarnings.m4 serial 16
2 dnl Copyright (C) 2008-2018 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_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"
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     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"
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       AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
87     fi
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"
96       AC_COMPILE_IFELSE(
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])
103   fi
105   # List all gcc warning categories.
106   # To compare this list to your installed GCC's, run this Bash command:
107   #
108   # comm -3 \
109   #  <((sed -n 's/^  *\(-[^ 0-9][^ ]*\) .*/\1/p' manywarnings.m4; \
110   #     awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \
111   #  <(LC_ALL=C gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort)
113   gl_manywarn_set=
114   for gl_manywarn_item in -fno-common \
115     -W \
116     -Waddress \
117     -Waggressive-loop-optimizations \
118     -Wall \
119     -Wattribute-alias \
120     -Wattributes \
121     -Wbad-function-cast \
122     -Wbool-compare \
123     -Wbool-operation \
124     -Wbuiltin-declaration-mismatch \
125     -Wbuiltin-macro-redefined \
126     -Wcast-align \
127     -Wcast-align=strict \
128     -Wcast-function-type \
129     -Wchar-subscripts \
130     -Wclobbered \
131     -Wcomment \
132     -Wcomments \
133     -Wcoverage-mismatch \
134     -Wcpp \
135     -Wdangling-else \
136     -Wdate-time \
137     -Wdeprecated \
138     -Wdeprecated-declarations \
139     -Wdesignated-init \
140     -Wdisabled-optimization \
141     -Wdiscarded-array-qualifiers \
142     -Wdiscarded-qualifiers \
143     -Wdiv-by-zero \
144     -Wdouble-promotion \
145     -Wduplicated-branches \
146     -Wduplicated-cond \
147     -Wduplicate-decl-specifier \
148     -Wempty-body \
149     -Wendif-labels \
150     -Wenum-compare \
151     -Wexpansion-to-defined \
152     -Wextra \
153     -Wformat-contains-nul \
154     -Wformat-extra-args \
155     -Wformat-nonliteral \
156     -Wformat-security \
157     -Wformat-signedness \
158     -Wformat-y2k \
159     -Wformat-zero-length \
160     -Wframe-address \
161     -Wfree-nonheap-object \
162     -Whsa \
163     -Wif-not-aligned \
164     -Wignored-attributes \
165     -Wignored-qualifiers \
166     -Wimplicit \
167     -Wimplicit-function-declaration \
168     -Wimplicit-int \
169     -Wincompatible-pointer-types \
170     -Winit-self \
171     -Winline \
172     -Wint-conversion \
173     -Wint-in-bool-context \
174     -Wint-to-pointer-cast \
175     -Winvalid-memory-model \
176     -Winvalid-pch \
177     -Wlogical-not-parentheses \
178     -Wlogical-op \
179     -Wmain \
180     -Wmaybe-uninitialized \
181     -Wmemset-elt-size \
182     -Wmemset-transposed-args \
183     -Wmisleading-indentation \
184     -Wmissing-attributes \
185     -Wmissing-braces \
186     -Wmissing-declarations \
187     -Wmissing-field-initializers \
188     -Wmissing-include-dirs \
189     -Wmissing-parameter-type \
190     -Wmissing-prototypes \
191     -Wmultichar \
192     -Wmultistatement-macros \
193     -Wnarrowing \
194     -Wnested-externs \
195     -Wnonnull \
196     -Wnonnull-compare \
197     -Wnull-dereference \
198     -Wodr \
199     -Wold-style-declaration \
200     -Wold-style-definition \
201     -Wopenmp-simd \
202     -Woverflow \
203     -Woverlength-strings \
204     -Woverride-init \
205     -Wpacked \
206     -Wpacked-bitfield-compat \
207     -Wpacked-not-aligned \
208     -Wparentheses \
209     -Wpointer-arith \
210     -Wpointer-compare \
211     -Wpointer-sign \
212     -Wpointer-to-int-cast \
213     -Wpragmas \
214     -Wpsabi \
215     -Wrestrict \
216     -Wreturn-local-addr \
217     -Wreturn-type \
218     -Wscalar-storage-order \
219     -Wsequence-point \
220     -Wshadow \
221     -Wshift-count-negative \
222     -Wshift-count-overflow \
223     -Wshift-negative-value \
224     -Wsizeof-array-argument \
225     -Wsizeof-pointer-div \
226     -Wsizeof-pointer-memaccess \
227     -Wstack-protector \
228     -Wstrict-aliasing \
229     -Wstrict-overflow \
230     -Wstrict-prototypes \
231     -Wstringop-truncation \
232     -Wsuggest-attribute=cold \
233     -Wsuggest-attribute=const \
234     -Wsuggest-attribute=format \
235     -Wsuggest-attribute=malloc \
236     -Wsuggest-attribute=noreturn \
237     -Wsuggest-attribute=pure \
238     -Wsuggest-final-methods \
239     -Wsuggest-final-types \
240     -Wswitch \
241     -Wswitch-bool \
242     -Wswitch-unreachable \
243     -Wsync-nand \
244     -Wsystem-headers \
245     -Wtautological-compare \
246     -Wtrampolines \
247     -Wtrigraphs \
248     -Wtype-limits \
249     -Wuninitialized \
250     -Wunknown-pragmas \
251     -Wunsafe-loop-optimizations \
252     -Wunused \
253     -Wunused-but-set-parameter \
254     -Wunused-but-set-variable \
255     -Wunused-function \
256     -Wunused-label \
257     -Wunused-local-typedefs \
258     -Wunused-macros \
259     -Wunused-parameter \
260     -Wunused-result \
261     -Wunused-value \
262     -Wunused-variable \
263     -Wvarargs \
264     -Wvariadic-macros \
265     -Wvector-operation-performance \
266     -Wvla \
267     -Wvolatile-register-var \
268     -Wwrite-strings \
269     \
270     ; do
271     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
272   done
274   # gcc --help=warnings outputs an unusual form for these options; list
275   # them here so that the above 'comm' command doesn't report a false match.
276   # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal.
277   # Also, AC_COMPUTE_INT requires it to fit in a long; it is 2**63 on
278   # the only platforms where it does not fit in a long, so make that
279   # a special case.
280   AC_MSG_CHECKING([max safe object size])
281   AC_COMPUTE_INT([gl_alloc_max],
282     [LONG_MAX < (PTRDIFF_MAX < (size_t) -1 ? PTRDIFF_MAX : (size_t) -1)
283      ? -1
284      : PTRDIFF_MAX < (size_t) -1 ? (long) PTRDIFF_MAX : (long) (size_t) -1],
285     [[#include <limits.h>
286       #include <stddef.h>
287       #include <stdint.h>
288     ]],
289     [gl_alloc_max=2147483647])
290   case $gl_alloc_max in
291     -1) gl_alloc_max=9223372036854775807;;
292   esac
293   AC_MSG_RESULT([$gl_alloc_max])
294   gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$gl_alloc_max"
295   gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
296   gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
297   gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
298   gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
299   gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
300   gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
301   gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
302   gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
303   gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
305   # These are needed for older GCC versions.
306   if test -n "$GCC"; then
307     case `($CC --version) 2>/dev/null` in
308       'gcc (GCC) '[[0-3]].* | \
309       'gcc (GCC) '4.[[0-7]].*)
310         gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
311         gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
312           ;;
313     esac
314   fi
316   # Disable specific options as needed.
317   if test "$gl_cv_cc_nomfi_needed" = yes; then
318     gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
319   fi
321   if test "$gl_cv_cc_uninitialized_supported" = no; then
322     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
323   fi
325   $1=$gl_manywarn_set
327   AC_LANG_POP([C])
330 # Specialization for _AC_LANG = C++.
331 # Use of m4_defun rather than AC_DEFUN works around a bug in autoconf < 2.63b.
332 m4_defun([gl_MANYWARN_ALL_GCC(C++)],
334   gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])