util: Add and use AssertUnreachable #36087

Manually merged
maflcko merged 6 commits from 2608-unreachable into master 2026-11-20 21:13:29 +00:00 AGit
maflcko commented 2026-08-26 05:24:17 +00:00 (Migrated from github.com)

The current code uses assertions with falsy literal values in a few places. This is perfectly fine, but this comes with a bit of confusion sometimes:

  • assert(false) may cause confusion when it is unclear if NDEBUG can disable it. (The intention is to disallow NDEBUG compilation). Also, it can lead to warnings when used with clang-cl.exe (GCC seems to understand it)
  • Assert(false) hides the noreturn attribute behind a function call, which may cause GCC return-type warnings. (Clang seems to understand it)

See https://godbolt.org/z/h7PT3jh3Y for the clang-cl/GCC warning reproducer.

  • When C++23 will be allowed, devs may prefer std::unreachable. However, this is unsafe and will invoke UB.
  • There is confusion why a CHECK_NONFATAL macro exists, but no fatal equivalent.

Fix all those issues by:

  • Adding a new AssertUnreachable, which directly calls the noreturn internal_abort_helper helper.
  • Adding an assert_falsy linter to enforce code to use this macro.
The current code uses assertions with falsy literal values in a few places. This is perfectly fine, but this comes with a bit of confusion sometimes: * `assert(false)` may cause confusion when it is unclear if `NDEBUG` can disable it. (The intention is to disallow `NDEBUG` compilation). Also, it can lead to warnings when used with clang-cl.exe (GCC seems to understand it) * `Assert(false)` hides the noreturn attribute behind a function call, which may cause GCC return-type warnings. (Clang seems to understand it) See https://godbolt.org/z/h7PT3jh3Y for the clang-cl/GCC warning reproducer. * When C++23 will be allowed, devs may prefer `std::unreachable`. However, this is unsafe and will invoke UB. * There is confusion why a `CHECK_NONFATAL` macro exists, but no fatal equivalent. Fix all those issues by: * Adding a new `AssertUnreachable`, which directly calls the noreturn `internal_abort_helper` helper. * Adding an `assert_falsy` linter to enforce code to use this macro.
DrahtBot commented 2026-08-26 05:24:30 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK l0rinc, hodlinator, jeanpablojp, ryanofsky
Stale ACK hebasto

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #bitcoin-core/gui/945 (Fix sign message address book filtering by Bushstar)
  • #36897 (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes by achow101)
  • #36808 (iwyu: Fix warnings in src/test/fuzz and treat them as errors by hebasto)
  • #36689 (cli: Parse -signetchallenge like bitcoind by ekzyis)
  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)
  • #36549 (WIP: improve MallocUsage and test in CI by sipa)
  • #36434 (http: support unix sockets by pinheadmz)
  • #36122 (BIP460: CISA for Taproot key path spends by fjahr)
  • #35911 (Warn on and add missing [[noreturn]] by fanquake)
  • #35713 (Remove boost as a unit test runner by rustaceanrob)
  • #35302 (Silent Payments: Sending (take 2) by Eunovo)
  • #34909 (wallet, refactor: modularise wallet by extracting out legacy wallet migration by rkrux)
  • #34193 (wallet: make migration more robust against failures by furszy)
  • #34132 (coins,dbwrapper: make point-read and txindex lookup failures fatal by l0rinc)
  • #32575 (consensus: Remove special treatment for single threaded script checking by fjahr)
  • #31252 (rpc: print P2WSH and P2SH redem Script in getrawtransaction and getblock by polespinasa)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36087 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36087.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36087#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [l0rinc](https://github.com/bitcoin/bitcoin/pull/36087#pullrequestreview-5939301104), [hodlinator](https://github.com/bitcoin/bitcoin/pull/36087#pullrequestreview-5960395208), [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36087#issuecomment-6987081756), [ryanofsky](https://github.com/bitcoin/bitcoin/pull/36087#pullrequestreview-5998898881) | | Stale ACK | [hebasto](https://github.com/bitcoin/bitcoin/pull/36087#pullrequestreview-5872663164) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#bitcoin-core/gui/945](https://github.com/bitcoin-core/gui/pull/945) <sub><img src="https://drahtbot.space/ack_count/bitcoin-core/gui/945.svg"></sub> (Fix sign message address book filtering by Bushstar) * [#36897](https://github.com/bitcoin/bitcoin/pull/36897) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36897.svg"></sub> (wallet, migration: Contain all legacy wallet and migration related things in its own subdirectory, namespace, and classes by achow101) * [#36808](https://github.com/bitcoin/bitcoin/pull/36808) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36808.svg"></sub> (iwyu: Fix warnings in `src/test/fuzz` and treat them as errors by hebasto) * [#36689](https://github.com/bitcoin/bitcoin/pull/36689) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36689.svg"></sub> (cli: Parse -signetchallenge like bitcoind by ekzyis) * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc) * [#36549](https://github.com/bitcoin/bitcoin/pull/36549) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36549.svg"></sub> (WIP: improve MallocUsage and test in CI by sipa) * [#36434](https://github.com/bitcoin/bitcoin/pull/36434) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36434.svg"></sub> (http: support unix sockets by pinheadmz) * [#36122](https://github.com/bitcoin/bitcoin/pull/36122) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36122.svg"></sub> (BIP460: CISA for Taproot key path spends by fjahr) * [#35911](https://github.com/bitcoin/bitcoin/pull/35911) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35911.svg"></sub> (Warn on and add missing `[[noreturn]]` by fanquake) * [#35713](https://github.com/bitcoin/bitcoin/pull/35713) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35713.svg"></sub> (Remove boost as a unit test runner by rustaceanrob) * [#35302](https://github.com/bitcoin/bitcoin/pull/35302) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo) * [#34909](https://github.com/bitcoin/bitcoin/pull/34909) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34909.svg"></sub> (wallet, refactor: modularise wallet by extracting out legacy wallet migration by rkrux) * [#34193](https://github.com/bitcoin/bitcoin/pull/34193) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34193.svg"></sub> (wallet: make migration more robust against failures by furszy) * [#34132](https://github.com/bitcoin/bitcoin/pull/34132) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34132.svg"></sub> (coins,dbwrapper: make point-read and txindex lookup failures fatal by l0rinc) * [#32575](https://github.com/bitcoin/bitcoin/pull/32575) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/32575.svg"></sub> (consensus: Remove special treatment for single threaded script checking by fjahr) * [#31252](https://github.com/bitcoin/bitcoin/pull/31252) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/31252.svg"></sub> (rpc: print P2WSH and P2SH redem Script in getrawtransaction and getblock by polespinasa) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
DrahtBot commented 2026-08-26 05:45:37 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/32933915544/job/98071384264
LLM reason (✨ experimental): CI failed because the assert_falsy lint check detected an assert(0 && ...) (in src/tinyformat.h) that must be replaced with AssertUnreachable().

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/32933915544/job/98071384264</sub> <sub>LLM reason (✨ experimental): CI failed because the `assert_falsy` lint check detected an `assert(0 && ...)` (in `src/tinyformat.h`) that must be replaced with `AssertUnreachable()`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
DrahtBot commented 2026-08-26 15:52:52 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-08-29 08:43:27 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
jeanpablojp (Migrated from github.com) reviewed 2026-08-29 17:37:39 +00:00
jeanpablojp (Migrated from github.com) left a comment

Left 3 comments.

Left 3 comments.
jeanpablojp (Migrated from github.com) commented 2026-08-29 17:37:39 +00:00

AssertUnreachable here and in SignatureHashSchnorr calls assertion_fail from util/check.cpp. This file is in libbitcoin_consensus, which should only depend on crypto. Normal builds hide it, bitcoin_common pulls util in anyway, but the riscv job links the lib standalone and breaks. Exclude consensus from assert_falsy under the same "not linking the util lib" reason, or move assertion_fail?

`AssertUnreachable` here and in `SignatureHashSchnorr` calls `assertion_fail` from `util/check.cpp`. This file is in `libbitcoin_consensus`, which should only depend on crypto. Normal builds hide it, `bitcoin_common` pulls util in anyway, but the riscv job links the lib standalone and breaks. Exclude consensus from `assert_falsy` under the same "not linking the util lib" reason, or move `assertion_fail`?
jeanpablojp (Migrated from github.com) commented 2026-08-29 17:37:39 +00:00

The message says any falsy literal, but the regex hardcodes the spacing, so assert (false), assert(false ) and assert(0&&"x") all slip through. \<(a|A)ssert\s*\(\s*(0|false)\s*(&&|\)) catches them. And std_unreachable lets __builtin_unreachable() through. libstdc++ implements std::unreachable() as exactly that, and it builds under C++20 where std::unreachable() doesn't. Worth catching the builtin too?

The message says any falsy literal, but the regex hardcodes the spacing, so `assert (false)`, `assert(false )` and `assert(0&&"x")` all slip through. `\<(a|A)ssert\s*\(\s*(0|false)\s*(&&|\))` catches them. And `std_unreachable` lets `__builtin_unreachable()` through. libstdc++ implements `std::unreachable()` as exactly that, and it builds under C++20 where `std::unreachable()` doesn't. Worth catching the builtin too?
jeanpablojp (Migrated from github.com) commented 2026-08-29 17:37:39 +00:00

