Note: This is based on #14920
This enables -Wzero-as-null-pointer-constant
, while avoiding applying it to dependencies.
Used Qt::NoItemFlags, Qt::Widget instead where applicable.
Note: This is based on #14920
This enables -Wzero-as-null-pointer-constant
, while avoiding applying it to dependencies.
Used Qt::NoItemFlags, Qt::Widget instead where applicable.
Concept ACK and in accordance with our developer notes.
Thanks for doing this!
Using zero as null pointer constant is sloppy at best and dangerous at worst :-)
As per conversation with @theuni, this now is only active if the user configures with --enable-isystem
, so the build possibilities are:
default: disabled
--enable-isystem
: -Wzero-as-null-pointer-constant
--enable-isystem --enable-werror
: -Werror=zero-as-null-pointer-constant
The idea being to add a travis run that exercises the latter combination to deny the introduction of violations. #14920 (comment)
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
libbitcoinkernel
by dongcarl)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
bitcoind
binary built with this patch applied is identical to a disassembly of the bitcoind
binary built against master
(as expected).
I get tons of these warnings (almost on every file):
0/home/user/src/bitcoin/src/tinyformat.h:119:32: warning: unknown warning group '-Wzero-as-null-pointer-constant', ignored [-Wunknown-pragmas]
1#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
2 ^
This is with clang version 3.8.1-24 (tags/RELEASE_381/final)
(which is old as the hills but we apparently still support).
Failing in travis with
0In file included from ./index/base.h:8:0,
1 from index/base.cpp:6:
2./dbwrapper.h:16:10: fatal error: leveldb/db.h: No such file or directory
3 #include <leveldb/db.h>
Please update OP as it seems outdated.
ACK fc19862337f0764104a918f22a97c47fb5dcc304
nullptr
for 0
. (Was unable to get a documentation warning by messing with a @param
varname , though, for some reason…)Fails in leveldb (shouldn’t it skip dependencies?):
0./leveldb/db/skiplist.h:328:21: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
1 head_(NewNode(0 /* any key will do */, kMaxHeight)),
2 ^
3cc1plus: some warnings being treated as errors
441@@ -442,6 +442,10 @@ if test "x$enable_werror" = "xyes"; then
442
443 if test x$suppress_external_warnings != xno ; then
444 AX_CHECK_COMPILE_FLAG([-Werror=documentation],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=documentation"],,[[$CXXFLAG_WERROR]])
445+ AX_CHECK_COMPILE_FLAG([-Werror=zero-as-null-pointer-constant],[
446+ WARN_CXXFLAGS="$WARN_CXXFLAGS -Werror=zero-as-null-pointer-constant"
447+ AC_DEFINE(HAVE_ZERO_AS_NULL_POINTER_CONSTANT, 1, [Define this symbol if -Wzero-as-null-pointer-constant is available])
448+ ],,[[$CXXFLAG_WERROR]])
One pair of []
is redundant:
0 AX_CHECK_COMPILE_FLAG([-Werror=zero-as-null-pointer-constant], [
1 WARN_CXXFLAGS="$WARN_CXXFLAGS -Werror=zero-as-null-pointer-constant"
2 AC_DEFINE(HAVE_ZERO_AS_NULL_POINTER_CONSTANT, 1, [Define this symbol if -Wzero-as-null-pointer-constant is available])
3 ], [], [$CXXFLAG_WERROR])
I’m an autoconf novice - I take it we’re not concerned about macro conflicts with the CXXFLAG_WERROR as its contents are of a different form than uppercase macro definitions?
When you use the same text in a macro argument, you must therefore have an extra quotation level (since one is stripped away by the macro substitution). In general, then, it is a good idea to use double quoting for all literal string arguments, either around just the problematic portions, or over the entire argument:
AC_MSG_WARN([[AC_DC] stinks --Iron Maiden]) AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
475@@ -472,6 +476,10 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
476
477 if test x$suppress_external_warnings != xno ; then
478 AX_CHECK_COMPILE_FLAG([-Wdocumentation],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wdocumentation"],,[[$CXXFLAG_WERROR]])
479+ AX_CHECK_COMPILE_FLAG([-Wzero-as-null-pointer-constant],[
480+ WARN_CXXFLAGS="$WARN_CXXFLAGS -Wzero-as-null-pointer-constant"
481+ AC_DEFINE(HAVE_ZERO_AS_NULL_POINTER_CONSTANT, 1, [Define this symbol if -Wzero-as-null-pointer-constant is available])
482+ ],,[[$CXXFLAG_WERROR]])
One pair of []
is redundant:
0 AX_CHECK_COMPILE_FLAG([-Wzero-as-null-pointer-constant], [
1 WARN_CXXFLAGS="$WARN_CXXFLAGS -Wzero-as-null-pointer-constant"
2 AC_DEFINE(HAVE_ZERO_AS_NULL_POINTER_CONSTANT, 1, [Define this symbol if -Wzero-as-null-pointer-constant is available])
3 ], [], [$CXXFLAG_WERROR])
Approach ACK 2036b7606f16a76a300f067824168de6536c60c8
I think the following patch could help:
0--- a/src/Makefile.leveldb.include
1+++ b/src/Makefile.leveldb.include
2@@ -36,7 +36,7 @@ LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX
3 endif
4
5 leveldb_libleveldb_a_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS)
6-leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override, $(AM_CXXFLAGS)) $(PIE_FLAGS)
7+leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override -Wzero-as-null-pointer-constant -Werror=zero-as-null-pointer-constant, $(AM_CXXFLAGS)) $(PIE_FLAGS)
8
9 leveldb_libleveldb_a_SOURCES=
10 leveldb_libleveldb_a_SOURCES += leveldb/port/port_stdcxx.h
In the OP could drop “Used Qt::NoItemFlags, Qt::Widget instead where applicable.” ?
In commit “Don’t use zero as null pointer constant (-Wzero-as-null-pointer-constant)” (2036b7606f16a76a300f067824168de6536c60c8) could drop “Protobuf generated files via pragmas inserted via src/Makefile.am” ?
The name HAVE_ZERO_AS_NULL_POINTER_CONSTANT
seems confusing, as actually it means an activated warning, not a feature.
https://cirrus-ci.com/task/6169333320646656?logs=ci#L2845
0test/util_tests.cpp:1805:48: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
1 void (*old_handler)(int) = signal(SIGCHLD, SIG_DFL);
2 ^
3/usr/include/x86_64-linux-gnu/bits/signum-generic.h:29:37: note: expanded from macro 'SIG_DFL'
4#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
5 ^
61 error generated.
130+
131+#if defined(HAVE_W_ZERO_AS_NULL_POINTER_CONSTANT)
132+#pragma GCC diagnostic push
133+#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
134+#pragma clang diagnostic push
135+#pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
With gcc 9.3.0:
0./tinyformat.h:134: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
1 134 | #pragma clang diagnostic push
2 |
3./tinyformat.h:135: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
4 135 | #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
5 |
1173@@ -1163,4 +1174,9 @@ std::string format(const std::string &fmt, const Args&... args)
1174 /** Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for details) */
1175 #define strprintf tfm::format
1176
1177+#if defined(HAVE_W_ZERO_AS_NULL_POINTER_CONSTANT)
1178+#pragma GCC diagnostic pop
1179+#pragma clang diagnostic pop
With gcc 9.3.0:
0./tinyformat.h:1179: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
1 1179 | #pragma clang diagnostic pop
2 |
364@@ -365,6 +365,14 @@ void SQLiteBatch::Close()
365 }
366 }
367
368+// disable -Wzero-as-null-pointer-constant due to SQLITE_STATIC
If I remove changes in this file I won’t receive warning with both gcc 9.3.0 and clang 10.0.0. What cases are guarded here?
Having system sqlite 3.31.1.
Here’s the failure I get on removing that:
0 CXX wallet/libbitcoin_wallet_a-sqlite.o
1wallet/sqlite.cpp:379:73: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
2 int res = sqlite3_bind_blob(m_read_stmt, 1, key.data(), key.size(), SQLITE_STATIC);
3 ^
4/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
5#define SQLITE_STATIC ((sqlite3_destructor_type)0)
6 ^
7wallet/sqlite.cpp:420:66: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
8 int res = sqlite3_bind_blob(stmt, 1, key.data(), key.size(), SQLITE_STATIC);
9 ^
10/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
11#define SQLITE_STATIC ((sqlite3_destructor_type)0)
12 ^
13wallet/sqlite.cpp:427:66: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
14 res = sqlite3_bind_blob(stmt, 2, value.data(), value.size(), SQLITE_STATIC);
15 ^
16/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
17#define SQLITE_STATIC ((sqlite3_destructor_type)0)
18 ^
19wallet/sqlite.cpp:451:75: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
20 int res = sqlite3_bind_blob(m_delete_stmt, 1, key.data(), key.size(), SQLITE_STATIC);
21 ^
22/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
23#define SQLITE_STATIC ((sqlite3_destructor_type)0)
24 ^
25wallet/sqlite.cpp:476:73: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
26 int res = sqlite3_bind_blob(m_read_stmt, 1, key.data(), key.size(), SQLITE_STATIC);
27 ^
28/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
29#define SQLITE_STATIC ((sqlite3_destructor_type)0)
30 ^
315 errors generated.
32make[2]: *** [wallet/libbitcoin_wallet_a-sqlite.o] Error 1
BTW:
0% clang --version
1Apple clang version 12.0.5 (clang-1205.0.22.11)
2Target: x86_64-apple-darwin20.6.0
3Thread model: posix
4InstalledDir: /Library/Developer/CommandLineTools/usr/bin
And -Werror=zero-as-null-pointer-constant if werror are enabled.
While disabling it in the following dependencies:
* LevelDb via build flags
* Tinyformat via pragmas due to external library
* Sqlite via pragmas due to use of SQLITE_STATIC
* util_tests via pragmas due to use of SIG_DFL
As without this, GCC warns on the following unrecognized clang pragmas.
https://github.com/bitcoin/bitcoin/pull/15112#discussion_r623251609