Set `default-directory' for watchdog in tramp-test.el
[emacs.git] / m4 / manywarnings.m4
bloba3d255a9402b4d6c93b3e8a9e07d158a4788331a
1 # manywarnings.m4 serial 11
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],
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 AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
44   AC_LANG_PUSH([C])
46   dnl First, check for some issues that only occur when combining multiple
47   dnl gcc warning categories.
48   AC_REQUIRE([AC_PROG_CC])
49   if test -n "$GCC"; then
51     dnl Check if -W -Werror -Wno-missing-field-initializers is supported
52     dnl with the current $CC $CFLAGS $CPPFLAGS.
53     AC_MSG_CHECKING([whether -Wno-missing-field-initializers is supported])
54     AC_CACHE_VAL([gl_cv_cc_nomfi_supported], [
55       gl_save_CFLAGS="$CFLAGS"
56       CFLAGS="$CFLAGS -W -Werror -Wno-missing-field-initializers"
57       AC_COMPILE_IFELSE(
58         [AC_LANG_PROGRAM([[]], [[]])],
59         [gl_cv_cc_nomfi_supported=yes],
60         [gl_cv_cc_nomfi_supported=no])
61       CFLAGS="$gl_save_CFLAGS"])
62     AC_MSG_RESULT([$gl_cv_cc_nomfi_supported])
64     if test "$gl_cv_cc_nomfi_supported" = yes; then
65       dnl Now check whether -Wno-missing-field-initializers is needed
66       dnl for the { 0, } construct.
67       AC_MSG_CHECKING([whether -Wno-missing-field-initializers is needed])
68       AC_CACHE_VAL([gl_cv_cc_nomfi_needed], [
69         gl_save_CFLAGS="$CFLAGS"
70         CFLAGS="$CFLAGS -W -Werror"
71         AC_COMPILE_IFELSE(
72           [AC_LANG_PROGRAM(
73              [[int f (void)
74                {
75                  typedef struct { int a; int b; } s_t;
76                  s_t s1 = { 0, };
77                  return s1.b;
78                }
79              ]],
80              [[]])],
81           [gl_cv_cc_nomfi_needed=no],
82           [gl_cv_cc_nomfi_needed=yes])
83         CFLAGS="$gl_save_CFLAGS"
84       ])
85       AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
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_MSG_CHECKING([whether -Wuninitialized is supported])
92     AC_CACHE_VAL([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     AC_MSG_RESULT([$gl_cv_cc_uninitialized_supported])
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/^  *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
109   #  <(gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort |
110   #      grep -v -x -F -f <(
111   #         awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
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     -Wattributes \
121     -Wbad-function-cast \
122     -Wbool-compare \
123     -Wbool-operation \
124     -Wbuiltin-declaration-mismatch \
125     -Wbuiltin-macro-redefined \
126     -Wcast-align \
127     -Wchar-subscripts \
128     -Wchkp \
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     -Wignored-attributes \
163     -Wignored-qualifiers \
164     -Wimplicit \
165     -Wimplicit-function-declaration \
166     -Wimplicit-int \
167     -Wincompatible-pointer-types \
168     -Winit-self \
169     -Winline \
170     -Wint-conversion \
171     -Wint-in-bool-context \
172     -Wint-to-pointer-cast \
173     -Winvalid-memory-model \
174     -Winvalid-pch \
175     -Wjump-misses-init \
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-braces \
184     -Wmissing-declarations \
185     -Wmissing-field-initializers \
186     -Wmissing-include-dirs \
187     -Wmissing-parameter-type \
188     -Wmissing-prototypes \
189     -Wmultichar \
190     -Wnarrowing \
191     -Wnested-externs \
192     -Wnonnull \
193     -Wnonnull-compare \
194     -Wnull-dereference \
195     -Wodr \
196     -Wold-style-declaration \
197     -Wold-style-definition \
198     -Wopenmp-simd \
199     -Woverflow \
200     -Woverlength-strings \
201     -Woverride-init \
202     -Wpacked \
203     -Wpacked-bitfield-compat \
204     -Wparentheses \
205     -Wpointer-arith \
206     -Wpointer-compare \
207     -Wpointer-sign \
208     -Wpointer-to-int-cast \
209     -Wpragmas \
210     -Wpsabi \
211     -Wrestrict \
212     -Wreturn-local-addr \
213     -Wreturn-type \
214     -Wscalar-storage-order \
215     -Wsequence-point \
216     -Wshadow \
217     -Wshift-count-negative \
218     -Wshift-count-overflow \
219     -Wshift-negative-value \
220     -Wsizeof-array-argument \
221     -Wsizeof-pointer-memaccess \
222     -Wstack-protector \
223     -Wstrict-aliasing \
224     -Wstrict-overflow \
225     -Wstrict-prototypes \
226     -Wsuggest-attribute=const \
227     -Wsuggest-attribute=format \
228     -Wsuggest-attribute=noreturn \
229     -Wsuggest-attribute=pure \
230     -Wsuggest-final-methods \
231     -Wsuggest-final-types \
232     -Wswitch \
233     -Wswitch-bool \
234     -Wswitch-default \
235     -Wswitch-unreachable \
236     -Wsync-nand \
237     -Wsystem-headers \
238     -Wtautological-compare \
239     -Wtrampolines \
240     -Wtrigraphs \
241     -Wtype-limits \
242     -Wuninitialized \
243     -Wunknown-pragmas \
244     -Wunsafe-loop-optimizations \
245     -Wunused \
246     -Wunused-but-set-parameter \
247     -Wunused-but-set-variable \
248     -Wunused-function \
249     -Wunused-label \
250     -Wunused-local-typedefs \
251     -Wunused-macros \
252     -Wunused-parameter \
253     -Wunused-result \
254     -Wunused-value \
255     -Wunused-variable \
256     -Wvarargs \
257     -Wvariadic-macros \
258     -Wvector-operation-performance \
259     -Wvla \
260     -Wvolatile-register-var \
261     -Wwrite-strings \
262     \
263     ; do
264     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
265   done
267   # gcc --help=warnings outputs an unusual form for these options; list
268   # them here so that the above 'comm' command doesn't report a false match.
269   # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal
270   # and AC_COMPUTE_INT requires it to fit in a long:
271   AC_MSG_CHECKING([max safe object size])
272   AC_COMPUTE_INT([gl_alloc_max],
273     [(LONG_MAX < PTRDIFF_MAX ? LONG_MAX : PTRDIFF_MAX) < (size_t) -1
274      ? (LONG_MAX < PTRDIFF_MAX ? LONG_MAX : PTRDIFF_MAX)
275      : (size_t) -1],
276     [[#include <limits.h>
277       #include <stddef.h>
278       #include <stdint.h>
279     ]],
280     [gl_alloc_max=2147483647])
281   AC_MSG_RESULT([$gl_alloc_max])
282   gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$gl_alloc_max"
283   gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
284   gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
285   gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
286   gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
287   gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
288   gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
289   gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
290   gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
291   gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
293   # These are needed for older GCC versions.
294   if test -n "$GCC"; then
295     case `($CC --version) 2>/dev/null` in
296       'gcc (GCC) '[[0-3]].* | \
297       'gcc (GCC) '4.[[0-7]].*)
298         gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
299         gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
300           ;;
301     esac
302   fi
304   # Disable specific options as needed.
305   if test "$gl_cv_cc_nomfi_needed" = yes; then
306     gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
307   fi
309   if test "$gl_cv_cc_uninitialized_supported" = no; then
310     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
311   fi
313   $1=$gl_manywarn_set
315   AC_LANG_POP([C])
318 # Specialization for _AC_LANG = C++.
319 AC_DEFUN([gl_MANYWARN_ALL_GCC(C++)],
321   gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])