The scripted-diff that satisfies this linter is the next commit, so lint is red here, 135 lines. Swapping the two applies cleanly and gives the same tree. The linters already in master came in with their fix in one commit.

The scripted-diff that satisfies this linter is the next commit, so lint is red here, 135 lines. Swapping the two applies cleanly and gives the same tree. The linters already in master came in with their fix in one commit.
DrahtBot commented 2026-08-31 16:50:57 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
maflcko (Migrated from github.com) reviewed 2026-09-01 07:08:57 +00:00
maflcko (Migrated from github.com) commented 2026-09-01 07:08:57 +00:00

\<(a|A)ssert\s*\(\s*(0|false)\s*(&&|\))

Thx, used that.

__builtin_unreachable

I think the risk of someone using it should be low, because it is a compiler-specific built-in.

> `\<(a|A)ssert\s*\(\s*(0|false)\s*(&&|\))` Thx, used that. > __builtin_unreachable I think the risk of someone using it should be low, because it is a compiler-specific built-in.
maflcko (Migrated from github.com) reviewed 2026-09-01 07:09:01 +00:00
maflcko (Migrated from github.com) commented 2026-09-01 07:09:01 +00:00

Thx, swapped commits

Thx, swapped commits
maflcko (Migrated from github.com) reviewed 2026-09-01 07:09:37 +00:00
maflcko (Migrated from github.com) commented 2026-09-01 07:09:37 +00:00

Thx, will fix this some time before taking out of draft.

Thx, will fix this some time before taking out of draft.
DrahtBot commented 2026-09-05 13:21:01 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
First-time contributor

No verified findings are available from this review.

Review coverage was incomplete.


Reviewed: fa9a4ddbaf16 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:2b20819f882b885f79f242c01722f54f2a55e27dcfa7d5e13701b4a0b5214248:c39fdacfa3b84799844a5e841c04997e3cd1142653dfad8e36dbb07c4b1e684b --> <!-- ralph-base:e211dd0186e9646167d063a16f0da88e5f72e05f --> <!-- ralph-head:fa9a4ddbaf16d7fc8f8c336600674b3c7facca16 --> <!-- ralph-case:08ceb4ef466ea7e4bb7ca25b770468e7c376e6383f9f0b967a7a64afa31386cd --> No verified findings are available from this review. Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`fa9a4ddbaf16`](<https://git.fish.foo/bitcoin/bitcoin/commit/fa9a4ddbaf16d7fc8f8c336600674b3c7facca16>) · [Review report](<https://review.fish.foo/report/36087-fa9a4ddbaf16d7fc8f8c336600674b3c7facca16-2746-11.html>) · [Previous reports](<https://review.fish.foo/traces/36087/>) [permalink](<https://review.fish.foo/report/36087-fa9a4ddbaf16d7fc8f8c336600674b3c7facca16-2746-11.html>)
DrahtBot commented 2026-11-10 19:09:16 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/42874130721/job/130032819364
LLM reason (✨ experimental): CI failed because check-deps.sh detected an unexpected dependency: interpreter.cpp.o depends on check.cpp.o via internal_abort_helper.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `tidy`: https://github.com/bitcoin/bitcoin/actions/runs/42874130721/job/130032819364</sub> <sub>LLM reason (✨ experimental): CI failed because `check-deps.sh` detected an unexpected dependency: `interpreter.cpp.o` depends on `check.cpp.o` via `internal_abort_helper`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
maflcko (Migrated from github.com) reviewed 2026-11-10 19:33:48 +00:00
maflcko (Migrated from github.com) commented 2026-11-10 19:33:48 +00:00

thx, excluded for now

thx, excluded for now
hebasto (Migrated from github.com) reviewed 2026-11-11 16:49:20 +00:00
hebasto (Migrated from github.com) left a comment

Concept ACK.

Thank you for reviving this topic!

Concept ACK. Thank you for [reviving](https://github.com/bitcoin/bitcoin/pull/26504) this topic!
hebasto (Migrated from github.com) reviewed 2026-11-11 17:42:44 +00:00
hebasto (Migrated from github.com) left a comment
Approach ACK fa0f314a5c21207dcab090178b55ede2337f3610.. faf79448a2293c8f6be0b17fe753e27a16e41d1c, forgot this one? https://github.com/bitcoin/bitcoin/blob/fa0f314a5c21207dcab090178b55ede2337f3610/src/protocol.cpp#L95
hebasto (Migrated from github.com) commented 2026-11-11 17:41:59 +00:00

Dead code left over?

Dead code left over?
hebasto (Migrated from github.com) commented 2026-11-11 17:31:11 +00:00

fa3ec8d81d

This header does not belong in this group.

fa3ec8d81d141019e7a5352aec8f067970a027d7 This header does not belong in this group.
hebasto (Migrated from github.com) commented 2026-11-11 17:12:08 +00:00

faf79448a2

This makes #include <cassert> unnecessary.

faf79448a2293c8f6be0b17fe753e27a16e41d1c This makes `#include <cassert>` unnecessary.
hebasto (Migrated from github.com) commented 2026-11-11 17:35:07 +00:00

nit: Why not use the more readable form (assuming we are okay with side effects in the asserted expression)?

    Assert(LoadWalletFlags(flags));
nit: Why not use the more readable form (assuming we are okay with side effects in the asserted expression)? ```suggestion Assert(LoadWalletFlags(flags)); ```
hebasto (Migrated from github.com) commented 2026-11-11 17:06:08 +00:00

fa47891c9b

The new message no longer mentions assert, but the regex still catches it.

fa47891c9b8db91b055ccbbee0282c295a52deb0 The new message no longer mentions `assert`, but the regex still catches it.
DrahtBot commented 2026-11-12 08:10:10 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/43179667829/job/131052297731
LLM reason (✨ experimental): CI failed on lint checks: assert_falsy flags assert(false) in src/test/fuzz/util/wallet.h, and the scripted_diff check also failed.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/43179667829/job/131052297731</sub> <sub>LLM reason (✨ experimental): CI failed on lint checks: `assert_falsy` flags `assert(false)` in `src/test/fuzz/util/wallet.h`, and the `scripted_diff` check also failed.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
maflcko commented 2026-11-12 08:52:46 +00:00 (Migrated from github.com)

rebased for silent conflict and fixed all nits

rebased for silent conflict and fixed all nits
hebasto (Migrated from github.com) reviewed 2026-11-12 09:49:24 +00:00
hebasto (Migrated from github.com) left a comment

ACK fa5c2d1440.

nit:

--- a/src/protocol.cpp
+++ b/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}
ACK fa5c2d144060b0a855f35da7b9aae1d91f5258e5. nit: ```diff --- a/src/protocol.cpp +++ b/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} ```
hebasto (Migrated from github.com) commented 2026-11-12 09:49:12 +00:00

Why is src/script/interpreter.cpp the only bitcoin_consensus source excluded here? The other sources of that library do not link bitcoin_util either.

Why is `src/script/interpreter.cpp` the only [`bitcoin_consensus`](https://github.com/bitcoin/bitcoin/blob/c68583ab5a886b6add45a8607d762b71678c748c/src/CMakeLists.txt#L69-L87) source excluded here? The other sources of that library do not link `bitcoin_util` either.
maflcko (Migrated from github.com) reviewed 2026-11-12 10:00:45 +00:00
maflcko (Migrated from github.com) left a comment

fixed include nit

fixed include nit
maflcko (Migrated from github.com) commented 2026-11-10 21:20:38 +00:00

self-nit: Could be NotNull?

self-nit: Could be NotNull?
maflcko (Migrated from github.com) commented 2026-11-12 09:54:16 +00:00

There are other linters (linkers) that enforce the exclusion as well: https://github.com/bitcoin/bitcoin/pull/36087#issuecomment-6776675778. Happy to include the full list, but I think I'll leave as-is for now and this can be extended on a case-by-case basis, when needed. Hopefully this "fixes itself" some time in the future via the library cleanup efforts.

There are other linters (linkers) that enforce the exclusion as well: https://github.com/bitcoin/bitcoin/pull/36087#issuecomment-6776675778. Happy to include the full list, but I think I'll leave as-is for now and this can be extended on a case-by-case basis, when needed. Hopefully this "fixes itself" some time in the future via the library cleanup efforts.
hebasto (Migrated from github.com) approved these changes 2026-11-12 10:14:50 +00:00
hebasto (Migrated from github.com) left a comment

re-ACK fa343ffd11.

re-ACK fa343ffd11115063ee958f98954ff192b6e4a6e6.
hodlinator (Migrated from github.com) approved these changes 2026-11-16 12:48:19 +00:00
hodlinator (Migrated from github.com) left a comment

crACK fa343ffd11

Should reduce the issue with non-standard no-[[no_return]] assert()s on Windows Clang-CL as noted in https://github.com/bitcoin/bitcoin/pull/31507#discussion_r3801801387.

Makes me wonder if the scope of -Wno-error=return-type from ci-windows.py could be reduced to only code that doesn't depend on check.h, but don't see any obvious way to do it.

crACK fa343ffd11115063ee958f98954ff192b6e4a6e6 Should reduce the issue with non-standard no-`[[no_return]]` `assert()`s on Windows Clang-CL as noted in https://github.com/bitcoin/bitcoin/pull/31507#discussion_r3801801387. Makes me wonder if the scope of `-Wno-error=return-type` from ci-windows.py could be reduced to only code that doesn't depend on check.h, but don't see any obvious way to do it.
hodlinator (Migrated from github.com) commented 2026-11-16 12:00:35 +00:00

remark: It's not obvious to me whether this shouldn't be named and/or cased FATAL_UNREACHABLE().

Maybe the uppercasing of NONFATAL_UNREACHABLE() and CHECK_NONFATAL() could be inferred to mean that they have different effects in debug builds and release builds. That would explain why you didn't go that way with AssertUnreachable(). OTOH Assume() has different effects depending on the build too.

remark: It's not obvious to me whether this shouldn't be named and/or cased `FATAL_UNREACHABLE()`. Maybe the uppercasing of `NONFATAL_UNREACHABLE()` and `CHECK_NONFATAL()` could be inferred to mean that they have different effects in debug builds and release builds. That would explain why you didn't go that way with `AssertUnreachable()`. OTOH `Assume()` has different effects depending on the build too.
hodlinator (Migrated from github.com) commented 2026-11-16 11:44:17 +00:00

nanonit: Think it's healthier for the shared semantics of the project to imply that all asserts are fatal rather than suggesting there are two classes.

CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of asserts or aborts
nanonit: Think it's healthier for the shared semantics of the project to imply that all asserts are fatal rather than suggesting there are two classes. ```suggestion CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of asserts or aborts ```
hodlinator (Migrated from github.com) commented 2026-11-16 12:27:00 +00:00

nit: This is not entirely true, asserting 0 occurs in two places.

            ":(exclude)src/tinyformat.h", // Avoid flagging externally maintained code
nit: This is not entirely true, asserting `0` occurs in two places. ```suggestion ":(exclude)src/tinyformat.h", // Avoid flagging externally maintained code ```
maflcko (Migrated from github.com) reviewed 2026-11-16 14:14:50 +00:00
maflcko (Migrated from github.com) commented 2026-11-16 14:14:50 +00:00

ok, I may or may not reconsider this on the next push. I think the linter is fine either way for now.

ok, I may or may not reconsider this on the next push. I think the linter is fine either way for now.
maflcko (Migrated from github.com) reviewed 2026-11-16 14:14:52 +00:00
maflcko (Migrated from github.com) commented 2026-11-16 14:14:52 +00:00

Assert already means fatal in this codebase and this is a bit like an AssertZero() (always fails), so I kept consistency with that. But naming is always hard and subjective, I guess.

`Assert` already means fatal in this codebase and this is a bit like an `AssertZero()` (always fails), so I kept consistency with that. But naming is always hard and subjective, I guess.
maflcko (Migrated from github.com) reviewed 2026-11-16 14:14:55 +00:00
maflcko (Migrated from github.com) commented 2026-11-16 14:14:55 +00:00

Which ones? Did you see #define TINYFORMAT_ERROR(reasonString) throw tinyformat::format_error(reasonString)?

Which ones? Did you see `#define TINYFORMAT_ERROR(reasonString) throw tinyformat::format_error(reasonString)`?
hodlinator (Migrated from github.com) reviewed 2026-11-16 14:26:02 +00:00
hodlinator (Migrated from github.com) commented 2026-11-16 14:26:02 +00:00

That disables one of them, but there's also a TINYFORMAT_ASSERT(0) (which admittedly doesn't match the regex).

That disables one of them, but there's also a `TINYFORMAT_ASSERT(0)` (which admittedly doesn't match the regex).
maflcko (Migrated from github.com) reviewed 2026-11-16 15:11:36 +00:00
maflcko (Migrated from github.com) commented 2026-11-16 15:11:36 +00:00

