3 dnl Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl From Simon Josefsson
12 # gl_MANYWARN_COMPLEMENT(OUTVAR, LISTVAR, REMOVEVAR)
13 # --------------------------------------------------
14 # Copy LISTVAR to OUTVAR except for the entries in REMOVEVAR.
15 # Elements separated by whitespace. In set logic terms, the function
16 # does OUTVAR = LISTVAR \ REMOVEVAR.
17 AC_DEFUN([gl_MANYWARN_COMPLEMENT],
27 AS_VAR_APPEND([gl_warn_set], [" $gl_warn_item"])
34 # gl_MANYWARN_ALL_GCC(VARIABLE)
35 # -----------------------------
36 # Add all documented GCC warning parameters to variable VARIABLE.
37 # Note that you need to test them using gl_WARN_ADD if you want to
38 # make sure your gcc understands it.
40 # The effects of this macro depend on the current language (_AC_LANG).
41 AC_DEFUN([gl_MANYWARN_ALL_GCC],
42 [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
44 # Specialization for _AC_LANG = C.
45 AC_DEFUN([gl_MANYWARN_ALL_GCC(C)],
49 dnl First, check for some issues that only occur when combining multiple
50 dnl gcc warning categories.
51 AC_REQUIRE([AC_PROG_CC])
52 AS_IF([test -n "$GCC"], [
53 AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
54 [gl_cv_cc_nomfi_needed],
55 [gl_cv_cc_nomfi_needed=no
56 gl_saved_CFLAGS="$CFLAGS"
57 CFLAGS="$CFLAGS -Wextra -Werror"
60 [[struct file_data { int desc, name; };
61 struct cmp { struct file_data file[1]; };
62 void f (struct cmp *r)
64 typedef struct { int a; int b; } s_t;
66 struct cmp cmp = { .file[0].desc = r->file[0].desc + s1.a };
72 [CFLAGS="$CFLAGS -Wno-missing-field-initializers"
74 [gl_cv_cc_nomfi_needed=yes])])
75 CFLAGS="$gl_saved_CFLAGS"
78 dnl Next, check if -Werror -Wuninitialized is useful with the
79 dnl user's choice of $CFLAGS; some versions of gcc warn that it
80 dnl has no effect if -O is not also used
81 AC_CACHE_CHECK([whether -Wuninitialized is supported],
82 [gl_cv_cc_uninitialized_supported],
83 [gl_saved_CFLAGS="$CFLAGS"
84 CFLAGS="$CFLAGS -Werror -Wuninitialized"
86 [AC_LANG_PROGRAM([[]], [[]])],
87 [gl_cv_cc_uninitialized_supported=yes],
88 [gl_cv_cc_uninitialized_supported=no])
89 CFLAGS="$gl_saved_CFLAGS"
93 # List all gcc warning categories.
94 # To compare this list to your installed GCC's, run this Bash command:
97 # <((sed -n 's/^ *\(-[^ 0-9][^ ]*\).*/\1/p' manywarnings.m4; \
98 # awk '/^[^#]/ {print $1}' ../build-aux/gcc-warning.spec) | sort) \
99 # <(LC_ALL=C gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort)
102 for gl_manywarn_item in -fanalyzer -fstrict-flex-arrays \
105 -Wbad-function-cast \
106 -Wcast-align=strict \
108 -Wdisabled-optimization \
110 -Wduplicated-branches \
113 -Wformat-signedness \
114 -Wflex-array-member-not-at-end \
119 -Wmissing-declarations \
120 -Wmissing-include-dirs \
121 -Wmissing-prototypes \
122 -Wmissing-variable-declarations \
125 -Wold-style-definition \
127 -Woverlength-strings \
132 -Wstrict-flex-arrays \
134 -Wstrict-prototypes \
135 -Wsuggest-attribute=cold \
136 -Wsuggest-attribute=const \
137 -Wsuggest-attribute=format \
138 -Wsuggest-attribute=malloc \
139 -Wsuggest-attribute=noreturn \
140 -Wsuggest-attribute=pure \
141 -Wsuggest-final-methods \
142 -Wsuggest-final-types \
148 -Wunsafe-loop-optimizations \
151 -Wvector-operation-performance \
156 AS_VAR_APPEND([$1], [" $gl_manywarn_item"])
159 # gcc --help=warnings outputs an unusual form for these options; list
160 # them here so that the above 'comm' command doesn't report a false match.
161 AS_VAR_APPEND([$1], [' -Warray-bounds=2'])
162 AS_VAR_APPEND([$1], [' -Wattribute-alias=2'])
163 AS_VAR_APPEND([$1], [' -Wbidi-chars=any,ucn'])
164 AS_VAR_APPEND([$1], [' -Wformat-overflow=2'])
165 AS_VAR_APPEND([$1], [' -Wformat=2'])
166 AS_VAR_APPEND([$1], [' -Wformat-truncation=2'])
167 AS_VAR_APPEND([$1], [' -Wimplicit-fallthrough=5'])
168 AS_VAR_APPEND([$1], [' -Wshift-overflow=2'])
169 AS_VAR_APPEND([$1], [' -Wuse-after-free=3'])
170 AS_VAR_APPEND([$1], [' -Wunused-const-variable=2'])
171 AS_VAR_APPEND([$1], [' -Wvla-larger-than=4031'])
173 # These are needed for older GCC versions.
174 if test -n "$GCC" && gl_gcc_version=`($CC --version) 2>/dev/null`; then
175 case $gl_gcc_version in
176 'gcc (GCC) '[[0-3]].* | \
177 'gcc (GCC) '4.[[0-7]].*)
178 AS_VAR_APPEND([$1], [' -fdiagnostics-show-option'])
179 AS_VAR_APPEND([$1], [' -funit-at-a-time'])
182 case $gl_gcc_version in
183 'gcc (GCC) '[[0-9]].*)
184 AS_VAR_APPEND([$1], [' -fno-common'])
189 # Disable specific options as needed.
190 if test "$gl_cv_cc_nomfi_needed" = yes; then
191 AS_VAR_APPEND([$1], [' -Wno-missing-field-initializers'])
194 if test "$gl_cv_cc_uninitialized_supported" = no; then
195 AS_VAR_APPEND([$1], [' -Wno-uninitialized'])
198 # This warning have too many false alarms in GCC 11.2.1.
199 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101713
200 AS_VAR_APPEND([$1], [' -Wno-analyzer-malloc-leak'])
205 # Specialization for _AC_LANG = C++.
206 AC_DEFUN([gl_MANYWARN_ALL_GCC(C++)],
208 gl_MANYWARN_ALL_GCC_CXX_IMPL([$1])