localename: Fine-tune support for per-thread locales on Solaris 11.4.
[gnulib.git] / m4 / manywarnings-c++.m4
blobdea8e1970b4339220d44aa62370838f602781488
1 # manywarnings-c++.m4 serial 3
2 dnl Copyright (C) 2008-2018 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 \
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     -Wchkp \
93     -Wclobbered \
94     -Wcomment \
95     -Wcomments \
96     -Wconditionally-supported \
97     -Wconversion-null \
98     -Wcoverage-mismatch \
99     -Wcpp \
100     -Wctor-dtor-privacy \
101     -Wdate-time \
102     -Wdelete-incomplete \
103     -Wdelete-non-virtual-dtor \
104     -Wdeprecated \
105     -Wdeprecated-declarations \
106     -Wdisabled-optimization \
107     -Wdiv-by-zero \
108     -Wdouble-promotion \
109     -Weffc++ \
110     -Wempty-body \
111     -Wendif-labels \
112     -Wenum-compare \
113     -Wextra \
114     -Wformat-contains-nul \
115     -Wformat-extra-args \
116     -Wformat-nonliteral \
117     -Wformat-security \
118     -Wformat-signedness \
119     -Wformat-y2k \
120     -Wformat-zero-length \
121     -Wfree-nonheap-object \
122     -Wignored-qualifiers \
123     -Winherited-variadic-ctor \
124     -Winit-self \
125     -Winline \
126     -Wint-to-pointer-cast \
127     -Winvalid-memory-model \
128     -Winvalid-offsetof \
129     -Winvalid-pch \
130     -Wliteral-suffix \
131     -Wlogical-not-parentheses \
132     -Wlogical-op \
133     -Wmain \
134     -Wmaybe-uninitialized \
135     -Wmemset-transposed-args \
136     -Wmissing-braces \
137     -Wmissing-declarations \
138     -Wmissing-field-initializers \
139     -Wmissing-include-dirs \
140     -Wmultichar \
141     -Wnarrowing \
142     -Wnoexcept \
143     -Wnon-template-friend \
144     -Wnon-virtual-dtor \
145     -Wnonnull \
146     -Wodr \
147     -Wold-style-cast \
148     -Wopenmp-simd \
149     -Woverflow \
150     -Woverlength-strings \
151     -Woverloaded-virtual \
152     -Wpacked \
153     -Wpacked-bitfield-compat \
154     -Wparentheses \
155     -Wpmf-conversions \
156     -Wpointer-arith \
157     -Wpragmas \
158     -Wreorder \
159     -Wreturn-local-addr \
160     -Wreturn-type \
161     -Wsequence-point \
162     -Wshadow \
163     -Wshift-count-negative \
164     -Wshift-count-overflow \
165     -Wsign-promo \
166     -Wsized-deallocation \
167     -Wsizeof-array-argument \
168     -Wsizeof-pointer-memaccess \
169     -Wstack-protector \
170     -Wstrict-aliasing \
171     -Wstrict-null-sentinel \
172     -Wstrict-overflow \
173     -Wsuggest-attribute=const \
174     -Wsuggest-attribute=format \
175     -Wsuggest-attribute=noreturn \
176     -Wsuggest-attribute=pure \
177     -Wsuggest-final-methods \
178     -Wsuggest-final-types \
179     -Wsuggest-override \
180     -Wswitch \
181     -Wswitch-bool \
182     -Wsync-nand \
183     -Wsystem-headers \
184     -Wtrampolines \
185     -Wtrigraphs \
186     -Wtype-limits \
187     -Wuninitialized \
188     -Wunknown-pragmas \
189     -Wunsafe-loop-optimizations \
190     -Wunused \
191     -Wunused-but-set-parameter \
192     -Wunused-but-set-variable \
193     -Wunused-function \
194     -Wunused-label \
195     -Wunused-local-typedefs \
196     -Wunused-macros \
197     -Wunused-parameter \
198     -Wunused-result \
199     -Wunused-value \
200     -Wunused-variable \
201     -Wuseless-cast \
202     -Wvarargs \
203     -Wvariadic-macros \
204     -Wvector-operation-performance \
205     -Wvirtual-move-assign \
206     -Wvla \
207     -Wvolatile-register-var \
208     -Wwrite-strings \
209     -Wzero-as-null-pointer-constant \
210     \
211     ; do
212     gl_manywarn_set="$gl_manywarn_set $gl_manywarn_item"
213   done
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"
229           ;;
230     esac
231   fi
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"
236   fi
238   if test "$gl_cv_cxx_uninitialized_supported" = no; then
239     gl_manywarn_set="$gl_manywarn_set -Wno-uninitialized"
240   fi
242   $1=$gl_manywarn_set
244   AC_LANG_POP([C++])