Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs
[emacs.git] / m4 / manywarnings.m4
blob90823b0acf4145236941f88a35f39274d4b81a39
1 # manywarnings.m4 serial 8
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],
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.
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"
49       AC_COMPILE_IFELSE(
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"
63         AC_COMPILE_IFELSE(
64           [AC_LANG_PROGRAM(
65              [[void f (void)
66                {
67                  typedef struct { int a; int b; } s_t;
68                  s_t s1 = { 0, };
69                }
70              ]],
71              [[]])],
72           [gl_cv_cc_nomfi_needed=no],
73           [gl_cv_cc_nomfi_needed=yes])
74         CFLAGS="$gl_save_CFLAGS"
75       ])
76       AC_MSG_RESULT([$gl_cv_cc_nomfi_needed])
77     fi
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"
86       AC_COMPILE_IFELSE(
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])
93   fi
95   # List all gcc warning categories.
96   # To compare this list to your installed GCC's, run this Bash command:
97   #
98   # comm -3 \
99   #  <(sed -n 's/^  *\(-[^ ]*\) .*/\1/p' manywarnings.m4 | sort) \
100   #  <(gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort |
101   #      grep -v -x -f <(
102   #         awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
104   gl_manywarn_set=
105   for gl_manywarn_item in \
106     -W \
107     -Wabi \
108     -Waddress \
109     -Waggressive-loop-optimizations \
110     -Wall \
111     -Wattributes \
112     -Wbad-function-cast \
113     -Wbool-compare \
114     -Wbuiltin-macro-redefined \
115     -Wcast-align \
116     -Wchar-subscripts \
117     -Wchkp \
118     -Wclobbered \
119     -Wcomment \
120     -Wcomments \
121     -Wcoverage-mismatch \
122     -Wcpp \
123     -Wdate-time \
124     -Wdeprecated \
125     -Wdeprecated-declarations \
126     -Wdesignated-init \
127     -Wdisabled-optimization \
128     -Wdiscarded-array-qualifiers \
129     -Wdiscarded-qualifiers \
130     -Wdiv-by-zero \
131     -Wdouble-promotion \
132     -Wduplicated-cond \
133     -Wempty-body \
134     -Wendif-labels \
135     -Wenum-compare \
136     -Wextra \
137     -Wformat-contains-nul \
138     -Wformat-extra-args \
139     -Wformat-nonliteral \
140     -Wformat-security \
141     -Wformat-signedness \
142     -Wformat-y2k \
143     -Wformat-zero-length \
144     -Wframe-address \
145     -Wfree-nonheap-object \
146     -Whsa \
147     -Wignored-attributes \
148     -Wignored-qualifiers \
149     -Wimplicit \
150     -Wimplicit-function-declaration \
151     -Wimplicit-int \
152     -Wincompatible-pointer-types \
153     -Winit-self \
154     -Winline \
155     -Wint-conversion \
156     -Wint-to-pointer-cast \
157     -Winvalid-memory-model \
158     -Winvalid-pch \
159     -Wjump-misses-init \
160     -Wlogical-not-parentheses \
161     -Wlogical-op \
162     -Wmain \
163     -Wmaybe-uninitialized \
164     -Wmemset-transposed-args \
165     -Wmisleading-indentation \
166     -Wmissing-braces \
167     -Wmissing-declarations \
168     -Wmissing-field-initializers \
169     -Wmissing-include-dirs \
170     -Wmissing-parameter-type \
171     -Wmissing-prototypes \
172     -Wmultichar \
173     -Wnarrowing \
174     -Wnested-externs \
175     -Wnonnull \
176     -Wnonnull-compare \
177     -Wnull-dereference \
178     -Wodr \
179     -Wold-style-declaration \
180     -Wold-style-definition \
181     -Wopenmp-simd \
182     -Woverflow \
183     -Woverlength-strings \
184     -Woverride-init \
185     -Wpacked \
186     -Wpacked-bitfield-compat \
187     -Wparentheses \
188     -Wpointer-arith \
189     -Wpointer-sign \
190     -Wpointer-to-int-cast \
191     -Wpragmas \
192     -Wreturn-local-addr \
193     -Wreturn-type \
194     -Wscalar-storage-order \
195     -Wsequence-point \
196     -Wshadow \
197     -Wshift-count-negative \
198     -Wshift-count-overflow \
199     -Wshift-negative-value \
200     -Wsizeof-array-argument \
201     -Wsizeof-pointer-memaccess \
202     -Wstack-protector \
203     -Wstrict-aliasing \
204     -Wstrict-overflow \
205     -Wstrict-prototypes \
206     -Wsuggest-attribute=const \
207     -Wsuggest-attribute=format \
208     -Wsuggest-attribute=noreturn \
209     -Wsuggest-attribute=pure \
210     -Wsuggest-final-methods \
211     -Wsuggest-final-types \
212     -Wswitch \
213     -Wswitch-bool \
214     -Wswitch-default \
215     -Wsync-nand \
216     -Wsystem-headers \
217     -Wtautological-compare \
218     -Wtrampolines \
219     -Wtrigraphs \
220     -Wtype-limits \
221     -Wuninitialized \
222     -Wunknown-pragmas \
223     -Wunsafe-loop-optimizations \
224     -Wunused \
225     -Wunused-but-set-parameter \
226     -Wunused-but-set-variable \
227     -Wunused-function \
228     -Wunused-label \
229     -Wunused-local-typedefs \
230     -Wunused-macros \
231     -Wunused-parameter \
232     -Wunused-result \
233     -Wunused-value \
234     -Wunused-variable \
235     -Wvarargs \
236     -Wvariadic-macros \
237     -Wvector-operation-performance \
238     -Wvla \
239     -Wvolatile-register-var \
240     -Wwrite-strings \
241     \
242     ; do
243     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
244   done
246   # gcc --help=warnings outputs an unusual form for these options; list
247   # them here so that the above 'comm' command doesn't report a false match.
248   gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
249   gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
250   gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
251   gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
253   # These are needed for older GCC versions.
254   if test -n "$GCC"; then
255     case `($CC --version) 2>/dev/null` in
256       'gcc (GCC) '[[0-3]].* | \
257       'gcc (GCC) '4.[[0-7]].*)
258         gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
259         gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
260           ;;
261     esac
262   fi
264   # Disable specific options as needed.
265   if test "$gl_cv_cc_nomfi_needed" = yes; then
266     gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
267   fi
269   if test "$gl_cv_cc_uninitialized_supported" = no; then
270     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
271   fi
273   $1=$gl_manywarn_set