Ah, didn't see that. Though, at this point, it isn't really "externally maintained". At some point this will all be removed, so it doesn't matter, but if I touch this again, I can say: // Avoid flagging dead branches in temporary std::format port

Ah, didn't see that. Though, at this point, it isn't really "externally maintained". At some point this will all be removed, so it doesn't matter, but if I touch this again, I can say: `// Avoid flagging dead branches in temporary std::format port`
l0rinc (Migrated from github.com) requested changes 2026-11-16 15:43:32 +00:00
l0rinc (Migrated from github.com) left a comment

Concept ACK!
Glad we're converging on the assert-cleanup-project™ - might as well simplify a few more of these while we're here, so we don't have to revisit the same lines later.
I don't insist on any of them, but wanted to present the inconsistencies.

Concept ACK! Glad we're converging on the assert-cleanup-project™ - might as well simplify a few more of these while we're here, so we don't have to revisit the same lines later. I don't insist on any of them, but wanted to present the inconsistencies.
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:41 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

This could just be a plain assert, the log seems superfluous:

Assert the addrman check directly
diff --git a/src/addrman.cpp b/src/addrman.cpp
index fe7bb0e65a..02d2b2f963 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -1042,11 +1042,7 @@ void AddrManImpl::Check() const
     if (m_consistency_check_ratio == 0) return;
     if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return;
 
-    const int err{CheckAddrman()};
-    if (err) {
-        LogError("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err);
-        AssertUnreachable();
-    }
+    Assert(CheckAddrman() == 0);
 }
 
 int AddrManImpl::CheckAddrman() const
> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: This could just be a plain assert, the log seems superfluous: <details> <summary>Assert the addrman check directly</summary> ```diff diff --git a/src/addrman.cpp b/src/addrman.cpp index fe7bb0e65a..02d2b2f963 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -1042,11 +1042,7 @@ void AddrManImpl::Check() const if (m_consistency_check_ratio == 0) return; if (insecure_rand.randrange(m_consistency_check_ratio) >= 1) return; - const int err{CheckAddrman()}; - if (err) { - LogError("ADDRMAN CONSISTENCY CHECK FAILED!!! err=%i", err); - AssertUnreachable(); - } + Assert(CheckAddrman() == 0); } int AddrManImpl::CheckAddrman() const ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:46 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

Might as well tidy this up while we're here:

Assert the remaining command
diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp
index e335d1e8e1..c1bc2fb0e6 100644
--- a/src/bitcoin-util.cpp
+++ b/src/bitcoin-util.cpp
@@ -241,10 +241,9 @@ MAIN_FUNCTION
     try {
         if (cmd->command == "grind") {
             ret = Grind(cmd->args, strPrint);
-        } else if (cmd->command == "getchainparams") {
-            ret = GetChainParams(cmd->args, strPrint);
         } else {
-            AssertUnreachable(); // unknown command should be caught earlier
+            Assert(cmd->command == "getchainparams");
+            ret = GetChainParams(cmd->args, strPrint);
         }
     } catch (const std::exception& e) {
         strPrint = std::string("error: ") + e.what();
> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: Might as well tidy this up while we're here: <details> <summary>Assert the remaining command</summary> ```diff diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp index e335d1e8e1..c1bc2fb0e6 100644 --- a/src/bitcoin-util.cpp +++ b/src/bitcoin-util.cpp @@ -241,10 +241,9 @@ MAIN_FUNCTION try { if (cmd->command == "grind") { ret = Grind(cmd->args, strPrint); - } else if (cmd->command == "getchainparams") { - ret = GetChainParams(cmd->args, strPrint); } else { - AssertUnreachable(); // unknown command should be caught earlier + Assert(cmd->command == "getchainparams"); + ret = GetChainParams(cmd->args, strPrint); } } catch (const std::exception& e) { strPrint = std::string("error: ") + e.what(); ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:01 +00:00

fa97e3a refactor: Use AssertUnreachable() and remove dead code:

Maybe extend the existing scripted diff to cover these, too?

Use AssertUnreachable in both fallbacks
diff --git a/src/validation.h b/src/validation.h
index 68c1f7e0a4..09f29154c8 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -1140,7 +1140,7 @@ public:
         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 @@ public:
         for (auto* cs : {&CurrentChainstate(), HistoricalChainstate()}) {
             if (cs && cs->m_assumeutxo == Assumeutxo::VALIDATED) return *cs;
         }
-        abort();
+        AssertUnreachable();
     }
 
     //! Remove a chainstate.
> [fa97e3a](https://github.com/bitcoin/bitcoin/pull/36087/changes/fa97e3ab1c062723d2f110a5e6a0e664e4f37e1d) _refactor: Use AssertUnreachable() and remove dead code_: Maybe extend the existing scripted diff to cover these, too? <details> <summary>Use AssertUnreachable in both fallbacks</summary> ```diff diff --git a/src/validation.h b/src/validation.h index 68c1f7e0a4..09f29154c8 100644 --- a/src/validation.h +++ b/src/validation.h @@ -1140,7 +1140,7 @@ public: 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 @@ public: for (auto* cs : {&CurrentChainstate(), HistoricalChainstate()}) { if (cs && cs->m_assumeutxo == Assumeutxo::VALIDATED) return *cs; } - abort(); + AssertUnreachable(); } //! Remove a chainstate. ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:33 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

nit: same comment as in to_btck for consistency?

Explain the omitted defaults
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index f68dc7b8b4..84ce94e240 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -441,7 +441,7 @@ private:
             return " regtest";
         case ChainType::MAIN:
             return "";
-        }
+        } // no default case, so the compiler can warn about missing cases
         AssertUnreachable();
     }
     std::string PingTimeToString(double seconds) const
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index 7d255d623f..fed439c7ab 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -158,7 +158,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
         ReadRegTestArgs(args, opts);
         return CChainParams::RegTest(opts);
     }
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp
index 61889bdd82..70ccc1287e 100644
--- a/src/chainparamsbase.cpp
+++ b/src/chainparamsbase.cpp
@@ -71,7 +71,7 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ArgsManager& args,
         return std::make_unique<CBaseChainParams>(GetSignetDataDir(args), 38332);
     case ChainType::REGTEST:
         return std::make_unique<CBaseChainParams>("regtest", 18443);
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp
index 732e7074fa..27f3272c1a 100644
--- a/src/kernel/bitcoinkernel.cpp
+++ b/src/kernel/bitcoinkernel.cpp
@@ -179,7 +179,7 @@ constexpr util::log::Level to_util(btck_LogLevel level)
     case btck_LogLevel_ERROR: {
         return util::log::Level::Error;
     }
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
@@ -1066,7 +1066,7 @@ btck_ChainParameters* btck_chain_parameters_create(const btck_ChainType chain_ty
     case btck_ChainType_REGTEST: {
         return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::RegTest().release()));
     }
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/kernel/mempool_removal_reason.cpp b/src/kernel/mempool_removal_reason.cpp
index a078d081b2..9c32172893 100644
--- a/src/kernel/mempool_removal_reason.cpp
+++ b/src/kernel/mempool_removal_reason.cpp
@@ -17,6 +17,6 @@ std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept
         case MemPoolRemovalReason::BLOCK: return "block";
         case MemPoolRemovalReason::CONFLICT: return "conflict";
         case MemPoolRemovalReason::REPLACED: return "replaced";
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
diff --git a/src/logging.cpp b/src/logging.cpp
index edf799c800..de5ae7f67b 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -254,7 +254,7 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level)
         return "warning";
     case BCLog::Level::Error:
         return "error";
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp
index 014b4df4db..1e347ac9df 100644
--- a/src/script/descriptor.cpp
+++ b/src/script/descriptor.cpp
@@ -2331,7 +2331,7 @@ struct KeyParser {
         switch (m_script_ctx) {
             case miniscript::MiniscriptContext::P2WSH: return ParseScriptContext::P2WSH;
             case miniscript::MiniscriptContext::TAPSCRIPT: return ParseScriptContext::P2TR;
-        }
+        } // no default case, so the compiler can warn about missing cases
         AssertUnreachable();
     }
 
