1 # manywarnings-c++.m4 serial 3
2 dnl Copyright (C) 2008-2020 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 # Implementation of the specialization of gl_MANYWARN_ALL_GCC
9 AC_DEFUN([gl_MANYWARN_ALL_GCC_CXX_IMPL],
13 dnl First, check for some issues that only occur when combining multiple
14 dnl gcc warning categories.
15 AC_REQUIRE([AC_PROG_CXX])
16 if test -n "$GXX"; then
18 dnl Check if -W -Werror -Wno-missing-field-initializers is supported
19 dnl with the current $CXX $CXXFLAGS $CPPFLAGS.
20 AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported],
21 [gl_cv_cxx_nomfi_supported],
22 [gl_save_CXXFLAGS="$CXXFLAGS"
23 CXXFLAGS="$CXXFLAGS -W -Werror -Wno-missing-field-initializers"
25 [AC_LANG_PROGRAM([[]], [[]])],
26 [gl_cv_cxx_nomfi_supported=yes],
27 [gl_cv_cxx_nomfi_supported=no])
28 CXXFLAGS="$gl_save_CXXFLAGS"
31 if test "$gl_cv_cxx_nomfi_supported" = yes; then
32 dnl Now check whether -Wno-missing-field-initializers is needed
33 dnl for the { 0, } construct.
34 AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
35 [gl_cv_cxx_nomfi_needed],
36 [gl_save_CXXFLAGS="$CXXFLAGS"
37 CXXFLAGS="$CXXFLAGS -W -Werror"
42 typedef struct { int a; int b; } s_t;
48 [gl_cv_cxx_nomfi_needed=no],
49 [gl_cv_cxx_nomfi_needed=yes])
50 CXXFLAGS="$gl_save_CXXFLAGS"
54 dnl Next, check if -Werror -Wuninitialized is useful with the
55 dnl user's choice of $CXXFLAGS; some versions of gcc warn that it
56 dnl has no effect if -O is not also used
57 AC_CACHE_CHECK([whether -Wuninitialized is supported],
58 [gl_cv_cxx_uninitialized_supported],
59 [gl_save_CXXFLAGS="$CXXFLAGS"
60 CXXFLAGS="$CXXFLAGS -Werror -Wuninitialized"
62 [AC_LANG_PROGRAM([[]], [[]])],
63 [gl_cv_cxx_uninitialized_supported=yes],
64 [gl_cv_cxx_uninitialized_supported=no])
65 CXXFLAGS="$gl_save_CXXFLAGS"
70 # List all gcc warning categories.
71 # To compare this list to your installed GCC's, run this Bash command:
74 # <(sed -n 's/^ *\(-[^ ]*\) .*/\1/p' manywarnings-c++.m4 | sort) \
75 # <(gcc --help=warnings | sed -n 's/^ \(-[^ ]*\) .*/\1/p' | sort |
77 # awk '/^[^#]/ {print $1}' ../build-aux/g++-warning.spec))
80 for gl_manywarn_item in \
85 -Waggressive-loop-optimizations \
89 -Wbuiltin-macro-redefined \
96 -Wconditionally-supported \
100 -Wctor-dtor-privacy \
102 -Wdelete-incomplete \
103 -Wdelete-non-virtual-dtor \
105 -Wdeprecated-declarations \
106 -Wdisabled-optimization \
114 -Wformat-contains-nul \
115 -Wformat-extra-args \
116 -Wformat-nonliteral \
118 -Wformat-signedness \
120 -Wformat-zero-length \
121 -Wfree-nonheap-object \
122 -Wignored-qualifiers \
123 -Winherited-variadic-ctor \
126 -Wint-to-pointer-cast \
127 -Winvalid-memory-model \
131 -Wlogical-not-parentheses \
134 -Wmaybe-uninitialized \
135 -Wmemset-transposed-args \
137 -Wmissing-declarations \
138 -Wmissing-field-initializers \
139 -Wmissing-include-dirs \
143 -Wnon-template-friend \
150 -Woverlength-strings \
151 -Woverloaded-virtual \
153 -Wpacked-bitfield-compat \
159 -Wreturn-local-addr \
163 -Wshift-count-negative \
164 -Wshift-count-overflow \
166 -Wsized-deallocation \
167 -Wsizeof-array-argument \
168 -Wsizeof-pointer-memaccess \
171 -Wstrict-null-sentinel \
173 -Wsuggest-attribute=const \
174 -Wsuggest-attribute=format \
175 -Wsuggest-attribute=noreturn \
176 -Wsuggest-attribute=pure \
177 -Wsuggest-final-methods \
178 -Wsuggest-final-types \
189 -Wunsafe-loop-optimizations \
191 -Wunused-but-set-parameter \
192 -Wunused-but-set-variable \
195 -Wunused-local-typedefs \
204 -Wvector-operation-performance \
205 -Wvirtual-move-assign \
207 -Wvolatile-register-var \
209 -Wzero-as-null-pointer-constant \
212 gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
215 # gcc --help=warnings outputs an unusual form for these options; list
216 # them here so that the above 'comm' command doesn't report a false match.
217 gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
218 gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
219 gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
220 gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
222 # These are needed for older GCC versions.
223 if test -n "$GXX"; then
224 case `($CXX --version) 2>/dev/null` in
225 'g++ (GCC) '[[0-3]].* | \
226 'g++ (GCC) '4.[[0-7]].*)
227 gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
228 gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
233 # Disable specific options as needed.
234 if test "$gl_cv_cxx_nomfi_needed" = yes; then
235 gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
238 if test "$gl_cv_cxx_uninitialized_supported" = no; then
239 gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"