Commentary enhancement in frame.el
[emacs.git] / m4 / manywarnings.m4
blob2d35eff6a2cf2981469f14212b11d70fec251561
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 -f <(
103   #         awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec))
105   gl_manywarn_set=
106   for gl_manywarn_item in -fno-common \
107     -W \
108     -Wabi \
109     -Waddress \
110     -Waggressive-loop-optimizations \
111     -Wall \
112     -Wattributes \
113     -Wbad-function-cast \
114     -Wbool-compare \
115     -Wbool-operation \
116     -Wbuiltin-declaration-mismatch \
117     -Wbuiltin-macro-redefined \
118     -Wcast-align \
119     -Wchar-subscripts \
120     -Wchkp \
121     -Wclobbered \
122     -Wcomment \
123     -Wcomments \
124     -Wcoverage-mismatch \
125     -Wcpp \
126     -Wdangling-else \
127     -Wdate-time \
128     -Wdeprecated \
129     -Wdeprecated-declarations \
130     -Wdesignated-init \
131     -Wdisabled-optimization \
132     -Wdiscarded-array-qualifiers \
133     -Wdiscarded-qualifiers \
134     -Wdiv-by-zero \
135     -Wdouble-promotion \
136     -Wduplicated-branches \
137     -Wduplicated-cond \
138     -Wduplicate-decl-specifier \
139     -Wempty-body \
140     -Wendif-labels \
141     -Wenum-compare \
142     -Wexpansion-to-defined \
143     -Wextra \
144     -Wformat-contains-nul \
145     -Wformat-extra-args \
146     -Wformat-nonliteral \
147     -Wformat-security \
148     -Wformat-signedness \
149     -Wformat-y2k \
150     -Wformat-zero-length \
151     -Wframe-address \
152     -Wfree-nonheap-object \
153     -Whsa \
154     -Wignored-attributes \
155     -Wignored-qualifiers \
156     -Wimplicit \
157     -Wimplicit-function-declaration \
158     -Wimplicit-int \
159     -Wincompatible-pointer-types \
160     -Winit-self \
161     -Winline \
162     -Wint-conversion \
163     -Wint-in-bool-context \
164     -Wint-to-pointer-cast \
165     -Winvalid-memory-model \
166     -Winvalid-pch \
167     -Wjump-misses-init \
168     -Wlogical-not-parentheses \
169     -Wlogical-op \
170     -Wmain \
171     -Wmaybe-uninitialized \
172     -Wmemset-elt-size \
173     -Wmemset-transposed-args \
174     -Wmisleading-indentation \
175     -Wmissing-braces \
176     -Wmissing-declarations \
177     -Wmissing-field-initializers \
178     -Wmissing-include-dirs \
179     -Wmissing-parameter-type \
180     -Wmissing-prototypes \
181     -Wmultichar \
182     -Wnarrowing \
183     -Wnested-externs \
184     -Wnonnull \
185     -Wnonnull-compare \
186     -Wnull-dereference \
187     -Wodr \
188     -Wold-style-declaration \
189     -Wold-style-definition \
190     -Wopenmp-simd \
191     -Woverflow \
192     -Woverlength-strings \
193     -Woverride-init \
194     -Wpacked \
195     -Wpacked-bitfield-compat \
196     -Wparentheses \
197     -Wpointer-arith \
198     -Wpointer-compare \
199     -Wpointer-sign \
200     -Wpointer-to-int-cast \
201     -Wpragmas \
202     -Wpsabi \
203     -Wrestrict \
204     -Wreturn-local-addr \
205     -Wreturn-type \
206     -Wscalar-storage-order \
207     -Wsequence-point \
208     -Wshadow \
209     -Wshift-count-negative \
210     -Wshift-count-overflow \
211     -Wshift-negative-value \
212     -Wsizeof-array-argument \
213     -Wsizeof-pointer-memaccess \
214     -Wstack-protector \
215     -Wstrict-aliasing \
216     -Wstrict-overflow \
217     -Wstrict-prototypes \
218     -Wsuggest-attribute=const \
219     -Wsuggest-attribute=format \
220     -Wsuggest-attribute=noreturn \
221     -Wsuggest-attribute=pure \
222     -Wsuggest-final-methods \
223     -Wsuggest-final-types \
224     -Wswitch \
225     -Wswitch-bool \
226     -Wswitch-default \
227     -Wswitch-unreachable \
228     -Wsync-nand \
229     -Wsystem-headers \
230     -Wtautological-compare \
231     -Wtrampolines \
232     -Wtrigraphs \
233     -Wtype-limits \
234     -Wuninitialized \
235     -Wunknown-pragmas \
236     -Wunsafe-loop-optimizations \
237     -Wunused \
238     -Wunused-but-set-parameter \
239     -Wunused-but-set-variable \
240     -Wunused-function \
241     -Wunused-label \
242     -Wunused-local-typedefs \
243     -Wunused-macros \
244     -Wunused-parameter \
245     -Wunused-result \
246     -Wunused-value \
247     -Wunused-variable \
248     -Wvarargs \
249     -Wvariadic-macros \
250     -Wvector-operation-performance \
251     -Wvla \
252     -Wvolatile-register-var \
253     -Wwrite-strings \
254     \
255     ; do
256     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
257   done
259   # gcc --help=warnings outputs an unusual form for these options; list
260   # them here so that the above 'comm' command doesn't report a false match.
261   # Would prefer "min (PTRDIFF_MAX, SIZE_MAX)", but it must be a literal:
262   ptrdiff_max_max=9223372036854775807
263   gl_manywarn_set="$gl_manywarn_set -Walloc-size-larger-than=$ptrdiff_max_max"
264   gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
265   gl_manywarn_set="$gl_manywarn_set -Wformat-overflow=2"
266   gl_manywarn_set="$gl_manywarn_set -Wformat-truncation=2"
267   gl_manywarn_set="$gl_manywarn_set -Wimplicit-fallthrough=5"
268   gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
269   gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
270   gl_manywarn_set="$gl_manywarn_set -Wstringop-overflow=2"
271   gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
272   gl_manywarn_set="$gl_manywarn_set -Wvla-larger-than=4031"
274   # These are needed for older GCC versions.
275   if test -n "$GCC"; then
276     case `($CC --version) 2>/dev/null` in
277       'gcc (GCC) '[[0-3]].* | \
278       'gcc (GCC) '4.[[0-7]].*)
279         gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
280         gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
281           ;;
282     esac
283   fi
285   # Disable specific options as needed.
286   if test "$gl_cv_cc_nomfi_needed" = yes; then
287     gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
288   fi
290   if test "$gl_cv_cc_uninitialized_supported" = no; then
291     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
292   fi
294   $1=$gl_manywarn_set