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