Skip to content

Commit e68c266

Browse files
committed
Merge #9789: build: add --enable-werror and warn on vla's
205830a build: add --enable-werror option (Cory Fields) b602fe0 build: warn about variable length arrays (Cory Fields)
2 parents 1d2a57e + 205830a commit e68c266

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

configure.ac

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ AC_ARG_ENABLE([debug],
192192
[enable_debug=$enableval],
193193
[enable_debug=no])
194194

195+
# Turn warnings into errors
196+
AC_ARG_ENABLE([werror],
197+
[AS_HELP_STRING([--enable-werror],
198+
[Treat certain compiler warnings as errors (default is no)])],
199+
[enable_werror=$enableval],
200+
[enable_werror=no])
201+
195202
AC_LANG_PUSH([C++])
196203
AX_CHECK_COMPILE_FLAG([-Werror],[CXXFLAG_WERROR="-Werror"],[CXXFLAG_WERROR=""])
197204

@@ -206,10 +213,19 @@ if test "x$enable_debug" = xyes; then
206213
fi
207214
fi
208215

216+
ERROR_CXXFLAGS=
217+
if test "x$enable_werror" = "xyes"; then
218+
if test "x$CXXFLAG_WERROR" = "x"; then
219+
AC_MSG_ERROR("enable-werror set but -Werror is not usable")
220+
fi
221+
AX_CHECK_COMPILE_FLAG([-Werror=vla],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=vla"],,[[$CXXFLAG_WERROR]])
222+
fi
223+
209224
if test "x$CXXFLAGS_overridden" = "xno"; then
210225
AX_CHECK_COMPILE_FLAG([-Wall],[CXXFLAGS="$CXXFLAGS -Wall"],,[[$CXXFLAG_WERROR]])
211226
AX_CHECK_COMPILE_FLAG([-Wextra],[CXXFLAGS="$CXXFLAGS -Wextra"],,[[$CXXFLAG_WERROR]])
212227
AX_CHECK_COMPILE_FLAG([-Wformat],[CXXFLAGS="$CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
228+
AX_CHECK_COMPILE_FLAG([-Wvla],[CXXFLAGS="$CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
213229
AX_CHECK_COMPILE_FLAG([-Wformat-security],[CXXFLAGS="$CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
214230

215231
## Some compilers (gcc) ignore unknown -Wno-* options, but warn about all
@@ -1066,6 +1082,7 @@ AC_SUBST(BITCOIN_CLI_NAME)
10661082
AC_SUBST(BITCOIN_TX_NAME)
10671083

10681084
AC_SUBST(RELDFLAGS)
1085+
AC_SUBST(ERROR_CXXFLAGS)
10691086
AC_SUBST(HARDENED_CXXFLAGS)
10701087
AC_SUBST(HARDENED_CPPFLAGS)
10711088
AC_SUBST(HARDENED_LDFLAGS)
@@ -1155,6 +1172,7 @@ echo " with test = $use_tests"
11551172
echo " with bench = $use_bench"
11561173
echo " with upnp = $use_upnp"
11571174
echo " debug enabled = $enable_debug"
1175+
echo " werror = $enable_werror"
11581176
echo
11591177
echo " target os = $TARGET_OS"
11601178
echo " build os = $BUILD_OS"

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
DIST_SUBDIRS = secp256k1 univalue
66

77
AM_LDFLAGS = $(PTHREAD_CFLAGS) $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS)
8-
AM_CXXFLAGS = $(HARDENED_CXXFLAGS)
8+
AM_CXXFLAGS = $(HARDENED_CXXFLAGS) $(ERROR_CXXFLAGS)
99
AM_CPPFLAGS = $(HARDENED_CPPFLAGS)
1010
EXTRA_LIBRARIES =
1111

0 commit comments

Comments
 (0)