Page MenuHomePhabricator

util/check: stop using lambda for Assert/Assume
ClosedPublic

Authored by PiRK on Oct 10 2023, 15:52.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC709d378e241a: util/check: stop using lambda for Assert/Assume
Summary

wallet: move Assert() check into constructor

This puts it in a function body, so that func is available
for reporting any assertion failure.

util/check: stop using lambda for Assert/Assume

util/check: avoid unused parameter warnings

refactor: Add LIFETIMEBOUND / -Wdangling-gsl to Assert()

Rationale from PR description:

Using a lambda creates a couple of odd namespacing issues, in particular making clang's thread safety analysis less helpful, and confusing gcc when calling member functions. Fix this by not using a lambda.

This is a backport of core#24714, core#24729 and core#25248.

This is a requirement for core#25077 because a lambda cannot be used with LOCK.

Depends on D14620

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Oct 10 2023, 15:52

Tail of the build log:

   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
cc1plus: all warnings being treated as errors
[389/482] Building CXX object src/CMakeFiles/server.dir/rpc/blockchain.cpp.o
FAILED: src/CMakeFiles/server.dir/rpc/blockchain.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-reuse=none -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wredundant-decls -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wformat-security -Wredundant-move -Woverloaded-virtual -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/rpc/blockchain.cpp.o -MF src/CMakeFiles/server.dir/rpc/blockchain.cpp.o.d -o src/CMakeFiles/server.dir/rpc/blockchain.cpp.o -c ../../src/rpc/blockchain.cpp
In file included from ../../src/./validation.h:35,
                 from ../../src/./rpc/blockchain.h:10,
                 from ../../src/rpc/blockchain.cpp:6:
../../src/./util/check.h: In instantiation of ‘T&& inline_assertion_check(T&&, const char*, int, const char*, const char*) [with bool IS_ASSERT = false; T = bool]’:
../../src/./validation.h:271:9:   required from here
../../src/./util/check.h:65:49: error: parameter ‘file’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                     ~~~~~~~~~~~~^~~~
../../src/./util/check.h:65:59: error: parameter ‘line’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                                       ~~~~^~~~
../../src/./util/check.h:66:40: error: parameter ‘func’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                            ~~~~~~~~~~~~^~~~
../../src/./util/check.h:66:58: error: parameter ‘assertion’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
cc1plus: all warnings being treated as errors
[390/482] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
FAILED: src/CMakeFiles/server.dir/validation.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-reuse=none -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wredundant-decls -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wformat-security -Wredundant-move -Woverloaded-virtual -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/validation.cpp.o -MF src/CMakeFiles/server.dir/validation.cpp.o.d -o src/CMakeFiles/server.dir/validation.cpp.o -c ../../src/validation.cpp
In file included from ../../src/./validation.h:35,
                 from ../../src/validation.cpp:7:
../../src/./util/check.h: In instantiation of ‘T&& inline_assertion_check(T&&, const char*, int, const char*, const char*) [with bool IS_ASSERT = false; T = bool]’:
../../src/./validation.h:271:9:   required from here
../../src/./util/check.h:65:49: error: parameter ‘file’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                     ~~~~~~~~~~~~^~~~
../../src/./util/check.h:65:59: error: parameter ‘line’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                                       ~~~~^~~~
../../src/./util/check.h:66:40: error: parameter ‘func’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                            ~~~~~~~~~~~~^~~~
../../src/./util/check.h:66:58: error: parameter ‘assertion’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
../../src/./util/check.h: In instantiation of ‘T&& inline_assertion_check(T&&, const char*, int, const char*, const char*) [with bool IS_ASSERT = false; T = const bool&]’:
../../src/validation.cpp:766:9:   required from here
../../src/./util/check.h:65:49: error: parameter ‘file’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                     ~~~~~~~~~~~~^~~~
../../src/./util/check.h:65:59: error: parameter ‘line’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                                       ~~~~^~~~
../../src/./util/check.h:66:40: error: parameter ‘func’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                            ~~~~~~~~~~~~^~~~
../../src/./util/check.h:66:58: error: parameter ‘assertion’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
cc1plus: all warnings being treated as errors
ninja: build stopped: cannot make progress due to previous errors.
Build build-without-wallet failed with exit code 1

Tail of the build log:

