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 :-)
Concept ACK.
Could submit the src/qt changes as separate pull request, since those are the bulk of the changes?
@MarcoFalke Perhaps 10f81e916d5fbb2751d03d06901f68d9b507807c (including the two non QT fixes) can be posted as a separate PR since they are all trivial to review?
@Empact What about -Werror=zero-as-null-pointer-constant as discussed in #15114 (comment)?
Enabled now. 👍
utACK 873145a56315ba032aa100646d682ec31d39e8d9
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)
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
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.
@Empact Appveyor restarted.
utACK b4996079cda89711c2b8b80adbbb06a80f7b9c86
FWIW: I've verified that a disassembly of the 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):
/home/user/src/bitcoin/src/tinyformat.h:119:32: warning: unknown warning group '-Wzero-as-null-pointer-constant', ignored [-Wunknown-pragmas]
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
^
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
In file included from ./index/base.h:8:0,
from index/base.cpp:6:
./dbwrapper.h:16:10: fatal error: leveldb/db.h: No such file or directory
#include <leveldb/db.h>
Please update OP as it seems outdated.
@Empact Seems like the current version does not compile?
ACK fc19862337f0764104a918f22a97c47fb5dcc304
nullptr for 0. (Was unable to get a documentation warning by messing with a @param varname , though, for some reason...)I'll happily re-review and re-ACK after rebase -- hopefully we can get this in soon :)
Fails in leveldb (shouldn't it skip dependencies?):
./leveldb/db/skiplist.h:328:21: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
head_(NewNode(0 /* any key will do */, kMaxHeight)),
^
cc1plus: 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:
AX_CHECK_COMPILE_FLAG([-Werror=zero-as-null-pointer-constant], [
WARN_CXXFLAGS="$WARN_CXXFLAGS -Werror=zero-as-null-pointer-constant"
AC_DEFINE(HAVE_ZERO_AS_NULL_POINTER_CONSTANT, 1, [Define this symbol if -Wzero-as-null-pointer-constant is available])
], [], [$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:
AX_CHECK_COMPILE_FLAG([-Wzero-as-null-pointer-constant], [
WARN_CXXFLAGS="$WARN_CXXFLAGS -Wzero-as-null-pointer-constant"
AC_DEFINE(HAVE_ZERO_AS_NULL_POINTER_CONSTANT, 1, [Define this symbol if -Wzero-as-null-pointer-constant is available])
], [], [$CXXFLAG_WERROR])
Approach ACK 2036b7606f16a76a300f067824168de6536c60c8
I think the following patch could help:
--- a/src/Makefile.leveldb.include
+++ b/src/Makefile.leveldb.include
@@ -36,7 +36,7 @@ LEVELDB_CPPFLAGS_INT += -DLEVELDB_PLATFORM_POSIX
endif
leveldb_libleveldb_a_CPPFLAGS = $(AM_CPPFLAGS) $(LEVELDB_CPPFLAGS_INT) $(LEVELDB_CPPFLAGS)
-leveldb_libleveldb_a_CXXFLAGS = $(filter-out -Wconditional-uninitialized -Werror=conditional-uninitialized -Wsuggest-override -Werror=suggest-override, $(AM_CXXFLAGS)) $(PIE_FLAGS)
+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)
leveldb_libleveldb_a_SOURCES=
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
test/util_tests.cpp:1805:48: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
void (*old_handler)(int) = signal(SIGCHLD, SIG_DFL);
^
/usr/include/x86_64-linux-gnu/bits/signum-generic.h:29:37: note: expanded from macro 'SIG_DFL'
#define SIG_DFL ((__sighandler_t) 0) /* Default action. */
^
1 error generated.
cr ACK 7f0f2ca49f23cfd9e28892137e13f057a2152a91: patch looks correct
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:
./tinyformat.h:134: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
134 | #pragma clang diagnostic push
|
./tinyformat.h:135: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
135 | #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
|
Might be better to do with clang-tidy or so externally instead of maiming the source code?
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:
./tinyformat.h:1179: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
1179 | #pragma clang diagnostic pop
|
I made the changes in https://github.com/bitcoin/bitcoin/pull/15112/commits/0b3c3552f4ca7d0d151265adff35bdfceac5f380 in an attempt to fix this - willing to test?
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:
CXX wallet/libbitcoin_wallet_a-sqlite.o
wallet/sqlite.cpp:379:73: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
int res = sqlite3_bind_blob(m_read_stmt, 1, key.data(), key.size(), SQLITE_STATIC);
^
/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
^
wallet/sqlite.cpp:420:66: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
int res = sqlite3_bind_blob(stmt, 1, key.data(), key.size(), SQLITE_STATIC);
^
/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
^
wallet/sqlite.cpp:427:66: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
res = sqlite3_bind_blob(stmt, 2, value.data(), value.size(), SQLITE_STATIC);
^
/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
^
wallet/sqlite.cpp:451:75: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
int res = sqlite3_bind_blob(m_delete_stmt, 1, key.data(), key.size(), SQLITE_STATIC);
^
/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
^
wallet/sqlite.cpp:476:73: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
int res = sqlite3_bind_blob(m_read_stmt, 1, key.data(), key.size(), SQLITE_STATIC);
^
/usr/local/Cellar/sqlite/3.36.0/include/sqlite3.h:5666:54: note: expanded from macro 'SQLITE_STATIC'
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
^
5 errors generated.
make[2]: *** [wallet/libbitcoin_wallet_a-sqlite.o] Error 1
BTW:
% clang --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /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
Sounds good, one of these days I'll familiarize myself with clang-tidy.