build: Optionally enable -Wzero-as-null-pointer-constant#15112
build: Optionally enable -Wzero-as-null-pointer-constant#15112Empact wants to merge 3 commits intobitcoin:masterfrom
Conversation
01a7e89 to
3bca8e9
Compare
|
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 :-) |
9724c7c to
6d509e7
Compare
|
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 |
6d509e7 to
873145a
Compare
|
Enabled now. 👍 |
|
utACK 873145a56315ba032aa100646d682ec31d39e8d9 |
873145a to
05ad601
Compare
|
As per conversation with @theuni, this now is only active if the user configures with The idea being to add a travis run that exercises the latter combination to deny the introduction of violations. |
05ad601 to
706ac51
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
706ac51 to
08d8902
Compare
|
Rebased for #13216 |
08d8902 to
48d05f3
Compare
|
Rebased for #15154 |
3a0e76f Replace remaining 0 with nullptr in Qt code (Ben Woosley) 9096276 Don't use zero as null pointer constant (-Wzero-as-null-pointer-constant) (practicalswift) Pull request description: This corrects all violations of `-Wzero-as-null-pointer-constant` identified in the Qt codebase. These changes are extracted from bitcoin#15112 as suggested by @MarcoFalke to ease review. This is in service of enabling `-Wzero-as-null-pointer-constant`, which should eliminate this as a concern going forward. Note there are 2 non-Qt changes: `src/test/allocator_tests.cpp` and `src/wallet/db.cpp`. Tree-SHA512: 206bd668802147ba42bc413c2d7d259cb59aca9ec1da74a6bf2ca3932e60ae492faacbc61bcee0fd6b4b49a4d59d075b7e5404f0526b36c47718f9b0587e7768
48d05f3 to
5bd3177
Compare
0d37ca7 to
7313fd0
Compare
7313fd0 to
7f0f2ca
Compare
|
cr ACK 7f0f2ca49f23cfd9e28892137e13f057a2152a91: patch looks correct |
src/tinyformat.h
Outdated
There was a problem hiding this comment.
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"
|
There was a problem hiding this comment.
Might be better to do with clang-tidy or so externally instead of maiming the source code?
There was a problem hiding this comment.
Might be better to do with clang-tidy
Have done this in #24971.
src/tinyformat.h
Outdated
There was a problem hiding this comment.
With gcc 9.3.0:
./tinyformat.h:1179: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas]
1179 | #pragma clang diagnostic pop
|
There was a problem hiding this comment.
I made the changes in 0b3c355 in an attempt to fix this - willing to test?
src/wallet/sqlite.cpp
Outdated
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
3a0e76f Replace remaining 0 with nullptr in Qt code (Ben Woosley) 9096276 Don't use zero as null pointer constant (-Wzero-as-null-pointer-constant) (practicalswift) Pull request description: This corrects all violations of `-Wzero-as-null-pointer-constant` identified in the Qt codebase. These changes are extracted from bitcoin#15112 as suggested by @MarcoFalke to ease review. This is in service of enabling `-Wzero-as-null-pointer-constant`, which should eliminate this as a concern going forward. Note there are 2 non-Qt changes: `src/test/allocator_tests.cpp` and `src/wallet/db.cpp`. Tree-SHA512: 206bd668802147ba42bc413c2d7d259cb59aca9ec1da74a6bf2ca3932e60ae492faacbc61bcee0fd6b4b49a4d59d075b7e5404f0526b36c47718f9b0587e7768
3a0e76f Replace remaining 0 with nullptr in Qt code (Ben Woosley) 9096276 Don't use zero as null pointer constant (-Wzero-as-null-pointer-constant) (practicalswift) Pull request description: This corrects all violations of `-Wzero-as-null-pointer-constant` identified in the Qt codebase. These changes are extracted from bitcoin#15112 as suggested by @MarcoFalke to ease review. This is in service of enabling `-Wzero-as-null-pointer-constant`, which should eliminate this as a concern going forward. Note there are 2 non-Qt changes: `src/test/allocator_tests.cpp` and `src/wallet/db.cpp`. Tree-SHA512: 206bd668802147ba42bc413c2d7d259cb59aca9ec1da74a6bf2ca3932e60ae492faacbc61bcee0fd6b4b49a4d59d075b7e5404f0526b36c47718f9b0587e7768
7f0f2ca to
fcd0a99
Compare
fcd0a99 to
1b06e99
Compare
…_warnings 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
|
Rebase for the move of |
As without this, GCC warns on the following unrecognized clang pragmas. bitcoin#15112 (comment)
|
Going to close this in favour of #24971; where we outsource this check to external tooling, and don't have to cover the codebase in pragmas to satisfy compilers. |
|
Sounds good, one of these days I'll familiarize myself with clang-tidy. |
Note: This is based on #14920This enables
-Wzero-as-null-pointer-constant, while avoiding applying it to dependencies.Used Qt::NoItemFlags, Qt::Widget instead where applicable.See #10483, #10645, #13802 for more on
nullptr.