diff --git a/src/script/miniscript.cpp b/src/script/miniscript.cpp
index 6dfa6832b4..7e34ac35d1 100644
--- a/src/script/miniscript.cpp
+++ b/src/script/miniscript.cpp
@@ -257,7 +257,7 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty
                    "s"_mst.If(num_s >= n_subs - k + 1) |  // s= >=(n-k+1) s
                    acc_tl; // timelock info
             }
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
@@ -291,7 +291,7 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_
         case Fragment::ANDOR: return subsize + 3;
         case Fragment::WRAP_J: return subsize + 4;
         case Fragment::THRESH: return subsize + n_subs + BuildScript(k).size();
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/script/miniscript.h b/src/script/miniscript.h
index 1ac4d71eec..1a24d39bfc 100644
--- a/src/script/miniscript.h
+++ b/src/script/miniscript.h
@@ -261,7 +261,7 @@ constexpr bool IsTapscript(MiniscriptContext ms_ctx)
     switch (ms_ctx) {
         case MiniscriptContext::P2WSH: return false;
         case MiniscriptContext::TAPSCRIPT: return true;
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
@@ -867,7 +867,7 @@ public:
                     }
                     return BuildScript(std::move(script), node.k, verify ? OP_EQUALVERIFY : OP_EQUAL);
                 }
-            }
+            } // no default case, so the compiler can warn about missing cases
             AssertUnreachable();
         };
         return TreeEval<CScript>(false, downfn, upfn);
@@ -1071,7 +1071,7 @@ private:
                 assert(k < sats.size());
                 return {count, sats[k], sats[0]};
             }
-        }
+        } // no default case, so the compiler can warn about missing cases
         AssertUnreachable();
     }
 
@@ -1186,7 +1186,7 @@ private:
                     sats[0] + SatInfo::Push() + SatInfo::OP_EQUAL()
                 };
             }
-        }
+        } // no default case, so the compiler can warn about missing cases
         AssertUnreachable();
     }
 
@@ -1239,7 +1239,7 @@ private:
                 assert(k < sats.size());
                 return {sats[k], sats[0]};
             }
-        }
+        } // no default case, so the compiler can warn about missing cases
         AssertUnreachable();
     }
 
@@ -1440,7 +1440,7 @@ private:
                 }
                 case Fragment::JUST_0: return {EMPTY, INVALID};
                 case Fragment::JUST_1: return {INVALID, EMPTY};
-            }
+            } // no default case, so the compiler can warn about missing cases
             AssertUnreachable();
         };
 
diff --git a/src/test/fuzz/http_request.cpp b/src/test/fuzz/http_request.cpp
index fcdcd1a4e5..88627d81cf 100644
--- a/src/test/fuzz/http_request.cpp
+++ b/src/test/fuzz/http_request.cpp
@@ -82,7 +82,7 @@ int StateRank(HTTPRequest::State s)
     case HTTPRequest::State::NeedsBody: return 2;
     case HTTPRequest::State::Complete: return 3;
     case HTTPRequest::State::Error: return 4;
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/test/fuzz/miniscript.cpp b/src/test/fuzz/miniscript.cpp
index 77c34415f0..22d86aabca 100644
--- a/src/test/fuzz/miniscript.cpp
+++ b/src/test/fuzz/miniscript.cpp
@@ -834,7 +834,7 @@ std::optional<NodeInfo> ConsumeNodeSmart(MsCtx script_ctx, FuzzedDataProvider& p
             while (subs.size() < children) subs.push_back(subs.back());
             return {{std::move(subs), frag, k}};
         }
-    }
+    } // no default case, so the compiler can warn about missing cases
 
     AssertUnreachable();
 }
diff --git a/src/util/chaintype.cpp b/src/util/chaintype.cpp
index 7078a50c8f..5391c2e8ba 100644
--- a/src/util/chaintype.cpp
+++ b/src/util/chaintype.cpp
@@ -22,7 +22,7 @@ std::string ChainTypeToString(ChainType chain)
         return "signet";
     case ChainType::REGTEST:
         return "regtest";
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
diff --git a/src/validation.cpp b/src/validation.cpp
index 89deea5215..5ff03f9c3e 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2110,7 +2110,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state,
                 return state.Invalid(TxValidationResult::TX_NOT_STANDARD, strprintf("mempool-script-verify-flag-failed (%s)", ScriptErrorString(result->first)), result->second);
             case CheckInputScriptsFor::Block:
                 return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("block-script-verify-flag-failed (%s)", ScriptErrorString(result->first)), result->second);
-            }
+            } // no default case, so the compiler can warn about missing cases
             AssertUnreachable();
         }
     }
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index 66deb1c9bc..9274c39204 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -209,7 +209,7 @@ bool LegacyDataSPKM::IsMine(const CScript& script) const
     case IsMineResult::WATCH_ONLY:
     case IsMineResult::SPENDABLE:
         return true;
-    }
+    } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
 
> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: nit: same comment as in `to_btck` for consistency? <details> <summary>Explain the omitted defaults</summary> ```diff diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index f68dc7b8b4..84ce94e240 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -441,7 +441,7 @@ private: return " regtest"; case ChainType::MAIN: return ""; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } std::string PingTimeToString(double seconds) const diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 7d255d623f..fed439c7ab 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -158,7 +158,7 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c ReadRegTestArgs(args, opts); return CChainParams::RegTest(opts); } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 61889bdd82..70ccc1287e 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -71,7 +71,7 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const ArgsManager& args, return std::make_unique<CBaseChainParams>(GetSignetDataDir(args), 38332); case ChainType::REGTEST: return std::make_unique<CBaseChainParams>("regtest", 18443); - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/kernel/bitcoinkernel.cpp b/src/kernel/bitcoinkernel.cpp index 732e7074fa..27f3272c1a 100644 --- a/src/kernel/bitcoinkernel.cpp +++ b/src/kernel/bitcoinkernel.cpp @@ -179,7 +179,7 @@ constexpr util::log::Level to_util(btck_LogLevel level) case btck_LogLevel_ERROR: { return util::log::Level::Error; } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } @@ -1066,7 +1066,7 @@ btck_ChainParameters* btck_chain_parameters_create(const btck_ChainType chain_ty case btck_ChainType_REGTEST: { return btck_ChainParameters::ref(const_cast<CChainParams*>(CChainParams::RegTest().release())); } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/kernel/mempool_removal_reason.cpp b/src/kernel/mempool_removal_reason.cpp index a078d081b2..9c32172893 100644 --- a/src/kernel/mempool_removal_reason.cpp +++ b/src/kernel/mempool_removal_reason.cpp @@ -17,6 +17,6 @@ std::string RemovalReasonToString(const MemPoolRemovalReason& r) noexcept case MemPoolRemovalReason::BLOCK: return "block"; case MemPoolRemovalReason::CONFLICT: return "conflict"; case MemPoolRemovalReason::REPLACED: return "replaced"; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/logging.cpp b/src/logging.cpp index edf799c800..de5ae7f67b 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -254,7 +254,7 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level) return "warning"; case BCLog::Level::Error: return "error"; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 014b4df4db..1e347ac9df 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -2331,7 +2331,7 @@ struct KeyParser { switch (m_script_ctx) { case miniscript::MiniscriptContext::P2WSH: return ParseScriptContext::P2WSH; case miniscript::MiniscriptContext::TAPSCRIPT: return ParseScriptContext::P2TR; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/script/miniscript.cpp b/src/script/miniscript.cpp index 6dfa6832b4..7e34ac35d1 100644 --- a/src/script/miniscript.cpp +++ b/src/script/miniscript.cpp @@ -257,7 +257,7 @@ Type ComputeType(Fragment fragment, Type x, Type y, Type z, const std::vector<Ty "s"_mst.If(num_s >= n_subs - k + 1) | // s= >=(n-k+1) s acc_tl; // timelock info } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } @@ -291,7 +291,7 @@ size_t ComputeScriptLen(Fragment fragment, Type sub0typ, size_t subsize, uint32_ case Fragment::ANDOR: return subsize + 3; case Fragment::WRAP_J: return subsize + 4; case Fragment::THRESH: return subsize + n_subs + BuildScript(k).size(); - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/script/miniscript.h b/src/script/miniscript.h index 1ac4d71eec..1a24d39bfc 100644 --- a/src/script/miniscript.h +++ b/src/script/miniscript.h @@ -261,7 +261,7 @@ constexpr bool IsTapscript(MiniscriptContext ms_ctx) switch (ms_ctx) { case MiniscriptContext::P2WSH: return false; case MiniscriptContext::TAPSCRIPT: return true; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } @@ -867,7 +867,7 @@ public: } return BuildScript(std::move(script), node.k, verify ? OP_EQUALVERIFY : OP_EQUAL); } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); }; return TreeEval<CScript>(false, downfn, upfn); @@ -1071,7 +1071,7 @@ private: assert(k < sats.size()); return {count, sats[k], sats[0]}; } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } @@ -1186,7 +1186,7 @@ private: sats[0] + SatInfo::Push() + SatInfo::OP_EQUAL() }; } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } @@ -1239,7 +1239,7 @@ private: assert(k < sats.size()); return {sats[k], sats[0]}; } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } @@ -1440,7 +1440,7 @@ private: } case Fragment::JUST_0: return {EMPTY, INVALID}; case Fragment::JUST_1: return {INVALID, EMPTY}; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); }; diff --git a/src/test/fuzz/http_request.cpp b/src/test/fuzz/http_request.cpp index fcdcd1a4e5..88627d81cf 100644 --- a/src/test/fuzz/http_request.cpp +++ b/src/test/fuzz/http_request.cpp @@ -82,7 +82,7 @@ int StateRank(HTTPRequest::State s) case HTTPRequest::State::NeedsBody: return 2; case HTTPRequest::State::Complete: return 3; case HTTPRequest::State::Error: return 4; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/test/fuzz/miniscript.cpp b/src/test/fuzz/miniscript.cpp index 77c34415f0..22d86aabca 100644 --- a/src/test/fuzz/miniscript.cpp +++ b/src/test/fuzz/miniscript.cpp @@ -834,7 +834,7 @@ std::optional<NodeInfo> ConsumeNodeSmart(MsCtx script_ctx, FuzzedDataProvider& p while (subs.size() < children) subs.push_back(subs.back()); return {{std::move(subs), frag, k}}; } - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/util/chaintype.cpp b/src/util/chaintype.cpp index 7078a50c8f..5391c2e8ba 100644 --- a/src/util/chaintype.cpp +++ b/src/util/chaintype.cpp @@ -22,7 +22,7 @@ std::string ChainTypeToString(ChainType chain) return "signet"; case ChainType::REGTEST: return "regtest"; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } diff --git a/src/validation.cpp b/src/validation.cpp index 89deea5215..5ff03f9c3e 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2110,7 +2110,7 @@ bool CheckInputScripts(const CTransaction& tx, TxValidationState& state, return state.Invalid(TxValidationResult::TX_NOT_STANDARD, strprintf("mempool-script-verify-flag-failed (%s)", ScriptErrorString(result->first)), result->second); case CheckInputScriptsFor::Block: return state.Invalid(TxValidationResult::TX_CONSENSUS, strprintf("block-script-verify-flag-failed (%s)", ScriptErrorString(result->first)), result->second); - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } } diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index 66deb1c9bc..9274c39204 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -209,7 +209,7 @@ bool LegacyDataSPKM::IsMine(const CScript& script) const case IsMineResult::WATCH_ONLY: case IsMineResult::SPENDABLE: return true; - } + } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:10 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

compat/assumptions.h already checks this (and even mentions MallocUsage).

Use the existing pointer-width check
diff --git a/src/memusage.h b/src/memusage.h
index d5777c37de..9a763ca32c 100644
--- a/src/memusage.h
+++ b/src/memusage.h
@@ -8,7 +8,6 @@
 #include <indirectmap.h>
 #include <prevector.h>
 #include <support/allocators/pool.h>
-#include <util/check.h>
 
 #include <cstdlib>
 #include <list>
@@ -56,10 +55,8 @@ static inline size_t MallocUsage(size_t alloc)
         return 0;
     } else if (sizeof(void*) == 8) {
         return ((alloc + 31) >> 4) << 4;
-    } else if (sizeof(void*) == 4) {
+    } else { // 4-byte pointers, guaranteed by compat/assumptions.h
         return ((alloc + 15) >> 3) << 3;
-    } else {
-        AssertUnreachable();
     }
 }
 
> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: `compat/assumptions.h` already checks this (and even mentions `MallocUsage`). <details> <summary>Use the existing pointer-width check</summary> ```diff diff --git a/src/memusage.h b/src/memusage.h index d5777c37de..9a763ca32c 100644 --- a/src/memusage.h +++ b/src/memusage.h @@ -8,7 +8,6 @@ #include <indirectmap.h> #include <prevector.h> #include <support/allocators/pool.h> -#include <util/check.h> #include <cstdlib> #include <list> @@ -56,10 +55,8 @@ static inline size_t MallocUsage(size_t alloc) return 0; } else if (sizeof(void*) == 8) { return ((alloc + 31) >> 4) << 4; - } else if (sizeof(void*) == 4) { + } else { // 4-byte pointers, guaranteed by compat/assumptions.h return ((alloc + 15) >> 3) << 3; - } else { - AssertUnreachable(); } } ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:33:02 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

We still get warnings for missing cases this way (and is less repetitive if we just break):

Share the final assertion
diff --git a/src/netaddress.cpp b/src/netaddress.cpp
index c89569142c..64a0db7839 100644
--- a/src/netaddress.cpp
+++ b/src/netaddress.cpp
@@ -41,7 +41,7 @@ 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
-        AssertUnreachable();
+        break;
     } // no default case, so the compiler can warn about missing cases
 
     AssertUnreachable();
@@ -495,7 +495,7 @@ 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
-        AssertUnreachable();
+        break;
     } // no default case, so the compiler can warn about missing cases
 
     AssertUnreachable();
@@ -602,7 +602,7 @@ 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
-        AssertUnreachable();
+        break;
     } // no default case, so the compiler can warn about missing cases
 
     AssertUnreachable();
diff --git a/src/netbase.cpp b/src/netbase.cpp
index 587824b33a..510e1216c4 100644
--- a/src/netbase.cpp
+++ b/src/netbase.cpp
@@ -122,7 +122,7 @@ std::string GetNetworkName(enum Network net)
     case NET_I2P: return "i2p";
     case NET_CJDNS: return "cjdns";
     case NET_INTERNAL: return "internal";
-    case NET_MAX: AssertUnreachable();
+    case NET_MAX: break;
     } // no default case, so the compiler can warn about missing cases
 
     AssertUnreachable();
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index bdeb4d77e6..dbfe8ce61f 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -694,7 +694,7 @@ 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: AssertUnreachable();
+    case NET_MAX: break;
     } // no default case, so the compiler can warn about missing cases
     AssertUnreachable();
 }
> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: We still get warnings for missing cases this way (and is less repetitive if we just break): <details> <summary>Share the final assertion</summary> ```diff diff --git a/src/netaddress.cpp b/src/netaddress.cpp index c89569142c..64a0db7839 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -41,7 +41,7 @@ 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 - AssertUnreachable(); + break; } // no default case, so the compiler can warn about missing cases AssertUnreachable(); @@ -495,7 +495,7 @@ 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 - AssertUnreachable(); + break; } // no default case, so the compiler can warn about missing cases AssertUnreachable(); @@ -602,7 +602,7 @@ 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 - AssertUnreachable(); + break; } // no default case, so the compiler can warn about missing cases AssertUnreachable(); diff --git a/src/netbase.cpp b/src/netbase.cpp index 587824b33a..510e1216c4 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -122,7 +122,7 @@ std::string GetNetworkName(enum Network net) case NET_I2P: return "i2p"; case NET_CJDNS: return "cjdns"; case NET_INTERNAL: return "internal"; - case NET_MAX: AssertUnreachable(); + case NET_MAX: break; } // no default case, so the compiler can warn about missing cases AssertUnreachable(); diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index bdeb4d77e6..dbfe8ce61f 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -694,7 +694,7 @@ 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: AssertUnreachable(); + case NET_MAX: break; } // no default case, so the compiler can warn about missing cases AssertUnreachable(); } ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:54 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

If this is indeed unreachable, we could collapse it to a single return with comment:

Return the comparison
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index d8a299fd5d..5c365dbd67 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -161,14 +161,7 @@ static bool ErrorSettingsRead(const bilingual_str& error, const std::vector<std:
     messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(details)));
     messagebox.setTextFormat(Qt::PlainText);
     messagebox.setDefaultButton(QMessageBox::Reset);
-    switch (messagebox.exec()) {
-    case QMessageBox::Reset:
-        return false;
-    case QMessageBox::Abort:
-        return true;
-    default:
-        AssertUnreachable();
-    }
+    return messagebox.exec() == QMessageBox::Abort; // Reset or Abort
 }
 
 static void ErrorSettingsWrite(const bilingual_str& error, const std::vector<std::string>& details)
> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: If this is indeed unreachable, we could collapse it to a single return with comment: <details> <summary>Return the comparison</summary> ```diff diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index d8a299fd5d..5c365dbd67 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -161,14 +161,7 @@ static bool ErrorSettingsRead(const bilingual_str& error, const std::vector<std: messagebox.setDetailedText(QString::fromStdString(MakeUnorderedList(details))); messagebox.setTextFormat(Qt::PlainText); messagebox.setDefaultButton(QMessageBox::Reset); - switch (messagebox.exec()) { - case QMessageBox::Reset: - return false; - case QMessageBox::Abort: - return true; - default: - AssertUnreachable(); - } + return messagebox.exec() == QMessageBox::Abort; // Reset or Abort } static void ErrorSettingsWrite(const bilingual_str& error, const std::vector<std::string>& details) ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:18 +00:00

fa97e3a refactor: Use AssertUnreachable() and remove dead code:

nit: we can just fall through

Share the two case labels
diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp
index 892b362262..f740ca15bb 100644
--- a/src/test/fuzz/tx_pool.cpp
+++ b/src/test/fuzz/tx_pool.cpp
@@ -288,13 +288,9 @@ 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
-        AssertUnreachable();
-    }
     case MempoolAcceptResult::ResultType::DIFFERENT_WITNESS:
     {
-        // ATMP never sets this; only set in package settings
+        // Only set in package settings, never by ATMP
         AssertUnreachable();
     }
     }
> [fa97e3a](https://github.com/bitcoin/bitcoin/pull/36087/changes/fa97e3ab1c062723d2f110a5e6a0e664e4f37e1d) _refactor: Use AssertUnreachable() and remove dead code_: nit: we can just fall through <details> <summary>Share the two case labels</summary> ```diff diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index 892b362262..f740ca15bb 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -288,13 +288,9 @@ 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 - AssertUnreachable(); - } case MempoolAcceptResult::ResultType::DIFFERENT_WITNESS: { - // ATMP never sets this; only set in package settings + // Only set in package settings, never by ATMP AssertUnreachable(); } } ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:32:26 +00:00

fa97e3a refactor: Use AssertUnreachable() and remove dead code:

As far as I can tell, ZeroSock already does this. Is the more specific error location a reason to keep these?

Inherit the existing assignment guard
diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp
index b8933d08fa..ab4db9cc27 100644
--- a/src/test/httpserver_tests.cpp
+++ b/src/test/httpserver_tests.cpp
@@ -782,10 +782,6 @@ BOOST_AUTO_TEST_CASE(http_should_disconnect_tests)
             ssize_t Send(const void*, size_t len, int) const override {
                 return CeilDiv(len, 2U); // Only let through half per call
             }
-        private:
-            SlowSocket& operator=(Sock&&) override {
-                AssertUnreachable(); // Move of Sock into SlowSocket not allowed.
-            }
         };
 
         // A request handed to a worker holds the idle timeout off until the reply is sent.
@@ -1032,7 +1028,6 @@ BOOST_AUTO_TEST_CASE(http_socket_error_tests)
     {
     public:
         explicit ErrorSock(std::shared_ptr<Pipes> pipes) : DynSock{std::move(pipes)} {}
-        DynSock& operator=(Sock&&) override { AssertUnreachable(); }
 
         ssize_t Send(const void* buf, size_t len, int flags) const override
         {
diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp
index 681f9e851e..11333ad449 100644
--- a/src/test/util/net.cpp
+++ b/src/test/util/net.cpp
@@ -255,11 +255,6 @@ ssize_t StaticContentsSock::Recv(void* buf, size_t len, int flags) const
     return consume_bytes;
 }
 
-StaticContentsSock& StaticContentsSock::operator=(Sock&& other)
-{
-    AssertUnreachable(); // Move of Sock into StaticContentsSock not allowed.
-}
-
 ssize_t DynSock::Pipe::GetBytes(void* buf, size_t len, int flags)
 {
     LOCK(m_mutex);
@@ -374,8 +369,3 @@ bool DynSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_
 
     return true;
 }
-
-DynSock& DynSock::operator=(Sock&&)
-{
-    AssertUnreachable(); // Move of Sock into DynSock not allowed.
-}
diff --git a/src/test/util/net.h b/src/test/util/net.h
index d226244077..ff80f4999f 100644
--- a/src/test/util/net.h
+++ b/src/test/util/net.h
@@ -225,8 +225,6 @@ public:
     }
 
 private:
-    StaticContentsSock& operator=(Sock&& other) override;
-
     const std::string m_contents;
     mutable size_t m_consumed{0};
 };
@@ -341,8 +339,6 @@ public:
     bool WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per_sock) const override;
 
 private:
-    DynSock& operator=(Sock&&) override;
-
     std::shared_ptr<Pipes> m_pipes;
     Queue* const m_accept_sockets;
 };
