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