-- Install component: "secp256k1"
-- Installing: /results/artifacts/lib/libsecp256k1.a
-- Installing: /results/artifacts/include/secp256k1.h
-- Installing: /results/artifacts/include/secp256k1_preallocated.h
-- Installing: /results/artifacts/include/secp256k1_recovery.h
-- Installing: /results/artifacts/include/secp256k1_schnorr.h
[366/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/blockindex.cpp.o
[367/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/logging.cpp.o
[368/542] Building CXX object src/CMakeFiles/server.dir/torcontrol.cpp.o
[369/542] Building CXX object src/CMakeFiles/server.dir/rpc/avalanche.cpp.o
[370/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/str.cpp.o
[371/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/transaction_utils.cpp.o
[372/542] Building CXX object src/CMakeFiles/server.dir/txorphanage.cpp.o
[373/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/wallet.cpp.o
[374/542] Building CXX object src/CMakeFiles/server.dir/validationinterface.cpp.o
[375/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/bdb.cpp.o
[376/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/coincontrol.cpp.o
[377/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/coinselection.cpp.o
[378/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/context.cpp.o
[379/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/crypter.cpp.o
[380/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/db.cpp.o
[381/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/fees.cpp.o
[382/542] Building CXX object src/CMakeFiles/server.dir/txmempool.cpp.o
[383/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/load.cpp.o
[384/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/receive.cpp.o
[385/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/blockfilter.cpp.o
[386/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/validation.cpp.o
[387/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/net.cpp.o
[388/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/mining.cpp.o
[389/542] Building CXX object src/CMakeFiles/server.dir/wallet/init.cpp.o
[390/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/salvage.cpp.o
[391/542] Building CXX object src/CMakeFiles/bitcoin-tx.dir/bitcoin-tx.cpp.o
[392/542] Building CXX object src/CMakeFiles/server.dir/rpc/rawtransaction.cpp.o
[393/542] Linking CXX executable src/bitcoin-tx
[394/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/sqlite.cpp.o
[395/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/transaction.cpp.o
[396/542] Building CXX object src/wallet/CMakeFiles/wallet-tool.dir/wallettool.cpp.o
[397/542] Building CXX object src/CMakeFiles/server.dir/net_processing.cpp.o
[398/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletutil.cpp.o
[399/542] Building CXX object src/CMakeFiles/server.dir/rpc/blockchain.cpp.o
[400/542] Building CXX object src/test/CMakeFiles/testutil.dir/util/setup_common.cpp.o
[401/542] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/dns.cpp.o
[402/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/signmessage.cpp.o
[403/542] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/options.cpp.o
[404/542] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/db.cpp.o
[405/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/util.cpp.o
[406/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/encrypt.cpp.o
[407/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/interfaces.cpp.o
[408/542] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
[409/542] Building CXX object src/seeder/CMakeFiles/seeder-base.dir/bitcoin.cpp.o
[410/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/spend.cpp.o
[411/542] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
[412/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/scriptpubkeyman.cpp.o
[413/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletdb.cpp.o
[414/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/backup.cpp.o
[415/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
[416/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcwallet.cpp.o
[417/542] Linking CXX static library src/wallet/libwallet.a
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1

Tail of the build log:

                 from ../../src/./seeder/messagewriter.h:9,
                 from ../../src/seeder/bitcoin.cpp:13:
../../src/./util/check.h: In instantiation of ‘T&& inline_assertion_check(T&&, const char*, int, const char*, const char*) [with bool IS_ASSERT = false; T = bool]’:
../../src/./validation.h:271:9:   required from here
../../src/./util/check.h:65:49: error: parameter ‘file’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                     ~~~~~~~~~~~~^~~~
../../src/./util/check.h:65:59: error: parameter ‘line’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                                       ~~~~^~~~
../../src/./util/check.h:66:40: error: parameter ‘func’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                            ~~~~~~~~~~~~^~~~
../../src/./util/check.h:66:58: error: parameter ‘assertion’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
cc1plus: all warnings being treated as errors
[410/542] Building CXX object src/seeder/CMakeFiles/bitcoin-seeder.dir/main.cpp.o
[411/542] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
FAILED: src/CMakeFiles/server.dir/validation.cpp.o 
/usr/bin/ccache /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-reuse=none -fstack-protector-all -Wstack-protector -fcf-protection=full -fstack-clash-protection -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wredundant-decls -Wsign-compare -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Wformat-security -Wredundant-move -Woverloaded-virtual -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-psabi -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/validation.cpp.o -MF src/CMakeFiles/server.dir/validation.cpp.o.d -o src/CMakeFiles/server.dir/validation.cpp.o -c ../../src/validation.cpp
In file included from ../../src/./validation.h:35,
                 from ../../src/validation.cpp:7:
../../src/./util/check.h: In instantiation of ‘T&& inline_assertion_check(T&&, const char*, int, const char*, const char*) [with bool IS_ASSERT = false; T = bool]’:
../../src/./validation.h:271:9:   required from here
../../src/./util/check.h:65:49: error: parameter ‘file’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                     ~~~~~~~~~~~~^~~~
../../src/./util/check.h:65:59: error: parameter ‘line’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                                       ~~~~^~~~
../../src/./util/check.h:66:40: error: parameter ‘func’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                            ~~~~~~~~~~~~^~~~
../../src/./util/check.h:66:58: error: parameter ‘assertion’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
../../src/./util/check.h: In instantiation of ‘T&& inline_assertion_check(T&&, const char*, int, const char*, const char*) [with bool IS_ASSERT = false; T = const bool&]’:
../../src/validation.cpp:766:9:   required from here
../../src/./util/check.h:65:49: error: parameter ‘file’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                     ~~~~~~~~~~~~^~~~
../../src/./util/check.h:65:59: error: parameter ‘line’ set but not used [-Werror=unused-but-set-parameter]
   65 | T &&inline_assertion_check(T &&val, const char *file, int line,
      |                                                       ~~~~^~~~
../../src/./util/check.h:66:40: error: parameter ‘func’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                            ~~~~~~~~~~~~^~~~
../../src/./util/check.h:66:58: error: parameter ‘assertion’ set but not used [-Werror=unused-but-set-parameter]
   66 |                            const char *func, const char *assertion) {
      |                                              ~~~~~~~~~~~~^~~~~~~~~
cc1plus: all warnings being treated as errors
[412/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/scriptpubkeyman.cpp.o
[413/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/walletdb.cpp.o
[414/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpc/backup.cpp.o
[415/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/wallet.cpp.o
[416/542] Building CXX object src/wallet/CMakeFiles/wallet.dir/rpcwallet.cpp.o
[417/542] Linking CXX static library src/wallet/libwallet.a
ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1
Fabien requested changes to this revision.Oct 10 2023, 16:21
Fabien added a subscriber: Fabien.

it's missing some maybe_unused

This revision now requires changes to proceed.Oct 10 2023, 16:21
PiRK edited the summary of this revision. (Show Details)
PiRK removed a reviewer: Fabien.

rebase on D14641, squash with core#25248 and core#24729

PiRK edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Oct 16 2023, 08:16