obstack-zprintf: Add more tests.
[gnulib.git] / m4 / manywarnings-c++.m4
blobdf190674f9fd2765c6fdf5b6989f3d74a48af809
1 # manywarnings-c++.m4
2 # serial 4
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 # Implementation of the specialization of gl_MANYWARN_ALL_GCC
9 # for _AC_LANG = C++.
10 AC_DEFUN([gl_MANYWARN_ALL_GCC_CXX_IMPL],
12   AC_LANG_PUSH([C++])
14   dnl First, check for some issues that only occur when combining multiple
15   dnl gcc warning categories.
16   AC_REQUIRE([AC_PROG_CXX])
17   if test -n "$GXX"; then
19     dnl Check if -W -Werror -Wno-missing-field-initializers is supported
20     dnl with the current $CXX $CXXFLAGS $CPPFLAGS.
21     AC_CACHE_CHECK([whether -Wno-missing-field-initializers is supported],
22       [gl_cv_cxx_nomfi_supported],
23       [gl_saved_CXXFLAGS="$CXXFLAGS"
24        CXXFLAGS="$CXXFLAGS -W -Werror -Wno-missing-field-initializers"
25        AC_COMPILE_IFELSE(
26          [AC_LANG_PROGRAM([[]], [[]])],
27          [gl_cv_cxx_nomfi_supported=yes],
28          [gl_cv_cxx_nomfi_supported=no])
29        CXXFLAGS="$gl_saved_CXXFLAGS"
30       ])
32     if test "$gl_cv_cxx_nomfi_supported" = yes; then
33       dnl Now check whether -Wno-missing-field-initializers is needed
34       dnl for the { 0, } construct.
35       AC_CACHE_CHECK([whether -Wno-missing-field-initializers is needed],
36         [gl_cv_cxx_nomfi_needed],
37         [gl_saved_CXXFLAGS="$CXXFLAGS"
38          CXXFLAGS="$CXXFLAGS -W -Werror"
39          AC_COMPILE_IFELSE(
40            [AC_LANG_PROGRAM(
41               [[int f (void)
42                 {
43                   typedef struct { int a; int b; } s_t;
44                   s_t s1 = { 0, };
45                   return s1.b;
46                 }
47               ]],
48               [[]])],
49            [gl_cv_cxx_nomfi_needed=no],
50            [gl_cv_cxx_nomfi_needed=yes])
51          CXXFLAGS="$gl_saved_CXXFLAGS"
52         ])
53     fi
55     dnl Next, check if -Werror -Wuninitialized is useful with the
56     dnl user's choice of $CXXFLAGS; some versions of gcc warn that it
57     dnl has no effect if -O is not also used
58     AC_CACHE_CHECK([whether -Wuninitialized is supported],
59       [gl_cv_cxx_uninitialized_supported],
60       [gl_saved_CXXFLAGS="$CXXFLAGS"
61        CXXFLAGS="$CXXFLAGS -Werror -Wuninitialized"
62        AC_COMPILE_IFELSE(
63          [AC_LANG_PROGRAM([[]], [[]])],
64          [gl_cv_cxx_uninitialized_supported=yes],
65          [gl_cv_cxx_uninitialized_supported=no])
66        CXXFLAGS="$gl_saved_CXXFLAGS"
67       ])
69   fi
71   # List all gcc warning categories.
72   # To compare this list to your installed GCC's, run this Bash command:
73   #
74   # comm -3 \
75   #  <(sed -n 's/^  *\(-[^ ]*\) .*/\1/p' manywarnings-c++.m4 | sort) \
76   #  <(gcc --help=warnings | sed -n 's/^  \(-[^ ]*\) .*/\1/p' | sort |
77   #      grep -v -x -f <(
78   #         awk '/^[^#]/ {print $1}' ../build-aux/g++-warning.spec))
80   gl_manywarn_set=
81   for gl_manywarn_item in \
82     -W \
83     -Wabi-tag \
84     -Waddress \
85     -Waggressive-loop-optimizations \
86     -Wall \
87     -Wattributes \
88     -Wbool-compare \
89     -Wbuiltin-macro-redefined \
90     -Wcast-align \
91     -Wchar-subscripts \
92     -Wclobbered \
93     -Wcomment \
94     -Wcomments \
95     -Wconditionally-supported \
96     -Wconversion-null \
97     -Wcoverage-mismatch \
98     -Wcpp \
99     -Wctor-dtor-privacy \
100     -Wdate-time \
101     -Wdelete-incomplete \
102     -Wdelete-non-virtual-dtor \
103     -Wdeprecated \
104     -Wdeprecated-declarations \
105     -Wdisabled-optimization \
106     -Wdiv-by-zero \
107     -Wdouble-promotion \
108     -Weffc++ \
109     -Wempty-body \
110     -Wendif-labels \
111     -Wenum-compare \
112     -Wextra \
113     -Wformat-contains-nul \
114     -Wformat-extra-args \
115     -Wformat-nonliteral \
116     -Wformat-security \
117     -Wformat-signedness \
118     -Wformat-y2k \
119     -Wformat-zero-length \
120     -Wfree-nonheap-object \
121     -Wignored-qualifiers \
122     -Winherited-variadic-ctor \
123     -Winit-self \
124     -Winline \
125     -Wint-to-pointer-cast \
126     -Winvalid-memory-model \
127     -Winvalid-offsetof \
128     -Winvalid-pch \
129     -Wliteral-suffix \
130     -Wlogical-not-parentheses \
131     -Wlogical-op \
132     -Wmain \
133     -Wmaybe-uninitialized \
134     -Wmemset-transposed-args \
135     -Wmissing-braces \
136     -Wmissing-declarations \
137     -Wmissing-field-initializers \
138     -Wmissing-include-dirs \
139     -Wmultichar \
140     -Wnarrowing \
141     -Wnoexcept \
142     -Wnon-template-friend \
143     -Wnon-virtual-dtor \
144     -Wnonnull \
145     -Wodr \
146     -Wold-style-cast \
147     -Wopenmp-simd \
148     -Woverflow \
149     -Woverlength-strings \
150     -Woverloaded-virtual \
151     -Wpacked \
152     -Wpacked-bitfield-compat \
153     -Wparentheses \
154     -Wpmf-conversions \
155     -Wpointer-arith \
156     -Wpragmas \
157     -Wreorder \
158     -Wreturn-local-addr \
159     -Wreturn-type \
160     -Wsequence-point \
161     -Wshadow \
162     -Wshift-count-negative \
163     -Wshift-count-overflow \
164     -Wsign-promo \
165     -Wsized-deallocation \
166     -Wsizeof-array-argument \
167     -Wsizeof-pointer-memaccess \
168     -Wstack-protector \
169     -Wstrict-aliasing \
170     -Wstrict-null-sentinel \
171     -Wstrict-overflow \
172     -Wsuggest-attribute=const \
173     -Wsuggest-attribute=format \
174     -Wsuggest-attribute=noreturn \
175     -Wsuggest-attribute=pure \
176     -Wsuggest-final-methods \
177     -Wsuggest-final-types \
178     -Wsuggest-override \
179     -Wswitch \
180     -Wswitch-bool \
181     -Wsync-nand \
182     -Wsystem-headers \
183     -Wtrampolines \
184     -Wtrigraphs \
185     -Wtype-limits \
186     -Wuninitialized \
187     -Wunknown-pragmas \
188     -Wunsafe-loop-optimizations \
189     -Wunused \
190     -Wunused-but-set-parameter \
191     -Wunused-but-set-variable \
192     -Wunused-function \
193     -Wunused-label \
194     -Wunused-local-typedefs \
195     -Wunused-macros \
196     -Wunused-parameter \
197     -Wunused-result \
198     -Wunused-value \
199     -Wunused-variable \
200     -Wuseless-cast \
201     -Wvarargs \
202     -Wvariadic-macros \
203     -Wvector-operation-performance \
204     -Wvirtual-move-assign \
205     -Wvla \
206     -Wvolatile-register-var \
207     -Wwrite-strings \
208     -Wzero-as-null-pointer-constant \
209     \
210     ; do
211     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
212   done
214   # gcc --help=warnings outputs an unusual form for these options; list
215   # them here so that the above 'comm' command doesn't report a false match.
216   gl_manywarn_set="$gl_manywarn_set -Warray-bounds=2"
217   gl_manywarn_set="$gl_manywarn_set -Wnormalized=nfc"
218   gl_manywarn_set="$gl_manywarn_set -Wshift-overflow=2"
219   gl_manywarn_set="$gl_manywarn_set -Wunused-const-variable=2"
221   # These are needed for older GCC versions.
222   if test -n "$GXX"; then
223     case `($CXX --version) 2>/dev/null` in
224       'g++ (GCC) '[[0-3]].* | \
225       'g++ (GCC) '4.[[0-7]].*)
226         gl_manywarn_set="$gl_manywarn_set -fdiagnostics-show-option"
227         gl_manywarn_set="$gl_manywarn_set -funit-at-a-time"
228           ;;
229     esac
230   fi
232   # Disable specific options as needed.
233   if test "$gl_cv_cxx_nomfi_needed" = yes; then
234     gl_manywarn_set="$gl_manywarn_set -Wno-missing-field-initializers"
235   fi
237   if test "$gl_cv_cxx_uninitialized_supported" = no; then
238     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
239   fi
241   $1=$gl_manywarn_set
243   AC_LANG_POP([C++])