Skip to content

Commit da223ce

Browse files
committed
Add configure option to warn on NULL/0 usage
This will help us migrate from checking for NULL to checking for NULLPTR. Enable this at configuration time with: ./configure --enable-null-warnings
1 parent 2b3c999 commit da223ce

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

configure.ac

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ AC_ARG_ENABLE([c++17],
6969
[use_cxx17=$enableval],
7070
[use_cxx17=no])
7171

72+
AC_ARG_ENABLE([null-warnings],
73+
[AS_HELP_STRING([--enable-null-warnings],
74+
[warn about using NULL instead of nullptr (default is no)])],
75+
[use_null_warnings=$enableval],
76+
[use_null_warnings=no])
77+
7278
dnl Require either of C++ 17, 14 or 11 (default) compiler (no GNU extensions)
7379
if test "x$use_cxx17" = xyes; then
7480
if test "x$use_cxx14" = xyes; then
@@ -290,6 +296,14 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
290296
AX_CHECK_COMPILE_FLAG([-Wunused-local-typedef],[CXXFLAGS="$CXXFLAGS -Wno-unused-local-typedef"],,[[$CXXFLAG_WERROR]])
291297
AX_CHECK_COMPILE_FLAG([-Wdeprecated-register],[CXXFLAGS="$CXXFLAGS -Wno-deprecated-register"],,[[$CXXFLAG_WERROR]])
292298
fi
299+
300+
if test "x$use_null_warnings" = "xyes"; then
301+
AX_CHECK_COMPILE_FLAG([-Wzero-as-null-pointer-constant],
302+
[CXXFLAGS="$CXXFLAGS -Wzero-as-null-pointer-constant"],
303+
[AC_MSG_WARN([Compiler doesn't support -Wzero-as-null-pointer-constant])],
304+
[[$CXXFLAG_WERROR]])
305+
fi
306+
293307
CPPFLAGS="$CPPFLAGS -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS"
294308

295309
AC_ARG_WITH([utils],
@@ -1295,6 +1309,7 @@ echo " with bench = $use_bench"
12951309
echo " with upnp = $use_upnp"
12961310
echo " debug enabled = $enable_debug"
12971311
echo " werror = $enable_werror"
1312+
echo " null warnings = $use_null_warnings"
12981313
echo
12991314
echo " experimental = $allow_experimental"
13001315
if test x$allow_experimental = xyes; then

0 commit comments

Comments
 (0)