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