Merge bitcoin/bitcoin#36087: util: Add and use AssertUnreachable
What changed, and why it matters
This is a code-cleanup change in Bitcoin Core. It replaces many uses of `assert(false)` and similar 'this should never happen' markers with a new macro called `AssertUnreachable()`. The goal is to make the code clearer for developers and avoid compiler warnings, not to fix a security bug that an attacker could exploit. The change does not alter what the program does when it reaches one of these unreachable points: it still aborts immediately.
No security action required. Treat as normal code-quality/maintenance refactor. Reviewers may verify that `AssertUnreachable()` is defined as noreturn and that no reachable code paths were accidentally converted.
Security signals we found
No security-relevant functional change: process still aborts on unreachable paths
Refactor only: replaces one abort mechanism with another equivalent one
Adds a new lint rule to enforce the preferred macro going forward
No input validation, memory safety, or consensus logic changes observed
Evidence from the diff
The merge commit adds AssertUnreachable() to src/util/check.h and mechanically replaces falsy assertions (assert(false), assert(0), std::abort(), abort(), and some Assert(false)) across ~84 files. The new macro calls the existing noreturn internal_abort_helper, preserving immediate process termination semantics. It also adds a linter (assert_falsy) to prevent regressions. A few unreachable return statements after the assertion are removed as dead code. There is no functional behavior change; this is a refactor to improve compiler diagnostics and code consistency.
Changed components
src/util/check.hsrc/wallet/scriptpubkeyman.cppsrc/wallet/wallet.cppsrc/validation.hsrc/netaddress.cppsrc/kernel/bitcoinkernel.cppsrc/qt/*.cppsrc/test/fuzz/*.cpptest/lint/test_runner/src/lint_cpp.rstest/lint/test_runner/src/main.rsInspect captured patch +274 / −264
### doc/developer-notes.md
@@ -923,14 +923,14 @@ int GetInt(Tabs tab)
case Tabs::info: return 0;
case Tabs::console: return 1;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}();
LogInfo("Tab %s", ret);
return ret;
}
```
-*Rationale*: The comment documents skipping `default:` label, and it complies with `clang-format` rules. The assertion prevents firing of `-Wreturn-type` warning on some compilers.
+*Rationale*: The comment documents skipping the `default:` case, and it complies with `clang-format` rules. `AssertUnreachable()` prevents `-Wreturn-type` warnings on some compilers.
## Strings and formatting
### src/addresstype.cpp
@@ -10,9 +10,9 @@
#include <script/script.h>
#include <script/solver.h>
#include <uint256.h>
+#include <util/check.h>
#include <util/hash_type.h>
-#include <cassert>
#include <vector>
typedef std::vector<unsigned char> valtype;
@@ -100,7 +100,7 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
addressRet = CNoDestination(scriptPubKey);
return false;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
namespace {
### src/addrman.cpp
@@ -1045,7 +1045,7 @@ void AddrManImpl::Check() const
const int err{CheckAddrman()};
if (err) {
LogError("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err);
- assert(false);
+ AssertUnreachable();
}
}
### src/bench/sign_transaction.cpp
@@ -49,7 +49,7 @@ static void SignTransactionSingleInput(benchmark::Bench& bench, InputType input_
case InputType::P2TR:
return GetScriptForDestination(WitnessV1Taproot(XOnlyPubKey{pubkey}));
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}();
prev_spks.push_back(prev_spk);
}
### src/bench/verify_script.cpp
@@ -39,7 +39,7 @@ static size_t ExpectedWitnessStackSize(ScriptType script_type)
case ScriptType::P2TR_KeyPath: return 1; // [signature]
case ScriptType::P2TR_ScriptPath: return 3; // [signature, tapscript, control block]
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
// Microbenchmark for verification of standard scripts.
@@ -71,7 +71,7 @@ static void VerifyScriptBench(benchmark::Bench& bench, ScriptType script_type)
keystore.tr_trees.emplace(output, builder);
return output;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}()};
const CMutableTransaction& txCredit = BuildCreditingTransaction(GetScriptForDestination(dest), 1);
CMutableTransaction txSpend = BuildSpendingTransaction(/*scriptSig=*/{}, /*scriptWitness=*/{}, CTransaction(txCredit));
### src/bitcoin-cli.cpp
@@ -25,6 +25,7 @@
#include <tinyformat.h>
#include <univalue.h>
#include <util/chaintype.h>
+#include <util/check.h>
#include <util/exception.h>
#include <util/sock.h>
#include <util/strencodings.h>
@@ -441,7 +442,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
case ChainType::MAIN:
return "";
}
- assert(false);
+ AssertUnreachable();
}
std::string PingTimeToString(double seconds) const
{
### src/bitcoin-util.cpp
@@ -17,6 +17,7 @@
#include <crypto/sha256.h>
#include <streams.h>
#include <univalue.h>
+#include <util/check.h>
#include <util/exception.h>
#include <util/strencodings.h>
#include <util/translation.h>
@@ -243,7 +244,7 @@ MAIN_FUNCTION
} else if (cmd->command == "getchainparams") {
ret = GetChainParams(cmd->args, strPrint);
} else {
- assert(false); // unknown command should be caught earlier
+ AssertUnreachable(); // unknown command should be caught earlier
}
} catch (const std::exception& e) {
strPrint = std::string("error: ") + e.what();
### src/chainparams.cpp
@@ -11,11 +11,11 @@
#include <deploymentinfo.h>
#include <tinyformat.h>
#include <util/chaintype.h>
+#include <util/check.h>
#include <util/log.h>
#include <util/strencodings.h>
#include <util/string.h>
-#include <cassert>
#include <cstdint>
#include <limits>
#include <stdexcept>
@@ -159,7 +159,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
return CChainParams::RegTest(opts);
}
}
- assert(false);
+ AssertUnreachable();
}
void SelectParams(const ChainType chain)
### src/chainparamsbase.cpp
@@ -10,9 +10,9 @@
#include <kernel/signet.h>
#include <tinyformat.h>
#include <util/chaintype.h>
+#include <util/check.h>
#include <util/strencodings.h>
-#include <cassert>
void SetupChainParamsBaseOptions(ArgsManager& argsman)
{
@@ -72,7 +72,7 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ArgsManager& args,
case ChainType::REGTEST:
return std::make_unique<CBaseChainParams>("regtest", 18443);
}
- assert(false);
+ AssertUnreachable();
}
void SelectBaseParams(const ChainType chain)
### src/common/messages.cpp
@@ -71,7 +71,7 @@ static std::string FeeModeInfo(const std::pair<std::string, FeeEstimateMode>& mo
case FeeEstimateMode::CONSERVATIVE:
return strprintf("%s potentially returns a higher fee rate estimate.\n", mode.first);
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::string FeeModesDetail(std::string default_info)
@@ -123,7 +123,7 @@ bilingual_str PSBTErrorString(PSBTError err)
case PSBTError::INVALID_TX:
return Untranslated("The transaction cannot be valid");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
bilingual_str TransactionErrorString(const TransactionError err)
@@ -150,7 +150,7 @@ bilingual_str TransactionErrorString(const TransactionError err)
case TransactionError::PRIVATE_BROADCAST_FULL:
return Untranslated("Private broadcast queue is full");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
bilingual_str ResolveErrMsg(const std::string& optname, const std::string& strBind)
### src/common/signmessage.cpp
@@ -91,5 +91,5 @@ std::string SigningResultString(const SigningResult res)
case SigningResult::SIGNING_FAILED:
return "Sign failed";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
### src/dbwrapper.h
@@ -293,7 +293,7 @@ class CDBWrapper
case ReadFailure::Code::DeserializationError: return false;
case ReadFailure::Code::DatabaseError: throw dbwrapper_error(err_msg);
} // no default case, so the compiler can warn about missing cases
- std::abort(); // unreachable
+ AssertUnreachable();
}
template <typename K, typename V>
### src/httpserver.cpp
@@ -124,7 +124,7 @@ std::string_view RequestMethodString(HTTPRequestMethod m)
case PUT: return "PUT";
case UNKNOWN: return "unknown";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
static void WriteNoStoreErrorReply(HTTPRequest& req, HTTPStatusCode status, std::string_view reply = {})
### src/index/blockfilterindex.cpp
@@ -68,7 +68,7 @@ std::string BlockFilterThreadName(BlockFilterType filter_type)
case BlockFilterType::BASIC: return "blkfltbscidx";
case BlockFilterType::INVALID: return "";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
struct DBVal {
### src/init.cpp
@@ -1265,7 +1265,7 @@ static bool LockDirectory(const fs::path& dir, bool probeOnly)
return InitError(strprintf(_("Cannot obtain a lock on directory %s. %s is probably already running."), fs::PathToString(dir), CLIENT_NAME));
case util::LockResult::Success: return true;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
static bool LockDirectories(bool probeOnly)
{
### src/kernel/bitcoinkernel.cpp
@@ -180,7 +180,7 @@ constexpr util::log::Level to_util(btck_LogLevel level)
return util::log::Level::Error;
}
}
- assert(false);
+ AssertUnreachable();
}
btck_SynchronizationState cast_state(SynchronizationState state)
@@ -193,7 +193,7 @@ btck_SynchronizationState cast_state(SynchronizationState state)
case SynchronizationState::POST_INIT:
return btck_SynchronizationState_POST_INIT;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
btck_Warning cast_btck_warning(kernel::Warning warning)
@@ -204,7 +204,7 @@ btck_Warning cast_btck_warning(kernel::Warning warning)
case kernel::Warning::LARGE_WORK_INVALID_CHAIN:
return btck_Warning_LARGE_WORK_INVALID_CHAIN;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
constexpr btck_LogLevel to_btck(util::log::Level level)
@@ -226,7 +226,7 @@ constexpr btck_LogLevel to_btck(util::log::Level level)
return btck_LogLevel_ERROR;
}
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
constexpr btck_StringView to_btck(std::string_view str)
@@ -1067,7 +1067,7 @@ btck_ChainParameters* btck_chain_parameters_create(const btck_ChainType chain_ty
return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::RegTest().release()));
}
}
- assert(false);
+ AssertUnreachable();
}
btck_ChainParameters* btck_chain_parameters_create_signet(const void* challenge, size_t challenge_len)
@@ -1215,7 +1215,7 @@ btck_BlockValidationResult btck_block_validation_state_get_block_validation_resu
case BlockValidationResult::BLOCK_HEADER_LOW_WORK:
return btck_BlockValidationResult_HEADER_LOW_WORK;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
btck_ChainstateManagerOptions* btck_chainstate_manager_options_create(const btck_Context* context, const char* data_dir, size_t data_dir_len, const char* blocks_dir, size_t blocks_dir_len)
@@ -1750,7 +1750,7 @@ btck_TxValidationResult btck_tx_validation_state_get_tx_validation_result(const
case TxValidationResult::TX_RECONSIDERABLE: return btck_TxValidationResult_RECONSIDERABLE;
case TxValidationResult::TX_UNKNOWN: return btck_TxValidationResult_UNKNOWN;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
void btck_tx_validation_state_destroy(btck_TxValidationState* state)
### src/kernel/coinstats.cpp
@@ -168,7 +168,7 @@ std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, const C
return ComputeUTXOStats(nullptr, view, blockman, interruption_point);
}
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}();
}
### src/kernel/mempool_removal_reason.cpp
@@ -4,7 +4,8 @@
#include <kernel/mempool_removal_reason.h>
-#include <cassert>
+#include <util/check.h>
+
#include <string>
std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
@@ -17,5 +18,5 @@ std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
case MemPoolRemovalReason::CONFLICT: return "conflict";
case MemPoolRemovalReason::REPLACED: return "replaced";
}
- assert(false);
+ AssertUnreachable();
}
### src/logging.cpp
@@ -255,7 +255,7 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level)
case BCLog::Level::Error:
return "error";
}
- assert(false);
+ AssertUnreachable();
}
static std::string LogCategoryToStr(BCLog::LogFlags category)
### src/memusage.h
@@ -9,20 +9,18 @@
#include <prevector.h>
#include <support/allocators/pool.h>
-#include <cassert>
#include <cstdlib>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <string>
-#include <vector>
#include <unordered_map>
#include <unordered_set>
+#include <vector>
-namespace memusage
-{
+namespace memusage {
/** Compute the total memory used by allocating alloc bytes. */
static size_t MallocUsage(size_t alloc);
@@ -54,12 +52,12 @@ static inline size_t MallocUsage(size_t alloc)
// Measured on libc6 2.19 on Linux.
if (alloc == 0) {
return 0;
- } else if (sizeof(void*) == 8) {
+ } else if constexpr (sizeof(void*) == 8) {
return ((alloc + 31) >> 4) << 4;
- } else if (sizeof(void*) == 4) {
+ } else if constexpr (sizeof(void*) == 4) {
return ((alloc + 15) >> 3) << 3;
} else {
- assert(0);
+ static_assert(sizeof(void*) == 4 || sizeof(void*) == 8);
}
}
### src/net.h
@@ -794,7 +794,7 @@ class CNode
return false;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
bool IsFullOutboundConn() const {
@@ -819,7 +819,7 @@ class CNode
return true;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
bool IsBlockOnlyConn() const {
@@ -863,7 +863,7 @@ class CNode
return true;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
/**
### src/net_processing.cpp
@@ -2505,7 +2505,7 @@ node::TransactionError PeerManagerImpl::InitiateTxBroadcastPrivate(const CTransa
LogDebug(BCLog::PRIVBROADCAST, "Rejecting private broadcast, queue full (cap=%u): %s", PrivateBroadcast::MAX_TRANSACTIONS, txstr);
return node::TransactionError::PRIVATE_BROADCAST_FULL;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
void PeerManagerImpl::RelayAddress(NodeId originator,
### src/netaddress.cpp
@@ -10,6 +10,7 @@
#include <hash.h>
#include <prevector.h>
#include <tinyformat.h>
+#include <util/check.h>
#include <util/strencodings.h>
#include <util/string.h>
@@ -40,10 +41,10 @@ CNetAddr::BIP155Network CNetAddr::GetBIP155Network() const
case NET_INTERNAL: // should have been handled before calling this function
case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
case NET_MAX: // m_net is never and should not be set to NET_MAX
- assert(false);
+ AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
bool CNetAddr::SetNetFromBIP155Network(uint8_t possible_bip155_net, size_t address_size)
@@ -128,7 +129,7 @@ void CNetAddr::SetIP(const CNetAddr& ipIn)
break;
case NET_UNROUTABLE:
case NET_MAX:
- assert(false);
+ AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
m_net = ipIn.m_net;
@@ -494,10 +495,10 @@ bool CNetAddr::IsAddrV1Compatible() const
return false;
case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
case NET_MAX: // m_net is never and should not be set to NET_MAX
- assert(false);
+ AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
enum Network CNetAddr::GetNetwork() const
@@ -601,10 +602,10 @@ std::string CNetAddr::ToStringAddr() const
return EncodeBase32(m_addr) + ".internal";
case NET_UNROUTABLE: // m_net is never and should not be set to NET_UNROUTABLE
case NET_MAX: // m_net is never and should not be set to NET_MAX
- assert(false);
+ AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
bool operator==(const CNetAddr& a, const CNetAddr& b)
@@ -675,7 +676,7 @@ uint32_t CNetAddr::GetLinkedIPv4() const
// Teredo tunneled IPv4: the IPv4 address is in the last 4 bytes of the address, but bitflipped
return ~ReadBE32(std::span{m_addr}.last(ADDR_IPV4_SIZE).data());
}
- assert(false);
+ AssertUnreachable();
}
Network CNetAddr::GetNetClass() const
### src/netaddress.h
@@ -11,6 +11,7 @@
#include <random.h>
#include <serialize.h>
#include <tinyformat.h>
+#include <util/check.h>
#include <util/strencodings.h>
#include <util/string.h>
@@ -349,7 +350,7 @@ class CNetAddr
break;
case NET_UNROUTABLE:
case NET_MAX:
- assert(false);
+ AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
// Serialize ONION, I2P and CJDNS as all-zeros.
### src/netbase.cpp
@@ -10,6 +10,7 @@
#include <compat/compat.h>
#include <sync.h>
#include <tinyformat.h>
+#include <util/check.h>
#include <util/log.h>
#include <util/sock.h>
#include <util/strencodings.h>
@@ -121,10 +122,10 @@ std::string GetNetworkName(enum Network net)
case NET_I2P: return "i2p";
case NET_CJDNS: return "cjdns";
case NET_INTERNAL: return "internal";
- case NET_MAX: assert(false);
+ case NET_MAX: AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::vector<std::string> GetNetworkNames(bool append_unroutable)
### src/node/connection_types.cpp
@@ -3,7 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <node/connection_types.h>
-#include <cassert>
+
+#include <util/check.h>
std::string ConnectionTypeAsString(ConnectionType conn_type)
{
@@ -24,7 +25,7 @@ std::string ConnectionTypeAsString(ConnectionType conn_type)
return "private-broadcast";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::string TransportTypeAsString(TransportProtocolType transport_type)
@@ -38,5 +39,5 @@ std::string TransportTypeAsString(TransportProtocolType transport_type)
return "v2";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
### src/outputtype.cpp
@@ -9,8 +9,8 @@
#include <script/script.h>
#include <script/sign.h>
#include <script/signingprovider.h>
+#include <util/check.h>
-#include <cassert>
#include <optional>
#include <string>
@@ -43,7 +43,7 @@ const std::string& FormatOutputType(OutputType type)
case OutputType::BECH32M: return OUTPUT_TYPE_STRING_BECH32M;
case OutputType::UNKNOWN: return OUTPUT_TYPE_STRING_UNKNOWN;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::string FormatAllOutputTypes()
@@ -74,7 +74,7 @@ CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, cons
case OutputType::BECH32M:
case OutputType::UNKNOWN: {} // This function should not be used for BECH32M or UNKNOWN, so let it assert
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::optional<OutputType> OutputTypeFromDestination(const CTxDestination& dest) {
### src/policy/feerate.cpp
@@ -3,9 +3,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <consensus/amount.h>
#include <policy/feerate.h>
+
+#include <consensus/amount.h>
#include <tinyformat.h>
+#include <util/check.h>
#include <cstdlib>
@@ -45,5 +47,5 @@ std::string CFeeRate::ToString(FeeRateFormat fee_rate_format) const
case FeeRateFormat::BTC_KVB: return format_feerate(feerate_per_kvb, COIN, /*decimals=*/8, CURRENCY_UNIT, "kvB");
case FeeRateFormat::SAT_VB: return format_feerate(feerate_per_kvb, 1000, /*decimals=*/3, CURRENCY_ATOM, "vB");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
### src/policy/fees/block_policy_estimator.cpp
@@ -16,14 +16,14 @@
#include <sync.h>
#include <tinyformat.h>
#include <uint256.h>
+#include <util/check.h>
#include <util/fs.h>
#include <util/log.h>
#include <util/serfloat.h>
#include <util/syserror.h>
#include <util/time.h>
#include <algorithm>
-#include <cassert>
#include <chrono>
#include <cmath>
#include <cstddef>
@@ -46,7 +46,7 @@ std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
case FeeEstimateHorizon::MED_HALFLIFE: return "medium";
case FeeEstimateHorizon::LONG_HALFLIFE: return "long";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::string StringForBlockPolicyEstimateReason(BlockPolicyEstimateReason reason)
@@ -63,7 +63,7 @@ std::string StringForBlockPolicyEstimateReason(BlockPolicyEstimateReason reason)
case BlockPolicyEstimateReason::CONSERVATIVE:
return "Conservative Double Target longer horizon";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
namespace {
@@ -777,7 +777,7 @@ unsigned int CBlockPolicyEstimator::HighestTargetTracked(FeeEstimateHorizon hori
return longStats->GetMaxConfirms();
}
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
unsigned int CBlockPolicyEstimator::BlockSpan() const
### src/policy/fees/estimator_man.cpp
@@ -8,6 +8,7 @@
#include <policy/feerate.h>
#include <policy/fees/block_policy_estimator.h>
#include <policy/fees/mempool_estimator.h>
+#include <util/check.h>
#include <util/fees.h>
FeeRateEstimatorManager::~FeeRateEstimatorManager() = default;
@@ -51,7 +52,7 @@ util::Expected<FeeRateEstimation, FeeRateEstimationError> FeeRateEstimatorManage
case FeeRateEstimatorType::MEMPOOL_POLICY:
return m_mempool_estimator->EstimateFeeRate(conservative);
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
void FeeRateEstimatorManager::IntervalFlush()
### src/protocol.cpp
@@ -6,6 +6,7 @@
#include <protocol.h>
#include <common/system.h>
+#include <util/check.h>
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* msg_type, unsigned int nMessageSizeIn)
: pchMessageStart{pchMessageStartIn}
@@ -92,7 +93,7 @@ static std::string serviceFlagToStr(size_t bit)
{
const uint64_t service_flag = 1ULL << bit;
switch ((ServiceFlags)service_flag) {
- case NODE_NONE: abort(); // impossible
+ case NODE_NONE: AssertUnreachable();
case NODE_NETWORK: return "NETWORK";
case NODE_BLOOM: return "BLOOM";
case NODE_WITNESS: return "WITNESS";
### src/psbt.cpp
@@ -856,7 +856,7 @@ std::string PSBTRoleName(PSBTRole role) {
case PSBTRole::FINALIZER: return "finalizer";
case PSBTRole::EXTRACTOR: return "extractor";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
util::Result<PartiallySignedTransaction> DecodeBase64PSBT(const std::string& base64_tx)
### src/qt/addresstablemodel.cpp
@@ -4,17 +4,17 @@
#include <qt/addresstablemodel.h>
+#include <key_io.h>
#include <qt/guiutil.h>
#include <qt/walletmodel.h>
-
-#include <key_io.h>
+#include <util/check.h>
#include <wallet/types.h>
#include <wallet/wallet.h>
-#include <algorithm>
-
-#include <QFont>
#include <QDebug>
+#include <QFont>
+
+#include <algorithm>
const QString AddressTableModel::Send = "S";
const QString AddressTableModel::Receive = "R";
@@ -61,7 +61,7 @@ constexpr AddressTableEntry::Type translateTransactionType(wallet::AddressPurpos
case wallet::AddressPurpose::RECEIVE: return AddressTableEntry::Receiving;
case wallet::AddressPurpose::REFUND: return AddressTableEntry::Hidden;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
// Private implementation
@@ -209,15 +209,15 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
case Address:
return rec->address;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
} else if (role == Qt::FontRole) {
switch (column) {
case Label:
return QFont();
case Address:
return GUIUtil::fixedPitchFont();
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
} else if (role == TypeRole) {
switch(rec->type)
{
@@ -228,7 +228,7 @@ QVariant AddressTableModel::data(const QModelIndex &index, int role) const
case AddressTableEntry::Hidden:
return {};
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
return QVariant();
}
### src/qt/bantablemodel.cpp
@@ -6,15 +6,16 @@
#include <interfaces/node.h>
#include <net_types.h>
-
-#include <utility>
+#include <util/check.h>
#include <QDateTime>
#include <QList>
#include <QLocale>
#include <QModelIndex>
#include <QVariant>
+#include <utility>
+
bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan& right) const
{
const CCombinedBan* pLeft = &left;
@@ -29,7 +30,7 @@ bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan
case BanTableModel::Bantime:
return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
// private implementation
@@ -124,7 +125,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
date = date.addSecs(rec->banEntry.nBanUntil);
return QLocale::system().toString(date, QLocale::LongFormat);
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
return QVariant();
### src/qt/bitcoin.cpp
@@ -31,6 +31,7 @@
#include <qt/winshutdownmonitor.h>
#include <uint256.h>
#include <util/btcsignals.h>
+#include <util/check.h>
#include <util/exception.h>
#include <util/log.h>
#include <util/string.h>
@@ -166,7 +167,7 @@ static bool ErrorSettingsRead(const bilingual_str& error, const std::vector<std:
case QMessageBox::Abort:
return true;
default:
- assert(false);
+ AssertUnreachable();
}
}
### src/qt/bitcoinunits.cpp
@@ -5,10 +5,10 @@
#include <qt/bitcoinunits.h>
#include <consensus/amount.h>
+#include <util/check.h>
#include <QStringList>
-#include <cassert>
static constexpr auto MAX_DIGITS_BTC = 16;
@@ -36,7 +36,7 @@ QString BitcoinUnits::longName(Unit unit)
case Unit::uBTC: return QString::fromUtf8("µBTC (bits)");
case Unit::SAT: return QString("Satoshi (sat)");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
QString BitcoinUnits::shortName(Unit unit)
@@ -47,7 +47,7 @@ QString BitcoinUnits::shortName(Unit unit)
case Unit::uBTC: return QString("bits");
case Unit::SAT: return QString("sat");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
QString BitcoinUnits::description(Unit unit)
@@ -58,7 +58,7 @@ QString BitcoinUnits::description(Unit unit)
case Unit::uBTC: return QString("Micro-Bitcoins (bits) (1 / 1" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
case Unit::SAT: return QString("Satoshi (sat) (1 / 100" THIN_SP_UTF8 "000" THIN_SP_UTF8 "000)");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
qint64 BitcoinUnits::factor(Unit unit)
@@ -69,7 +69,7 @@ qint64 BitcoinUnits::factor(Unit unit)
case Unit::uBTC: return 100;
case Unit::SAT: return 1;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
int BitcoinUnits::decimals(Unit unit)
@@ -80,7 +80,7 @@ int BitcoinUnits::decimals(Unit unit)
case Unit::uBTC: return 2;
case Unit::SAT: return 0;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
QString BitcoinUnits::format(Unit unit, const CAmount& nIn, bool fPlus, SeparatorStyle separators, bool justify)
@@ -237,7 +237,7 @@ qint8 ToQint8(BitcoinUnit unit)
case BitcoinUnit::uBTC: return 2;
case BitcoinUnit::SAT: return 3;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
BitcoinUnit FromQint8(qint8 num)
@@ -248,7 +248,7 @@ BitcoinUnit FromQint8(qint8 num)
case 2: return BitcoinUnit::uBTC;
case 3: return BitcoinUnit::SAT;
}
- assert(false);
+ AssertUnreachable();
}
} // namespace
### src/qt/guiutil.cpp
@@ -4,12 +4,6 @@
#include <qt/guiutil.h>
-#include <qt/bitcoinaddressvalidator.h>
-#include <qt/bitcoinunits.h>
-#include <qt/platformstyle.h>
-#include <qt/qvalidatedlineedit.h>
-#include <qt/sendcoinsrecipient.h>
-
#include <addresstype.h>
#include <base58.h>
#include <chainparams.h>
@@ -21,8 +15,14 @@
#include <policy/policy.h>
#include <primitives/transaction.h>
#include <protocol.h>
+#include <qt/bitcoinaddressvalidator.h>
+#include <qt/bitcoinunits.h>
+#include <qt/platformstyle.h>
+#include <qt/qvalidatedlineedit.h>
+#include <qt/sendcoinsrecipient.h>
#include <script/script.h>
#include <util/chaintype.h>
+#include <util/check.h>
#include <util/exception.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
@@ -70,7 +70,6 @@
#include <QUrlQuery>
#include <QtGlobal>
-#include <cassert>
#include <chrono>
#include <exception>
#include <fstream>
@@ -695,9 +694,9 @@ QString NetworkToQString(Network net)
//: Name of CJDNS network in peer info
case NET_CJDNS: return QObject::tr("CJDNS", "network name");
case NET_INTERNAL: return "Internal"; // should never actually happen
- case NET_MAX: assert(false);
+ case NET_MAX: AssertUnreachable();
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction)
@@ -728,7 +727,7 @@ QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction
//: Short-lived peer connection type that is used for broadcasting privacy-sensitive data.
case ConnectionType::PRIVATE_BROADCAST: return prefix + QObject::tr("Private Broadcast");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
QString formatDurationStr(std::chrono::nanoseconds dur)
### src/qt/peertablemodel.cpp
@@ -4,16 +4,16 @@
#include <qt/peertablemodel.h>
+#include <interfaces/node.h>
#include <qt/guiconstants.h>
#include <qt/guiutil.h>
-
-#include <interfaces/node.h>
-
-#include <utility>
+#include <util/check.h>
#include <QList>
#include <QTimer>
+#include <utility>
+
PeerTableModel::PeerTableModel(interfaces::Node& node, QObject* parent)
: QAbstractTableModel(parent),
m_node(node)
@@ -90,7 +90,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
case Subversion:
return QString::fromStdString(rec->nodeStats.cleanSubVer);
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
} else if (role == Qt::TextAlignmentRole) {
switch (column) {
case NetNodeId:
@@ -109,7 +109,7 @@ QVariant PeerTableModel::data(const QModelIndex& index, int role) const
case Subversion:
return {};
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
} else if (role == StatsRole) {
return QVariant::fromValue(rec);
}
### src/qt/peertablesortproxy.cpp
@@ -43,5 +43,5 @@ bool PeerTableSortProxy::lessThan(const QModelIndex& left_index, const QModelInd
case PeerTableModel::Subversion:
return left_stats.cleanSubVer.compare(right_stats.cleanSubVer) < 0;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
### src/qt/receivecoinsdialog.cpp
@@ -2,18 +2,18 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <wallet/wallet.h>
-
#include <qt/receivecoinsdialog.h>
-#include <qt/forms/ui_receivecoinsdialog.h>
#include <qt/addresstablemodel.h>
+#include <qt/forms/ui_receivecoinsdialog.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/platformstyle.h>
#include <qt/receiverequestdialog.h>
#include <qt/recentrequeststablemodel.h>
#include <qt/walletmodel.h>
+#include <util/check.h>
+#include <wallet/wallet.h>
#include <QAction>
#include <QCursor>
@@ -184,7 +184,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
case AddressTableModel::EditStatus::INVALID_ADDRESS:
case AddressTableModel::EditStatus::DUPLICATE_ADDRESS:
case AddressTableModel::EditStatus::NO_CHANGES:
- assert(false);
+ AssertUnreachable();
}
clear();
}
### src/qt/rpcconsole.cpp
@@ -5,17 +5,18 @@
#include <bitcoin-build-config.h>
#include <qt/rpcconsole.h>
-#include <qt/forms/ui_debugwindow.h>
#include <chainparams.h>
#include <common/system.h>
#include <interfaces/node.h>
#include <node/connection_types.h>
#include <qt/bantablemodel.h>
#include <qt/clientmodel.h>
+#include <qt/forms/ui_debugwindow.h>
#include <qt/guiutil.h>
#include <qt/peertablesortproxy.h>
#include <qt/platformstyle.h>
+#include <util/check.h>
#ifdef ENABLE_WALLET
#include <qt/walletmodel.h>
#endif // ENABLE_WALLET
@@ -1365,7 +1366,7 @@ QKeySequence RPCConsole::tabShortcut(TabTypes tab_type) const
case TabTypes::PEERS: return QKeySequence(tr("Ctrl+P"));
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
void RPCConsole::updateAlerts(const QString& warnings)
### src/qt/sendcoinsdialog.cpp
@@ -5,40 +5,40 @@
#include <bitcoin-build-config.h>
#include <qt/sendcoinsdialog.h>
-#include <qt/forms/ui_sendcoinsdialog.h>
+#include <chainparams.h>
+#include <interfaces/node.h>
+#include <key_io.h>
+#include <node/interface_ui.h>
+#include <node/types.h>
#include <qt/addresstablemodel.h>
#include <qt/bitcoinunits.h>
#include <qt/clientmodel.h>
#include <qt/coincontroldialog.h>
+#include <qt/forms/ui_sendcoinsdialog.h>
#include <qt/guiutil.h>
#include <qt/optionsmodel.h>
#include <qt/platformstyle.h>
#include <qt/sendcoinsentry.h>
-
-#include <chainparams.h>
-#include <interfaces/node.h>
-#include <key_io.h>
-#include <node/interface_ui.h>
-#include <node/types.h>
#include <txmempool.h>
+#include <util/check.h>
#include <validation.h>
#include <wallet/coincontrol.h>
#include <wallet/fees.h>
#include <wallet/types.h>
#include <wallet/wallet.h>
+#include <QFontMetrics>
+#include <QScrollBar>
+#include <QSettings>
+#include <QTextDocument>
+
#include <array>
#include <chrono>
#include <fstream>
#include <memory>
#include <optional>
-#include <QFontMetrics>
-#include <QScrollBar>
-#include <QSettings>
-#include <QTextDocument>
-
using common::PSBTError;
using wallet::CCoinControl;
@@ -426,7 +426,7 @@ void SendCoinsDialog::presentPSBT(PartiallySignedTransaction& psbtx)
case QMessageBox::Discard:
break;
default:
- assert(false);
+ AssertUnreachable();
} // msgBox.exec()
}
### src/qt/transactiontablemodel.cpp
@@ -4,6 +4,8 @@
#include <qt/transactiontablemodel.h>
+#include <core_io.h>
+#include <interfaces/handler.h>
#include <qt/addresstablemodel.h>
#include <qt/bitcoinunits.h>
#include <qt/clientmodel.h>
@@ -14,14 +16,9 @@
#include <qt/transactiondesc.h>
#include <qt/transactionrecord.h>
#include <qt/walletmodel.h>
-
-#include <core_io.h>
-#include <interfaces/handler.h>
#include <tinyformat.h>
#include <uint256.h>
-
-#include <algorithm>
-#include <functional>
+#include <util/check.h>
#include <QColor>
#include <QDateTime>
@@ -31,6 +28,9 @@
#include <QLatin1String>
#include <QList>
+#include <algorithm>
+#include <functional>
+
// Amount column is right-aligned it contains numbers
static int column_alignments[] = {
@@ -478,7 +478,7 @@ QVariant TransactionTableModel::txStatusDecoration(const TransactionRecord *wtx)
case TransactionStatus::NotAccepted:
return QIcon(":/icons/transaction_0");
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
QString TransactionTableModel::formatTooltip(const TransactionRecord *rec) const
@@ -510,7 +510,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
return txAddressDecoration(rec);
case Amount: return {};
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
case Qt::DecorationRole:
{
QIcon icon = qvariant_cast<QIcon>(index.data(RawDecorationRole));
@@ -528,7 +528,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
case Amount:
return formatTxAmount(rec, true, BitcoinUnits::SeparatorStyle::ALWAYS);
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
case Qt::EditRole:
// Edit role is used for sorting, so return the unformatted values
switch (column) {
@@ -543,7 +543,7 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
case Amount:
return qint64(rec->credit + rec->debit);
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
case Qt::ToolTipRole:
return formatTooltip(rec);
case Qt::TextAlignmentRole:
### src/rest.cpp
@@ -468,7 +468,7 @@ static bool rest_block(const std::any& context,
assert(block_part);
return RESTERR(req, HTTP_BAD_REQUEST, strprintf("Bad block part offset/size %d/%d for %s", block_part->first, block_part->second, hashStr));
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
switch (rf) {
### src/script/descriptor.cpp
@@ -2332,7 +2332,7 @@ struct KeyParser {
case miniscript::MiniscriptContext::P2WSH: return ParseScriptContext::P2WSH;
case miniscript::MiniscriptContext::TAPSCRIPT: return ParseScriptContext::P2TR;
}
- assert(false);
+ AssertUnreachable();
}
std::optional<Key> FromString(std::span<const char>& in) const
### src/script/miniscript.cpp
@@ -258,7 +258,7 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
acc_tl; // timelock info
}
}
- assert(false);
+ AssertUnreachable();
}
size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_t k, size_t n_subs,
@@ -292,7 +292,7 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_
case Fragment::WRAP_J: return subsize + 4;
case Fragment::THRESH: return subsize + n_subs + BuildScript(k).size();
}
- assert(false);
+ AssertUnreachable();
}
InputStack& InputStack::SetAvailable(Availability avail) {
### src/script/miniscript.h
@@ -262,7 +262,7 @@ constexpr bool IsTapscript(MiniscriptContext ms_ctx)
case MiniscriptContext::P2WSH: return false;
case MiniscriptContext::TAPSCRIPT: return true;
}
- assert(false);
+ AssertUnreachable();
}
namespace internal {
@@ -868,7 +868,7 @@ class Node
return BuildScript(std::move(script), node.k, verify ? OP_EQUALVERIFY : OP_EQUAL);
}
}
- assert(false);
+ AssertUnreachable();
};
return TreeEval<CScript>(false, downfn, upfn);
}
@@ -994,7 +994,7 @@ class Node
}
default: break;
}
- assert(false);
+ AssertUnreachable();
};
return TreeEvalMaybe<std::string>(false, downfn, upfn);
@@ -1072,7 +1072,7 @@ class Node
return {count, sats[k], sats[0]};
}
}
- assert(false);
+ AssertUnreachable();
}
internal::StackSize CalcStackSize() const {
@@ -1187,7 +1187,7 @@ class Node
};
}
}
- assert(false);
+ AssertUnreachable();
}
internal::WitnessSize CalcWitnessSize() const {
@@ -1240,7 +1240,7 @@ class Node
return {sats[k], sats[0]};
}
}
- assert(false);
+ AssertUnreachable();
}
template<typename Ctx>
@@ -1441,8 +1441,7 @@ class Node
case Fragment::JUST_0: return {EMPTY, INVALID};
case Fragment::JUST_1: return {INVALID, EMPTY};
}
- assert(false);
- return {INVALID, INVALID};
+ AssertUnreachable();
};
auto tester = [&helper](const Node& node, std::span<InputResult> subres) -> InputResult {
### src/script/sign.cpp
@@ -727,7 +727,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
case TxoutType::ANCHOR:
return true;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
static CScript PushAll(const std::vector<valtype>& values)
### src/script/solver.cpp
@@ -9,8 +9,8 @@
#include <pubkey.h>
#include <script/interpreter.h>
#include <script/script.h>
+#include <util/check.h>
-#include <cassert>
#include <string>
typedef std::vector<unsigned char> valtype;
@@ -30,7 +30,7 @@ std::string GetTxnOutputType(TxoutType t)
case TxoutType::WITNESS_V1_TAPROOT: return "witness_v1_taproot";
case TxoutType::WITNESS_UNKNOWN: return "witness_unknown";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
static bool MatchPayToPubkey(const CScript& script, valtype& pubkey)
### src/test/fuzz/cluster_linearize.cpp
@@ -421,8 +421,7 @@ FUZZ_TARGET(clusterlin_depgraph_sim)
if (offset == 0) return i;
--offset;
}
- assert(false);
- return DepGraphIndex(-1);
+ AssertUnreachable();
};
/** Read a valid subset of the transactions from the provider. */
### src/test/fuzz/http_request.cpp
@@ -83,7 +83,7 @@ int StateRank(HTTPRequest::State s)
case HTTPRequest::State::Complete: return 3;
case HTTPRequest::State::Error: return 4;
}
- assert(false);
+ AssertUnreachable();
}
struct ParsedRequest {
### src/test/fuzz/miniscript.cpp
@@ -836,7 +836,7 @@ std::optional<NodeInfo> ConsumeNodeSmart(MsCtx script_ctx, FuzzedDataProvider& p
}
}
- assert(false);
+ AssertUnreachable();
}
/**
@@ -1182,9 +1182,8 @@ void TestNode(const MsCtx script_ctx, const std::optional<Node>& node, FuzzedDat
case Fragment::HASH160:
return TEST_DATA.hash160_preimages.contains(node.Data());
default:
- assert(false);
+ AssertUnreachable();
}
- return false;
});
assert(mal_success == satisfiable);
}
### src/test/fuzz/threadpool.cpp
@@ -35,7 +35,7 @@ static void GetFuture(std::future<void>& future, uint32_t& fail_counter)
} catch (const ExpectedException&) {
fail_counter++;
} catch (...) {
- assert(false && "Unexpected exception type");
+ AssertUnreachable(); // Unexpected exception type
}
}
### src/test/fuzz/tx_pool.cpp
@@ -288,16 +288,10 @@ void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, b
break;
}
case MempoolAcceptResult::ResultType::MEMPOOL_ENTRY:
- {
- // ATMP never sets this; only set in package settings
- Assert(false);
- break;
- }
case MempoolAcceptResult::ResultType::DIFFERENT_WITNESS:
{
- // ATMP never sets this; only set in package settings
- Assert(false);
- break;
+ // Only set in package settings, never by ATMP
+ AssertUnreachable();
}
}
}
### src/test/fuzz/txgraph.cpp
@@ -391,7 +391,7 @@ FUZZ_TARGET(txgraph)
if (choice == 0) return sim.GetRef(i);
--choice;
}
- assert(false);
+ AssertUnreachable();
} else {
choice -= tx_count[level];
}
### src/test/fuzz/txrequest.cpp
@@ -384,7 +384,7 @@ FUZZ_TARGET(txrequest)
tester.ReceivedResponse(peer, txidnum % MAX_TXHASHES);
break;
default:
- assert(false);
+ AssertUnreachable();
}
}
tester.Check();
### src/test/fuzz/util/net.cpp
@@ -130,8 +130,7 @@ FuzzedSock::~FuzzedSock()
FuzzedSock& FuzzedSock::operator=(Sock&& other)
{
- assert(false && "Move of Sock into FuzzedSock not allowed.");
- return *this;
+ AssertUnreachable(); // Move of Sock into FuzzedSock not allowed.
}
ssize_t FuzzedSock::Send(const void* data, size_t len, int flags) const
### src/test/fuzz/util/wallet.h
@@ -98,7 +98,7 @@ struct FuzzedWallet {
for (size_t i = 0; i < OUTPUT_TYPES.size(); ++i) {
if (OUTPUT_TYPES.at(i) == type) return i;
}
- assert(false);
+ AssertUnreachable();
}
std::vector<DescriptorScriptPubKeyMan*> m_spkms;
### src/test/fuzz/versionbits.cpp
@@ -318,7 +318,7 @@ FUZZ_TARGET(versionbits, .init = initialize)
}
return;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}();
if (blocks.size() >= period * max_periods) {
### src/test/httpserver_tests.cpp
@@ -8,11 +8,13 @@
#include <test/util/logging.h>
#include <test/util/net.h>
#include <test/util/setup_common.h>
+#include <util/check.h>
#include <util/overflow.h>
#include <util/string.h>
#include <util/threadpool.h>
#include <boost/test/unit_test.hpp>
+
#include <memory>
using util::LineReader;
@@ -782,8 +784,7 @@ BOOST_AUTO_TEST_CASE(http_should_disconnect_tests)
}
private:
SlowSocket& operator=(Sock&&) override {
- assert(false && "Move of Sock into SlowSocket not allowed.");
- return *this;
+ AssertUnreachable(); // Move of Sock into SlowSocket not allowed.
}
};
@@ -1031,7 +1032,7 @@ BOOST_AUTO_TEST_CASE(http_socket_error_tests)
{
public:
explicit ErrorSock(std::shared_ptr<Pipes> pipes) : DynSock{std::move(pipes)} {}
- DynSock& operator=(Sock&&) override { assert(false); return *this; }
+ DynSock& operator=(Sock&&) override { AssertUnreachable(); }
ssize_t Send(const void* buf, size_t len, int flags) const override
{
### src/test/logging_tests.cpp
@@ -10,6 +10,7 @@
#include <test/util/logging.h>
#include <test/util/setup_common.h>
#include <tinyformat.h>
+#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/string.h>
@@ -440,7 +441,7 @@ void LogFromLocation(Location location, const std::string& message) {
LogInfo(util::log::NO_RATE_LIMIT, "%s\n", message);
return;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
/**
### src/test/pcp_tests.cpp
@@ -4,9 +4,10 @@
#include <common/pcp.h>
#include <netbase.h>
-#include <test/util/logging.h>
#include <test/util/common.h>
+#include <test/util/logging.h>
#include <test/util/setup_common.h>
+#include <util/check.h>
#include <util/time.h>
#include <boost/test/unit_test.hpp>
@@ -100,8 +101,7 @@ class PCPTestSock final : public Sock
PCPTestSock& operator=(Sock&& other) override
{
- assert(false && "Move of Sock into PCPTestSock not allowed.");
- return *this;
+ AssertUnreachable(); // Move of Sock into PCPTestSock not allowed.
}
ssize_t Send(const void* data, size_t len, int) const override {
### src/test/private_broadcast_tests.cpp
@@ -6,11 +6,13 @@
#include <private_broadcast.h>
#include <test/util/setup_common.h>
#include <test/util/time.h>
+#include <util/check.h>
#include <util/time.h>
+#include <boost/test/unit_test.hpp>
+
#include <algorithm>
#include <ostream>
-#include <boost/test/unit_test.hpp>
std::ostream& operator<<(std::ostream& os, PrivateBroadcast::AddResult r)
{
@@ -19,7 +21,7 @@ std::ostream& operator<<(std::ostream& os, PrivateBroadcast::AddResult r)
case PrivateBroadcast::AddResult::AlreadyPresent: return os << "AlreadyPresent";
case PrivateBroadcast::AddResult::QueueFull: return os << "QueueFull";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
BOOST_FIXTURE_TEST_SUITE(private_broadcast_tests, BasicTestingSetup)
### src/test/util/net.cpp
@@ -15,6 +15,7 @@
#include <serialize.h>
#include <span.h>
#include <sync.h>
+#include <util/check.h>
#include <chrono>
#include <optional>
@@ -236,8 +237,7 @@ bool ZeroSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events
ZeroSock& ZeroSock::operator=(Sock&& other)
{
- assert(false && "Move of Sock into ZeroSock not allowed.");
- return *this;
+ AssertUnreachable(); // Move of Sock into ZeroSock not allowed.
}
StaticContentsSock::StaticContentsSock(const std::string& contents)
@@ -257,8 +257,7 @@ ssize_t StaticContentsSock::Recv(void* buf, size_t len, int flags) const
StaticContentsSock& StaticContentsSock::operator=(Sock&& other)
{
- assert(false && "Move of Sock into StaticContentsSock not allowed.");
- return *this;
+ AssertUnreachable(); // Move of Sock into StaticContentsSock not allowed.
}
ssize_t DynSock::Pipe::GetBytes(void* buf, size_t len, int flags)
@@ -378,6 +377,5 @@ bool DynSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_
DynSock& DynSock::operator=(Sock&&)
{
- assert(false && "Move of Sock into DynSock not allowed.");
- return *this;
+ AssertUnreachable(); // Move of Sock into DynSock not allowed.
}
### src/test/util_check_tests.cpp
@@ -9,13 +9,6 @@
BOOST_AUTO_TEST_SUITE(util_check_tests)
-namespace {
-void TriggerNonFatalUnreachable()
-{
- NONFATAL_UNREACHABLE();
-}
-} // namespace
-
BOOST_AUTO_TEST_CASE(check_pass)
{
Assume(true);
@@ -36,14 +29,8 @@ BOOST_AUTO_TEST_CASE(check_fail)
BOOST_CHECK_EXCEPTION(CHECK_NONFATAL(false), NonFatalCheckError, HasReason{"Internal bug detected: `false` check failed"});
void* this_should_be_nonnull{nullptr};
BOOST_CHECK_EXCEPTION(Assert(this_should_be_nonnull != nullptr), NonFatalCheckError, HasReason{"Internal bug detected: `this_should_be_nonnull != nullptr` check failed"});
-}
-
-BOOST_AUTO_TEST_CASE(unreachable_diagnostics)
-{
- // Disable aborts for easier testing here
- test_only_CheckFailuresAreExceptionsNotAborts mock_checks{};
-
- BOOST_CHECK_EXCEPTION(TriggerNonFatalUnreachable(), NonFatalCheckError, HasReason{"Internal bug detected: unreachable"});
+ BOOST_CHECK_EXCEPTION(AssertUnreachable(), NonFatalCheckError, HasReason{"Internal bug detected: unreachable"});
+ BOOST_CHECK_EXCEPTION(NONFATAL_UNREACHABLE(), NonFatalCheckError, HasReason{"Internal bug detected: unreachable"});
}
BOOST_AUTO_TEST_SUITE_END()
### src/test/util_tests.cpp
@@ -15,9 +15,8 @@
#include <test/util/setup_common.h>
#include <test/util/time.h>
#include <uint256.h>
-#include <univalue.h>
-#include <util/bitdeque.h>
#include <util/byte_units.h>
+#include <util/check.h>
#include <util/fs.h>
#include <util/fs_helpers.h>
#include <util/moneystr.h>
@@ -32,7 +31,6 @@
#include <array>
#include <cmath>
#include <cstdint>
-#include <cstring>
#include <fstream>
#include <limits>
#include <map>
@@ -43,8 +41,6 @@
#include <utility>
#include <vector>
-#include <sys/types.h>
-
#ifndef WIN32
#include <sys/wait.h>
#endif
@@ -1031,7 +1027,7 @@ enum : char {
case util::LockResult::ErrorWrite: return ResErrorWrite;
case util::LockResult::ErrorLock: return ResErrorLock;
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}();
rv = write(fd, &ch, 1);
assert(rv == 1);
@@ -1046,7 +1042,7 @@ enum : char {
close(fd);
exit(0);
default:
- assert(0);
+ AssertUnreachable();
}
}
}
### src/txdb.cpp
@@ -13,11 +13,11 @@
#include <serialize.h>
#include <uint256.h>
#include <util/byte_units.h>
+#include <util/check.h>
#include <util/log.h>
#include <util/threadnames.h>
#include <util/vector.h>
-#include <cassert>
#include <chrono>
#include <cstdlib>
#include <exception>
@@ -97,7 +97,7 @@ std::optional<Coin> CCoinsViewDB::GetCoin(const COutPoint& outpoint) const
case CDBWrapper::ReadFailure::Code::DatabaseError:
throw dbwrapper_error{strprintf("Coin DB read failure: %s", err_msg)};
} // no default case, so the compiler can warn about missing cases
- std::abort(); // unreachable
+ AssertUnreachable();
}
// Check whether the coin exists
### src/txgraph.cpp
@@ -713,8 +713,7 @@ class TxGraphImpl final : public TxGraph
if (tx_count >= GenericClusterImpl::MIN_INTENDED_TX_COUNT && tx_count <= GenericClusterImpl::MAX_TX_COUNT) {
return CreateEmptyGenericCluster();
}
- assert(false);
- return {};
+ AssertUnreachable();
}
// Functions for handling Refs.
@@ -1007,8 +1006,7 @@ int GenericClusterImpl::GetLevel(const TxGraphImpl& graph) const noexcept
}
// Given that we started with an Entry that occurs in this Cluster, one of its Locators must
// point back to it.
- assert(false);
- return -1;
+ AssertUnreachable();
}
int SingletonClusterImpl::GetLevel(const TxGraphImpl& graph) const noexcept
@@ -1024,8 +1022,7 @@ int SingletonClusterImpl::GetLevel(const TxGraphImpl& graph) const noexcept
}
// Given that we started with an Entry that occurs in this Cluster, one of its Locators must
// point back to it.
- assert(false);
- return -1;
+ AssertUnreachable();
}
void TxGraphImpl::ClearLocator(int level, GraphIndex idx, bool oversized_tx) noexcept
@@ -2199,8 +2196,7 @@ std::pair<uint64_t, bool> SingletonClusterImpl::Relinearize(TxGraphImpl& graph,
{
// All singletons are optimal, oversized, or need splitting. Each of these precludes
// Relinearize from being called.
- assert(false);
- return {0, false};
+ AssertUnreachable();
}
void TxGraphImpl::MakeAcceptable(Cluster& cluster, int level) noexcept
### src/util/asmap.cpp
@@ -226,8 +226,7 @@ uint32_t Interpret(const std::span<const std::byte> asmap, const std::span<const
}
// Reached EOF without RETURN, or aborted (see any of the breaks above)
// - should have been caught by SanityCheckAsmap below
- assert(false);
- return 0; // 0 is not a valid ASN
+ AssertUnreachable();
}
/**
### src/util/chaintype.cpp
@@ -23,7 +23,7 @@ std::string ChainTypeToString(ChainType chain)
case ChainType::REGTEST:
return "regtest";
}
- assert(false);
+ AssertUnreachable();
}
std::optional<ChainType> ChainTypeFromString(std::string_view chain)
### src/util/check.h
@@ -130,6 +130,9 @@ constexpr T&& inline_assertion_check(LIFETIMEBOUND T&& val, [[maybe_unused]] con
*/
#define Assume(val) inline_assertion_check<false>(val, std::source_location::current(), #val)
+/// Mark unreachable code. Aborts if called.
+#define AssertUnreachable() internal_abort_helper(std::source_location::current(), "unreachable")
+
/**
* NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code. It throws a NonFatalCheckError.
* Control flow will not continue past this macro.
### src/util/fees.cpp
@@ -4,9 +4,9 @@
#include <util/fees.h>
+#include <util/check.h>
#include <util/strencodings.h>
-#include <cassert>
#include <optional>
#include <string_view>
@@ -21,7 +21,7 @@ std::string_view FeeRateEstimatorTypeToString(FeeRateEstimatorType feerate_estim
return "mempool_policy";
}
// no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
std::optional<FeeRateEstimatorType> FeeRateEstimatorTypeFromString(std::string_view feerate_estimator_type)
### src/validation.cpp
@@ -2111,7 +2111,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
case CheckInputScriptsFor::Block:
return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("block-script-verify-flag-failed (%s)", ScriptErrorString(result->first)), result->second);
}
- assert(false); // unreachable
+ AssertUnreachable();
}
}
### src/validation.h
@@ -1140,7 +1140,7 @@ class ChainstateManager
for (auto& cs : m_chainstates) {
if (cs && cs->m_assumeutxo != Assumeutxo::INVALID && !cs->TargetBlockHash()) return *cs;
}
- abort();
+ AssertUnreachable();
}
//! Return historical chainstate targeting a specific block, if any.
@@ -1160,7 +1160,7 @@ class ChainstateManager
for (auto* cs : {&CurrentChainstate(), HistoricalChainstate()}) {
if (cs && cs->m_assumeutxo == Assumeutxo::VALIDATED) return *cs;
}
- abort();
+ AssertUnreachable();
}
//! Remove a chainstate.
### src/wallet/coinselection.cpp
@@ -1037,7 +1037,7 @@ std::string GetAlgorithmName(const SelectionAlgorithm algo)
case SelectionAlgorithm::CG: return "cg";
case SelectionAlgorithm::MANUAL: return "manual";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
CAmount SelectionResult::GetChange(const CAmount min_viable_change, const CAmount change_fee) const
### src/wallet/feebumper.h
@@ -6,8 +6,9 @@
#define BITCOIN_WALLET_FEEBUMPER_H
#include <consensus/consensus.h>
-#include <script/interpreter.h>
#include <primitives/transaction.h>
+#include <script/interpreter.h>
+#include <util/check.h>
class uint256;
enum class FeeEstimateMode;
@@ -92,7 +93,7 @@ struct SignatureWeights
break;
case SigVersion::TAPROOT:
case SigVersion::TAPSCRIPT:
- assert(false);
+ AssertUnreachable();
}
}
### src/wallet/scriptpubkeyman.cpp
@@ -210,7 +210,7 @@ bool LegacyDataSPKM::IsMine(const CScript& script) const
case IsMineResult::SPENDABLE:
return true;
}
- assert(false);
+ AssertUnreachable();
}
bool LegacyDataSPKM::CheckDecryptionKey(const CKeyingMaterial& master_key)
@@ -580,9 +580,7 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
// keyids is now all non-HD keys. Each key will have its own combo descriptor
for (const CKeyID& keyid : keyids) {
CKey key;
- if (!GetKey(keyid, key)) {
- assert(false);
- }
+ Assert(GetKey(keyid, key));
// Get birthdate from key meta
uint64_t creation_time = 0;
@@ -635,9 +633,7 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
// Get the master xprv
CKey seed_key;
- if (!GetKey(chain.seed_id, seed_key)) {
- assert(false);
- }
+ Assert(GetKey(chain.seed_id, seed_key));
CExtKey master_key;
master_key.SetSeed(seed_key);
@@ -680,9 +676,7 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
// Add the current master seed to the migration data
if (!m_hd_chain.seed_id.IsNull()) {
CKey seed_key;
- if (!GetKey(m_hd_chain.seed_id, seed_key)) {
- assert(false);
- }
+ Assert(GetKey(m_hd_chain.seed_id, seed_key));
out.master_key.SetSeed(seed_key);
}
@@ -717,9 +711,7 @@ std::optional<MigrationData> LegacyDataSPKM::MigrateToDescriptor()
// Get the private keys for this descriptor
std::vector<CScript> scripts;
FlatSigningProvider keys;
- if (!desc->Expand(0, DUMMY_SIGNING_PROVIDER, scripts, keys)) {
- assert(false);
- }
+ Assert(desc->Expand(0, DUMMY_SIGNING_PROVIDER, scripts, keys));
std::set<CKeyID> privkeyids;
for (const auto& key_orig_pair : keys.origins) {
privkeyids.insert(key_orig_pair.first);
### src/wallet/spend.cpp
@@ -1044,7 +1044,7 @@ void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast,
// May be MAX BIP125 to disable BIP68 and enable BIP125
if (in.nSequence == MAX_BIP125_RBF_SEQUENCE) continue;
// The wallet does not support any other sequence-use right now.
- assert(false);
+ AssertUnreachable();
}
}
### src/wallet/test/wallet_tests.cpp
@@ -632,10 +632,8 @@ static size_t CalculateNestedKeyhashInputSize(bool use_max_sig)
// Fill in dummy signatures for fee calculation.
SignatureData sig_data;
- if (!ProduceSignature(keystore, use_max_sig ? DUMMY_MAXIMUM_SIGNATURE_CREATOR : DUMMY_SIGNATURE_CREATOR, script_pubkey, sig_data)) {
- // We're hand-feeding it correct arguments; shouldn't happen
- assert(false);
- }
+ // We're hand-feeding it correct arguments, so signing should succeed
+ Assert(ProduceSignature(keystore, use_max_sig ? DUMMY_MAXIMUM_SIGNATURE_CREATOR : DUMMY_SIGNATURE_CREATOR, script_pubkey, sig_data));
CTxIn tx_in;
UpdateInput(tx_in, sig_data);
### src/wallet/wallet.cpp
@@ -3,10 +3,10 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <wallet/wallet.h>
-
#include <bitcoin-build-config.h>
+#include <wallet/wallet.h>
+
#include <addresstype.h>
#include <blockfilter.h>
#include <chain.h>
@@ -75,7 +75,6 @@
#include <wallet/walletutil.h>
#include <algorithm>
-#include <cassert>
#include <condition_variable>
#include <exception>
#include <limits>
@@ -1812,7 +1811,7 @@ void CWallet::InitWalletFlags(uint64_t flags)
throw std::runtime_error(std::string(__func__) + ": writing wallet flags failed");
}
- if (!LoadWalletFlags(flags)) assert(false);
+ Assert(LoadWalletFlags(flags));
}
uint64_t CWallet::GetWalletFlags() const
@@ -3831,7 +3830,7 @@ bool CWallet::MigrateToSQLite(bilingual_str& error)
batch->TxnAbort();
m_database->Close();
fs::remove(m_database->Filename());
- assert(false); // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
+ AssertUnreachable(); // This is a critical error, the new db could not be written to. The original db exists as a backup, but we should not continue execution.
}
}
bool committed = batch->TxnCommit();
### src/wallet/wallet.h
@@ -25,6 +25,7 @@
#include <tinyformat.h>
#include <uint256.h>
#include <util/btcsignals.h>
+#include <util/check.h>
#include <util/expected.h>
#include <util/fs.h>
#include <util/hasher.h>
@@ -41,7 +42,6 @@
#include <wallet/walletutil.h>
#include <atomic>
-#include <cassert>
#include <cstddef>
#include <cstdint>
#include <functional>
@@ -292,7 +292,7 @@ inline std::string PurposeToString(AddressPurpose p)
case AddressPurpose::SEND: return "send";
case AddressPurpose::REFUND: return "refund";
} // no default case, so the compiler can warn about missing cases
- assert(false);
+ AssertUnreachable();
}
inline std::optional<AddressPurpose> PurposeFromString(std::string_view s)
### src/wallet/walletutil.cpp
@@ -7,6 +7,7 @@
#include <chainparams.h>
#include <common/args.h>
#include <key_io.h>
+#include <util/check.h>
#include <util/log.h>
namespace wallet {
@@ -62,7 +63,7 @@ WalletDescriptor GenerateWalletDescriptor(const CExtPubKey& master_key, const Ou
case OutputType::UNKNOWN: {
// We should never have a DescriptorScriptPubKeyMan for an UNKNOWN OutputType,
// so if we get to this point something is wrong
- assert(false);
+ AssertUnreachable();
}
} // no default case, so the compiler can warn about missing cases
assert(!desc_prefix.empty());
### test/lint/test_runner/src/lint_cpp.rs
@@ -147,8 +147,8 @@ pub fn lint_rpc_assert() -> LintResult {
.args([
"grep",
"--line-number",
- "--extended-regexp",
- r"\<(A|a)ss(ume|ert)\(",
+ "--perl-regexp",
+ r"\b(Assume|[aA]ssert|AssertUnreachable)\(",
"--",
"src/rpc/",
"src/wallet/rpc*",
@@ -160,10 +160,40 @@ pub fn lint_rpc_assert() -> LintResult {
.success();
if found {
Err(r#"
-CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of assert for RPC code.
+CHECK_NONFATAL(...) or NONFATAL_UNREACHABLE() should be used instead of asserts or aborts in RPC
+code.
Aborting the whole process is undesirable for RPC code. So nonfatal
-checks should be used over assert. See: src/util/check.h
+checks should be used. See: src/util/check.h
+ "#
+ .trim()
+ .to_string())
+ } else {
+ Ok(())
+ }
+}
+
+pub fn lint_assert_falsy() -> LintResult {
+ let found = git()
+ .args([
+ "grep",
+ "--line-number",
+ "--perl-regexp",
+ r"\b[aA]ssert\s*\(\s*(0|false)\s*(&&|\))",
+ "--",
+ "src/",
+ // Temporary exclusions, which are not linking the util lib:
+ ":(exclude)src/script/interpreter.cpp",
+ ":(exclude)src/univalue/",
+ ":(exclude)src/tinyformat.h", // Avoid flagging ~dead code in temporary std::format port
+ ])
+ .args(get_pathspecs_default_excludes())
+ .status()
+ .expect("command error")
+ .success();
+ if found {
+ Err(r#"
+Assertions with a falsy literal value should be replaced with AssertUnreachable().
"#
.trim()
.to_string())
### test/lint/test_runner/src/main.rs
@@ -14,8 +14,8 @@ use std::fs;
use std::process::{Command, ExitCode};
use lint_cpp::{
- lint_boost_assert, lint_includes_build_config, lint_remove_all, lint_rpc_assert,
- lint_std_filesystem,
+ lint_assert_falsy, lint_boost_assert, lint_includes_build_config, lint_remove_all,
+ lint_rpc_assert, lint_std_filesystem,
};
use lint_docs::{lint_doc_args, lint_doc_release_note_snippets, lint_markdown};
use lint_py::{lint_py_lint, lint_rmtree};
@@ -73,6 +73,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
name: "rpc_assert",
lint_fn: lint_rpc_assert
},
+ &Linter {
+ description: "Check that assertions with falsy literal values are not used",
+ name: "assert_falsy",
+ lint_fn: lint_assert_falsy
+ },
&Linter {
description: "Check that boost assertions are not used",
name: "boost_assert",Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.