> [fa97e3a](https://github.com/bitcoin/bitcoin/pull/36087/changes/fa97e3ab1c062723d2f110a5e6a0e664e4f37e1d) _refactor: Use AssertUnreachable() and remove dead code_: As far as I can tell, `ZeroSock` already does this. Is the more specific error location a reason to keep these? <details> <summary>Inherit the existing assignment guard</summary> ```diff diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp index b8933d08fa..ab4db9cc27 100644 --- a/src/test/httpserver_tests.cpp +++ b/src/test/httpserver_tests.cpp @@ -782,10 +782,6 @@ BOOST_AUTO_TEST_CASE(http_should_disconnect_tests) ssize_t Send(const void*, size_t len, int) const override { return CeilDiv(len, 2U); // Only let through half per call } - private: - SlowSocket& operator=(Sock&&) override { - AssertUnreachable(); // Move of Sock into SlowSocket not allowed. - } }; // A request handed to a worker holds the idle timeout off until the reply is sent. @@ -1032,7 +1028,6 @@ BOOST_AUTO_TEST_CASE(http_socket_error_tests) { public: explicit ErrorSock(std::shared_ptr<Pipes> pipes) : DynSock{std::move(pipes)} {} - DynSock& operator=(Sock&&) override { AssertUnreachable(); } ssize_t Send(const void* buf, size_t len, int flags) const override { diff --git a/src/test/util/net.cpp b/src/test/util/net.cpp index 681f9e851e..11333ad449 100644 --- a/src/test/util/net.cpp +++ b/src/test/util/net.cpp @@ -255,11 +255,6 @@ ssize_t StaticContentsSock::Recv(void* buf, size_t len, int flags) const return consume_bytes; } -StaticContentsSock& StaticContentsSock::operator=(Sock&& other) -{ - AssertUnreachable(); // Move of Sock into StaticContentsSock not allowed. -} - ssize_t DynSock::Pipe::GetBytes(void* buf, size_t len, int flags) { LOCK(m_mutex); @@ -374,8 +369,3 @@ bool DynSock::WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_ return true; } - -DynSock& DynSock::operator=(Sock&&) -{ - AssertUnreachable(); // Move of Sock into DynSock not allowed. -} diff --git a/src/test/util/net.h b/src/test/util/net.h index d226244077..ff80f4999f 100644 --- a/src/test/util/net.h +++ b/src/test/util/net.h @@ -225,8 +225,6 @@ public: } private: - StaticContentsSock& operator=(Sock&& other) override; - const std::string m_contents; mutable size_t m_consumed{0}; }; @@ -341,8 +339,6 @@ public: bool WaitMany(std::chrono::milliseconds timeout, EventsPerSock& events_per_sock) const override; private: - DynSock& operator=(Sock&&) override; - std::shared_ptr<Pipes> m_pipes; Queue* const m_accept_sockets; }; ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:31:51 +00:00

fa97e3a refactor: Use AssertUnreachable() and remove dead code:

Same as in InitWalletFlags: it's weird to do if not ... assert(false)...

Assert the wallet results
diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp
index d917f6b2bb..66deb1c9bc 100644
--- a/src/wallet/scriptpubkeyman.cpp
+++ b/src/wallet/scriptpubkeyman.cpp
@@ -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)) {
-            AssertUnreachable();
-        }
+        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)) {
-            AssertUnreachable();
-        }
+        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)) {
-            AssertUnreachable();
-        }
+        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)) {
-            AssertUnreachable();
-        }
+        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);
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index a0553ddf20..e3760e0ab6 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/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
-        AssertUnreachable();
-    }
+    // 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);
> [fa97e3a](https://github.com/bitcoin/bitcoin/pull/36087/changes/fa97e3ab1c062723d2f110a5e6a0e664e4f37e1d) _refactor: Use AssertUnreachable() and remove dead code_: Same as in `InitWalletFlags`: it's weird to do `if not ... assert(false)`... <details> <summary>Assert the wallet results</summary> ```diff diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp index d917f6b2bb..66deb1c9bc 100644 --- a/src/wallet/scriptpubkeyman.cpp +++ b/src/wallet/scriptpubkeyman.cpp @@ -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)) { - AssertUnreachable(); - } + 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)) { - AssertUnreachable(); - } + 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)) { - AssertUnreachable(); - } + 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)) { - AssertUnreachable(); - } + 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); diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index a0553ddf20..e3760e0ab6 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/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 - AssertUnreachable(); - } + // 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); ``` </details>
l0rinc (Migrated from github.com) commented 2026-11-16 15:33:19 +00:00

fafb9c6 scripted-diff: Replace falsy assertions with AssertUnreachable:

Given the name suggests it's "unreachable", if we start handling it, it sounds like it's just "exceptional" ...
Writes can fail, so would an exception make more sense once the caller can restore the backup - wouldn't this get tangled up with https://github.com/bitcoin/bitcoin/pull/34193?

> [fafb9c6](https://github.com/bitcoin/bitcoin/pull/36087/changes/fafb9c61f7129eba000dfeece00050fda310960f) _scripted-diff: Replace falsy assertions with AssertUnreachable_: Given the name suggests it's "unreachable", if we start handling it, it sounds like it's just "exceptional" ... Writes can fail, so would an exception make more sense once the caller can restore the backup - wouldn't this get tangled up with https://github.com/bitcoin/bitcoin/pull/34193?
l0rinc (Migrated from github.com) commented 2026-11-16 15:31:40 +00:00

fa343ff test: Add assert_falsy linter, And use AssertUnreachable:

To avoid assume / AssumeUnreachable / assertUnreachable, we could use --perl-regexp (with \b instead, which also avoids native macOS Git silently missing \< - seems lint_includes_build_config already uses it) and list the methods instead of (ume|ert) hacks

Spell out the assertion names
diff --git a/test/lint/test_runner/src/lint_cpp.rs b/test/lint/test_runner/src/lint_cpp.rs
index d1c51891a9..668e4bfbd6 100644
--- a/test/lint/test_runner/src/lint_cpp.rs
+++ b/test/lint/test_runner/src/lint_cpp.rs
@@ -154,8 +154,8 @@ pub fn lint_rpc_assert() -> LintResult {
         .args([
             "grep",
             "--line-number",
-            "--extended-regexp",
-            r"\<(A|a)ss(ume|ert)(Unreachable)?\(",
+            "--perl-regexp",
+            r"\b(?:Assume|[aA]ssert|AssertUnreachable)\(",
             "--",
             "src/rpc/",
             "src/wallet/rpc*",
@@ -185,8 +185,8 @@ pub fn lint_assert_falsy() -> LintResult {
         .args([
             "grep",
             "--line-number",
-            "--extended-regexp",
-            r"\<(a|A)ssert\s*\(\s*(0|false)\s*(&&|\))",
+            "--perl-regexp",
+            r"\b[aA]ssert\s*\(\s*(0|false)\s*(&&|\))",
             "--",
             "src/",
             // Temporary exclusions, which are not linking the util lib:
> [fa343ff](https://github.com/bitcoin/bitcoin/pull/36087/changes/fa343ffd11115063ee958f98954ff192b6e4a6e6) _test: Add assert\_falsy linter, And use AssertUnreachable_: To avoid `assume` / `AssumeUnreachable` / `assertUnreachable`, we could use `--perl-regexp` (with `\b` instead, which also avoids native macOS Git silently missing `\<` - seems `lint_includes_build_config` already uses it) and list the methods instead of `(ume|ert)` hacks <details> <summary>Spell out the assertion names</summary> ```diff diff --git a/test/lint/test_runner/src/lint_cpp.rs b/test/lint/test_runner/src/lint_cpp.rs index d1c51891a9..668e4bfbd6 100644 --- a/test/lint/test_runner/src/lint_cpp.rs +++ b/test/lint/test_runner/src/lint_cpp.rs @@ -154,8 +154,8 @@ pub fn lint_rpc_assert() -> LintResult { .args([ "grep", "--line-number", - "--extended-regexp", - r"\<(A|a)ss(ume|ert)(Unreachable)?\(", + "--perl-regexp", + r"\b(?:Assume|[aA]ssert|AssertUnreachable)\(", "--", "src/rpc/", "src/wallet/rpc*", @@ -185,8 +185,8 @@ pub fn lint_assert_falsy() -> LintResult { .args([ "grep", "--line-number", - "--extended-regexp", - r"\<(a|A)ssert\s*\(\s*(0|false)\s*(&&|\))", + "--perl-regexp", + r"\b[aA]ssert\s*\(\s*(0|false)\s*(&&|\))", "--", "src/", // Temporary exclusions, which are not linking the util lib: ``` </details>
DrahtBot commented 2026-11-16 19:47:20 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
maflcko (Migrated from github.com) reviewed 2026-11-17 11:31:48 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:31:48 +00:00

Sure, happy to wait for the other pull first

Sure, happy to wait for the other pull first
maflcko (Migrated from github.com) reviewed 2026-11-17 11:31:52 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:31:52 +00:00

this is part of the scripted-diff, so not sure

this is part of the scripted-diff, so not sure
maflcko (Migrated from github.com) reviewed 2026-11-17 11:32:18 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:32:18 +00:00

All of this code will be deleted , so no need to rewrite it

All of this code will be deleted , so no need to rewrite it
DrahtBot commented 2026-11-17 11:32:21 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/44072951784/job/134003532996
LLM reason (✨ experimental): CI failed the scripted_diff lint check because the scripted replacement incorrectly removes #include <util/check.h> from src/memusage.h.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/44072951784/job/134003532996</sub> <sub>LLM reason (✨ experimental): CI failed the `scripted_diff` lint check because the scripted replacement incorrectly removes `#include <util/check.h>` from `src/memusage.h`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
maflcko (Migrated from github.com) reviewed 2026-11-17 11:32:28 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:32:28 +00:00

not sure

not sure
maflcko (Migrated from github.com) reviewed 2026-11-17 11:32:36 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:32:36 +00:00

I presume the log was intentional, so I'll leave as-is.

I presume the log was intentional, so I'll leave as-is.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:33:16 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:33:16 +00:00

this is not possible to do in a scripted-diff. Also, I am sure your diff is wrong, because there is no compiler checks on stuff like btck_LogLevel_ERROR.

this is not possible to do in a scripted-diff. Also, I am sure your diff is wrong, because there is no compiler checks on stuff like `btck_LogLevel_ERROR`.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:33:37 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:33:37 +00:00

I guess so, but I think this was written intentionally? I think I'll leave as-is for now.

I guess so, but I think this was written intentionally? I think I'll leave as-is for now.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:33:58 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:33:58 +00:00

thx, done

thx, done
maflcko (Migrated from github.com) reviewed 2026-11-17 11:34:22 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:34:22 +00:00

hmm, did something else in the first commit

hmm, did something else in the first commit
maflcko (Migrated from github.com) reviewed 2026-11-17 11:34:48 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:34:48 +00:00

thx, pushed something

thx, pushed something
maflcko (Migrated from github.com) reviewed 2026-11-17 11:35:06 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:35:06 +00:00

pushed my last suggestion

pushed my last suggestion
l0rinc (Migrated from github.com) reviewed 2026-11-17 11:35:08 +00:00
l0rinc (Migrated from github.com) commented 2026-11-17 11:35:09 +00:00

Not sure I understand what this means: if it's not 32 bits and not 64 bits, check that it's either 32 bits or 64 bits? We're already asserting that elsewhere, I don't think this is useful...

Not sure I understand what this means: if it's not 32 bits and not 64 bits, check that it's either 32 bits or 64 bits? We're already asserting that elsewhere, I don't think this is useful...
maflcko (Migrated from github.com) reviewed 2026-11-17 11:35:48 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:35:48 +00:00

Heh, didn't know that git doesn't bundle regex. Switched to perl regex

Heh, didn't know that git doesn't bundle regex. Switched to perl regex
maflcko (Migrated from github.com) reviewed 2026-11-17 11:35:57 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:35:57 +00:00

thx, done

thx, done
l0rinc (Migrated from github.com) reviewed 2026-11-17 11:36:02 +00:00
l0rinc (Migrated from github.com) commented 2026-11-17 11:36:02 +00:00

We could add the break in a previous commit.

We could add the break in a previous commit.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:36:11 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:36:11 +00:00

Sure, done

Sure, done
l0rinc (Migrated from github.com) reviewed 2026-11-17 11:38:51 +00:00
l0rinc (Migrated from github.com) commented 2026-11-17 11:38:51 +00:00

btck_LogLevel_ERROR - ah, so the missing comments are sometimes deliberate. Isn't that another reason to add them when they would be true?

`btck_LogLevel_ERROR` - ah, so the missing comments are sometimes deliberate. Isn't that another reason to add them when they would be true?
l0rinc (Migrated from github.com) reviewed 2026-11-17 11:40:22 +00:00
l0rinc (Migrated from github.com) commented 2026-11-17 11:40:22 +00:00

Isn't the error clearer saying that cmd is not getchainparams? Isn't the meaning the same as before? I don't insist, but seems simpler to me.

Isn't the error clearer saying that `cmd` is not `getchainparams`? Isn't the meaning the same as before? I don't insist, but seems simpler to me.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:41:27 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:41:27 +00:00

This will become static_assert(0) in C++23, which doesn't work in C++20 due to a language defect.

static_assert(0) is the compile-time equivalent of assert(0) at runtime, so I think it is useful.

Edit: Leaving this open, so I don't forget to follow-up with C++23 here.

This will become `static_assert(0)` in C++23, which doesn't work in C++20 due to a language defect. `static_assert(0)` is the compile-time equivalent of `assert(0)` at runtime, so I think it is useful. Edit: Leaving this open, so I don't forget to follow-up with C++23 here.
l0rinc (Migrated from github.com) reviewed 2026-11-17 11:43:15 +00:00
l0rinc (Migrated from github.com) commented 2026-11-17 11:43:15 +00:00

The proper fix here would be the removal of the incomplete 32 bit support anyway - please resolve the comment.

The proper fix here would be the removal of the incomplete 32 bit support anyway - please resolve the comment.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:44:36 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:44:36 +00:00

This makes it harder to add new commands in the future, because the diff would be more verbose

This makes it harder to add new commands in the future, because the diff would be more verbose
maflcko (Migrated from github.com) reviewed 2026-11-17 11:47:36 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:47:36 +00:00

Yeah, they should be added, but this pull is already a bit large, and there is no consistency enforcement anyway, so I am not sure if reviewers will be happy about such a commit.

Yeah, they should be added, but this pull is already a bit large, and there is no consistency enforcement anyway, so I am not sure if reviewers will be happy about such a commit.
maflcko (Migrated from github.com) reviewed 2026-11-17 11:48:36 +00:00
maflcko (Migrated from github.com) commented 2026-11-17 11:48:36 +00:00

Right, but I think an explicit marker is clearer than a break, so I think I'll leave this as-is for now.

Right, but I think an explicit marker is clearer than a break, so I think I'll leave this as-is for now.
l0rinc (Migrated from github.com) approved these changes 2026-11-17 13:26:18 +00:00
l0rinc (Migrated from github.com) left a comment

ACK fa9a4ddbaf

Nit: PR description needs update, AssertUnreachable doesn't call assertion_fail anymore.

ACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16 Nit: PR description needs update, `AssertUnreachable` doesn't call `assertion_fail` anymore.
hodlinator (Migrated from github.com) approved these changes 2026-11-18 16:06:09 +00:00
hodlinator (Migrated from github.com) left a comment

re-ACK fa9a4ddbaf

Changes since previous review (https://github.com/bitcoin/bitcoin/pull/36087#pullrequestreview-5919415158):

  • Added commit to move unreachable assert from runtime to compile time
  • Switched to explicit regexp dialect with broader compatibility
  • Avoided implying some asserts being non-fatal in linter diagnostic, thanks!
  • Fall-through in switch
  • Use of AssertUnreachable() over abort() to make unreachability explicit
  • Cleaner use of Assert(blah) over if (!blah) { AssertUnreachable(); }
  • More accurate motivation for excluding tinyformat, thanks!
re-ACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16 Changes since previous review (https://github.com/bitcoin/bitcoin/pull/36087#pullrequestreview-5919415158): * Added commit to move unreachable assert from runtime to compile time * Switched to explicit regexp dialect with broader compatibility * Avoided implying some asserts being non-fatal in linter diagnostic, thanks! * Fall-through in `switch` * Use of `AssertUnreachable()` over `abort()` to make unreachability explicit * Cleaner use of `Assert(blah)` over `if (!blah) { AssertUnreachable(); }` * More accurate motivation for excluding tinyformat, thanks!
jeanpablojp commented 2026-11-18 18:01:50 +00:00 (Migrated from github.com)

tACK fa9a4ddbaf

tACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16
ryanofsky (Migrated from github.com) approved these changes 2026-11-20 21:11:53 +00:00
ryanofsky (Migrated from github.com) left a comment

Code review ACK fa9a4ddbaf. Nice cleanup making code more consistent, and I like the clever approach to updating includes in the scripted-diff

Code review ACK fa9a4ddbaf16d7fc8f8c336600674b3c7facca16. Nice cleanup making code more consistent, and I like the clever approach to updating includes in the scripted-diff
Lines 375-377
ryanofsky (Migrated from github.com) commented 2026-11-20 20:37:26 +00:00

In commit "util: Add AssertUnreachable" (fa81e4700a)

This list of check helpers doesn't mention AssertUnreachable() or NONFATAL_UNREACHABLE(). Since the PR description gives the missing fatal counterpart to NONFATAL_UNREACHABLE() as one of the motivations, it could be worth adding a bullet after this one, something like:

* `AssertUnreachable()` should be used to mark code that can never be reached,
  for example after a `switch` that handles every enum value. Like `Assert`, it
  aborts if it is reached. `NONFATAL_UNREACHABLE()` is the counterpart for code
  where `CHECK_NONFATAL` would be used.
In commit "util: Add AssertUnreachable" (fa81e4700a9495b7216580da151f36674b5affde) This list of check helpers doesn't mention `AssertUnreachable()` or `NONFATAL_UNREACHABLE()`. Since the PR description gives the missing fatal counterpart to `NONFATAL_UNREACHABLE()` as one of the motivations, it could be worth adding a bullet after this one, something like: ```markdown * `AssertUnreachable()` should be used to mark code that can never be reached, for example after a `switch` that handles every enum value. Like `Assert`, it aborts if it is reached. `NONFATAL_UNREACHABLE()` is the counterpart for code where `CHECK_NONFATAL` would be used. ```
ryanofsky (Migrated from github.com) commented 2026-11-20 20:27:03 +00:00

re: https://github.com/bitcoin/bitcoin/pull/36087#discussion_r4599063726

This will become static_assert(0) in C++23, which doesn't work in C++20 due to a language defect.

Two things to know for the follow-up:

  • MallocUsage needs to be made into a function template for static_assert(false) to work. In a non-template function, a static_assert is checked in every branch, including discarded if constexpr branches, so it fires on every platform.
  • Since the change is a defect report (CWG2518, which includes P2593R1), it depends on the compiler version, not the language version. It already works with -std=c++20 on GCC 13 and our minimum Clang, so this can change as soon as we drop support for GCC 12.
re: https://github.com/bitcoin/bitcoin/pull/36087#discussion_r4599063726 > This will become `static_assert(0)` in C++23, which doesn't work in C++20 due to a language defect. Two things to know for the follow-up: - `MallocUsage` needs to be made into a function template for `static_assert(false)` to work. In a non-template function, a `static_assert` is checked in every branch, including discarded `if constexpr` branches, so it fires on every platform. - Since the change is a defect report ([CWG2518](https://cplusplus.github.io/CWG/issues/2518.html), which includes P2593R1), it depends on the compiler version, not the language version. It already works with `-std=c++20` on GCC 13 and our minimum Clang, so this can change as soon as we drop support for GCC 12.
maflcko (Migrated from github.com) reviewed 2026-11-23 14:02:58 +00:00
Lines 375-377
maflcko (Migrated from github.com) commented 2026-11-23 14:02:58 +00:00
thx, done in https://github.com/bitcoin/bitcoin/pull/36952
maflcko (Migrated from github.com) reviewed 2026-11-23 14:03:03 +00:00
maflcko (Migrated from github.com) commented 2026-11-23 14:03:03 +00:00
  • MallocUsage needs to be made into a function template for static_assert(false) to work.

Ok, I think I'll leave this as-is then. An alternative would be to append a short comment to this line:

        static_assert(sizeof(void*) == 4 || sizeof(void*) == 8); // Only 32-bit or 64-bit supported for now
> * `MallocUsage` needs to be made into a function template for `static_assert(false)` to work. Ok, I think I'll leave this as-is then. An alternative would be to append a short comment to this line: ```cpp static_assert(sizeof(void*) == 4 || sizeof(void*) == 8); // Only 32-bit or 64-bit supported for now
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36087
No description provided.