mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:44:38 +00:00
util: Add util::NotNull<SmartPtrType> #34844
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!34844
Loading…
Reference in a new issue
No description provided.
Delete branch "2603-not-null"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The C++ standard library lacks a type to denote a smart pointer is not null. For raw pointer there is
std::reference_wrapper, or a plain reference.Other third-party libraries provide such a type, such as
gsl::strict_not_null.Fix all issues by adding
util::NotNull<SmartPtrType>, which documents (and checks) that the inner pointer is never null.This type can be used when passing never-null smart pointers between functions. It removes the need to
Assert()the pointer before dereference. For example, in a getter function:Fixes https://github.com/bitcoin/bitcoin/issues/24423
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.
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:
-addnodestartup values by w0xlt)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.
LLM Linter (✨ experimental)
Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):StageAddition(tx1_conflict, tx1_fee, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“It doesn't improve itself”)StageAddition(tx1_conflict, tx1_fee + 1, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“With one more satoshi it does”)StageAddition(tx1_conflict, tx1_fee + 1, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“With prioritisation of in-mempool conflicts”)StageAddition(tx1_conflict, tx1_fee, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“With fewer vbytes it does”)StageAddition(entry4.GetSharedTx(), tx2_fee, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“With fewer vbytes it does”)StageAddition(tx1_conflict, tx1_fee, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“Adding a grandchild makes the cluster size 3”)StageAddition(entry4.GetSharedTx(), tx2_fee + entry5->GetModifiedFee() + 1, 0, 1, 0, false, 4, LockPoints())insrc/test/rbf_tests.cpp(“Adding a grandchild makes the cluster size 3”)2026-10-06 12:27:38
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/23213194537/job/67467180922LLM reason (✨ experimental): Build failed during the cmake build, due to a compilation error in src/test/util_pointers_tests.cpp.
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.
Concept ACK
Looks like C++20 CTAD alias templates are not supported with clang-18, so I replaced this one-liner with a more verbose alternative in the last force push.
Probably not going to push here, but another place where this would be suitable is
GetWalletForJSONRPCRequestEdit: diff in https://github.com/bitcoin/bitcoin/pull/34844#discussion_r3305943200
Other suggested diffs: https://github.com/bitcoin/bitcoin/pull/34844#discussion_r3293173669
edit: or even https://www.github.com/bitcoin/bitcoin/pull/35569#issuecomment-4835740603
edit: or add annotations/attributes, see https://github.com/bitcoin/bitcoin/pull/34844#discussion_r3702941931
Removed the movable feature of NotNull for now, which can be added/reviewed later
edit: added this back again
Concept ACK, I think this could help in a few cases where the pointer-like type is part of the contract and a plain reference would not preserve the ownership/storage semantics.
This also feels aligned with ongoing efforts like https://github.com/bitcoin/bitcoin/pull/35229 (cc: @optout21).
The part that bothers me most is that
util::NotNull<std::unique_ptr<T>>does not quite feel like a first-class type yet. The construction and call sites are fairly verbose, which makes the stronger invariant harder to adopt/read. I left a few suggestions around making common smart-pointer usage more compact, adding a few assertions/tests so the API is less surprising, and pointing out a few other places where this pattern may fit.Could we avoid repeating the verbose template instantiation for all non-null smart pointers? I like the extra guarantee, but I don't like how verbose the results are.
We could add
NotNullUniquePtrandNotNullSharedPtraliases and demo them at the mentioned call sites:Another similar one is
BlockTemplateImpl, it could even simplify passing it as reference:And a few other ones that we're already treating as non-null implicitly: their constructors initialize
m_implwithstd::make_unique, and the members are const, so the pointer cannot later be reset or reassigned:This extra verbosity is a bit of a turn-off. Can we add a forwarding constructor for class-type pointer wrappers (diff assumes the previous
NotNullUniquePtrsuggestion)?Which obviously begs the question: do we ever want to convert back.
Given your hint for converting GetWalletForJSONRPCRequest it may be necessary (unless we propagate the type further), but I agree with you that this could also be done in a followup.
Migrate `GetWalletForJSONRPCRequest` to `util::NotNullSharedPtr`
Could the first commit stay closer to the imported GSL header, with Bitcoin-specific changes applied in follow-up commits?
We could even cherry-pick it and add the above
curlreproducer as a scripted diff if you want to push the boundaries of #35275 :DNit, we could make this explicit to avoid warnings:
nit: This failure reason is a bit hard to read:
ptr_ != nullptris the invariant that failed, so this test is actually checking the null case. In other words, the message prints the failed condition, not the observed value. Likely not something we can fix here...The
noexceptannotations are a bit confusing since that's exactly how we're testing the methods -check_nullptrworks because it deliberately avoids thenoexceptpath.I understand that
test_only_CheckFailuresAreExceptionsNotAbortsisn't used in prod and we don't like modifying prod for tests, but we do have a failure case inside and I'm just not sure what happens if we are explicit about not throwing while deliberately relying on throwing behavior (currently this terminates before the test can observeNonFatalCheckError. Maybe that is acceptable for production, but it makes the main smart-pointer null checks harder to test).This way we can't test for example:
it just fails with
But without the
noexceptthe above passes:NotNullUniquePtrcan look move-constructible to traits even though actual move construction fails.I understand if we keep this, but could we avoid exposing move construction for
util::NotNull?Explicitly deleting move construction/assignment in the public
util::NotNullwrapper would make the API surface match the intended contract more directly.Seeing the comments in e.g. https://github.com/bitcoin/bitcoin/issues/24423#issuecomment-1048795957, maybe we could document when this is preferred over other solutions, e.g. that ordinary references remain preferred for simple non-owning access.
Thx for the review. I pushed some changes and replied to all comments.
Ah, right. Though, my preference would be to make all
NotNullconstructor calls explicit, as they serve as a drop-in replacement forAssert. Also, one could consider makingNotNullmovable and then construct it at the call site here.Nice. Happy to push such a commit. Though, if we use it for m_impl, it should be used in all places in the codebase. E.g. the following is missing from your diff:
src/musig.h: std::unique_ptr<MuSig2SecNonceImpl> m_impl;const std::unique_ptr<TxDownloadManagerImpl> m_impl;If you send a full diff, I can include it here ( Let me know if you want to be listed as co-author in any commits). Or you can push a branch to your liking to your repo, and I can take it as-is.
Thx, but I think the diff is not quite right:
return util::NotNull{pwallet};The correct diff would be:
a diff
However, this raises the concern that thread-safety annotations will be broken by this.
I guess this makes sense, as clang can not figure out that the
operator->returns the same smart wallet pointer every time it is called. So I guess my above diff is still incomplete and would likely require a change to first assign a wallet reference:thx, done
Turned into compile-time test instead.
Sure, but this is just how it works on master. E.g. in a release build with an injected bug:
->
getchaintxstats<-
Happy to review a pull request changing/improving that (e.g. by appending
"failed"), but it seems unrelated to the changes here.Is this still relevant after the last push?
Heh, good point, but I think I'd like to go the other way and make it moveable. I have a commit for this, but removed it, see https://github.com/bitcoin/bitcoin/pull/34844#issuecomment-4290176661. Move semantics can be done in a later commit/pull request.
edit: If we wait long enough, C++29 or later may ship with trivial reloc (or similar), which makes this safer to implement from a static analysis perspective 😅
thx, added a doxygen comment here.
thx, done
ACK fae0a346c1ea2c96160448f660b37749d695265e
Remaining nits aren't critical, we can do them in follow-ups.
Seems simple enough to do here or in a follow-up, it's not a blocker from me.
I usually add coauthors when their comments triggered a change that makes the PR better.
This still seems like something we could still assert for safety, i.e. that raw pointers do not implicitly convert to
util::NotNull.The verbosity still bothers me, but every other workaround I found was too complicated - we can simplify in a followup, if needed.
I know, it's why I wrote:
Can be resolved, thanks
Could we maybe document that it's not movable yet and remove it when it becomes movable? It's not intuitive what should happen in case of a move.
Proposed improvement for this: #35461
I pushed a doc-only update for now, but let me write a longer reply here in the future ...
untested diff review ACK 6389aa8f15aa4ed55d76afda36c0b1c870f1c9d0reACK
Mostly whitespace and formatting and comment changes since last review.
Changes since my last ack
Long answer:
Correct, but this is harmless, because actual move-construction will correctly fail at compile time. So the only difference here is a cleaner error message.
Looking at your diff, you seem to be
=deleteing the move ctor. This is fine, because it changes the compile error message to something more explicit. Also, the comment above the=deletehas some rationale and recommended workarounds.However, personally, I'd rather move toward making it movable (https://github.com/bitcoin/bitcoin/pull/34844#issuecomment-4290176661) instead of adding code that will be removed anyway when the switch is done. I already have the commit for this and I am happy to push it. At this point, it may be easier to just review one final state (movable) instead of two states?
This should be true for all pointer types, because the constructors are intentionally marked
explicit. The rationale is that the constructor acts like anAssert(and callsAssert).Also, raw pointers should just use reference_wrapper, not this class. Happy to add checks for smart pointer types, if you want.
So this is intentional and shouldn't be changed in the future 😅
Added a unit test to document this, and the recommended workaround of taking a reference while holding the lock.
I'm fine with both - though I'm still not sure how move can be done safely with non-null source.
lightly tested diff review ACK fa951b422c43d7a3b51aaefbaf25f3d9d53e1a69
I guess this thread can be resolved? The only remaining thing could be to apply the diff (https://github.com/bitcoin/bitcoin/pull/34844#discussion_r3305943200) in the future?
It can't be done safely in the language itself (unless C++29 gets trivial reloc or so). However, with clang-tidy use-after-move, this should be safe.
So I went ahead and pushed the move commmits.
Heh, I never know when to include or not include. I guess I just try to preserve whoever wrote the bulk of the commit initially.
I guess I can close this thread and the diffs can be submitted later?
Concept ACK
(closing this thread, based on the thumbs-up)
The new move changes are a bit surprising to me at first glance, but I'll circle back to this later, unless you think it's urgent.
🐙 This pull request conflicts with the target branch and needs rebase.
rebased and added a commit
I'm not sure using gsl as a base makes sense for us. It seems very unlikely that this will ever be standardized, and we're already customizing it here quite a bit already. It seems like we don't care about the
strict_not_nullvsnot_nullseparation, so we might as well avoid the complexity altogether?I prototyped one such approach with claude (may still be missing edge cases etc, but overall looks pretty complete to me):
github.com/stickies-v/bitcoin@3c10a9588eimplements from scratch, with a much smaller diff. Slightly different behaviour, e.g.get()doesn't have thevalue_or_reference_return_toptimization, but since we don't want this to be used for raw pointers I think that's okay?github.com/stickies-v/bitcoin@5a99e4461athen goes a step further and prevents raw pointers from being used, since we can be as opinionated as we like on our own types.(note: not sure if we should/need to better attribute gsl, i just removed the copyright notice for now as it's a rewrite)
if we use the public interface here, we can skip the friend class (, and it might (not sure) help with some use-after-move detection by marking
otheras moved, instead of just itsptr_?)git diff on fa53bbcb11
It's not ideal (but I think the best choice out of the options) that this class relies on clang-tidy for its safe usage wrt
use-after-move. I think one easy and free (in release) belt-and-suspenders check we can add is toAssumethe invariant where we can?git diff on fa53bbcb11
🐙 This pull request conflicts with the target branch and needs rebase.
Yeah, I liked the gsl header-only version and was hoping it is battle-tested, but given that (1) I had to fix-up some
noexecptedge-cases upstream, (2) we are making it movable, (3) we likely want to easily and freely fix it up ourselves, (4) the code should be easy to read in one go, and not as a patch on top of something else, it makes sense to just write a minimal, clean, and C++20 impl ourselves.So I went over all lines in your branch, applied some small test fixups, and then pushed it here. Added you as co-author, as you pushed the commit/diff, but let me know if you prefer to be dropped as co-author.
thx, added
AssumeI think
otheris already moved, so it shouldn't change any detection. But I pushed your branch, so this is now included.🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/29573818713/job/87863590921LLM reason (✨ experimental): CI failed because
ctestreportedutil_pointers_testsaborting on an assertion failure inutil/pointers.h:73(NotNull<NoCopyPtr>::get).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.
🐙 This pull request conflicts with the target branch and needs rebase.
Approach ACK, code lgtm fa0227405c497e94ddb7a7603b37993a7703c0c1 but the forwarding ctor issue should probably be fixed, nothing else blocking
fa27f2e49fe6875769477f536735607c55140e16 nit: why not do this in the previous commit right away?
It increases the diff, but I think using scopes here would be the better choice, instead of documenting how to abuse
NotNull.nit: iiuc
use-after-movestatic analysis does not catch everything, so perhaps "can never be observed" is misleading / too strong.For a non-const lvalue
NotNull<T>under direct-init, the forwarding ctor is selected instead of the copy ctor.git diff on fa0227405c
nit: could do with some
LIFETIMEBOUND:git diff on fa0227405c
nit:
swapis currently unused, might make sense to add if/when we need it?nit: I think we typically implement these as member functions
git diff on fa0227405c
Sure, but there can't be an issue?
operator Tcreates a copy, just like.get()creates a copy. And any compiler failure before will remain a compile failure after?I guess you are mostly worried about this style-wise and for trait stuff like:
std::is_constructible_v<NotNullUniquePtr<int>, NotNullUniquePtr<int>&>?thx, done for all references
thx,
s/can never/should never/Yeah, that is also less code and a cleaner. Thx, done.
thx, squashed the two commits
Hmm, I guess move is noexcept for the smart pointers we care about, so we can just use the default swap fallback and let the compiler optimize down to the same binary.
Removed.
thx, done
Sorry, should have stated why I raised this. My main concern was the ambiguity this creates, i.e.
NotNull<std::shared_ptr<int>> u{t};andNotNull<std::shared_ptr<int>> u = t;use different constructors, with the former adding an extraAssert. Indeed this shouldn't lead to any issues, except for when we're dealing with a moved-from object (which shouldn't be possible, but is not guaranteed), in which case they will have different behaviour. I think it's prudent to prevent this from happening.I also assumed the copy constructor would be more performant, but thinking about it again I suppose the difference is negligible, with just the (very) minimal runtime
Assertoverhead.Ok, the additional assert makes sense. My eyes didn't see that, and I guess compilers won't optimize it away either, unless there are annotations on the getter/opT(), see https://github.com/bitcoin/bitcoin/issues/24423#issuecomment-4079986901
In any case, I've applied your diff, so this should be fixed.
ACK
fa0e12e77bACK
fa0e12e77bThere are a few other pimpls that could get this treatment. How did you select the current ones?
Might it be preferable to return
There instead ofT&&and have it construct the value directly? That would get rid of theLIFETIMEBOUND, no?Should this noexcept be conditional?
Sure, there could be an extra move in some cases, but removing the need for
LIFETIMEBOUNDseems also ok.Sure, it could be. However, it doesn't make a difference for uniq ptr and shared ptr. It could only make a difference for pointer types whose copy-ctor may throw, like https://www.boost.org/doc/libs/latest/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr
I don't think this is ever needed, but I pushed it.
I didn't want to explode this pull with boring mechanical changes. There are a bunch of ideas for later in comment https://github.com/bitcoin/bitcoin/pull/34844#issuecomment-4267662343, and changing the boring pimpls could be done as well.
ACK
5555d39c68Forgot to mention to mention this before, but why not call the new file
not_null.h?re-ACK
5555d39c68I was going to leave the same suggestion in my previous review cycle until I noticed I already used up my nit budget. Would prefer that too.
ACK
5555d39c68The results are quite simple now, remaining comments are nits (doc wording, alias, test dedup, an over-advertised converting-constructor constraint) and can be follow-ups given how long this one's been open. The
explicitconversion suggestion touches validation.cpp, so I'm fine deferring that one as well.nit: developer-notes accepts both, but the rest of this file uses
//!NotNullonly compares with anotherNotNull, sonullptris rejected even without the deleted constructor. Could the comment say that instead?What's the purpose of this test case? Isn't it basically the same as the one below?
Nit:
I read this a few times, maybe:
or simply
My understanding is that
clang-tidy’sbugprone-use-after-moveonly checks local variables and function parameters, but misses moves from members and globals.And
Assumeis only triggered in debug and fuzz builds - and since we canot haveAssert- we should probably update the doc.The constraint checks an rvalue
U, but the body converts aconst U&, so they don't match:Same for the lvalue
operator T() const&, which lacks therequiresandnoexceptits rvalue twin has.tests to constrain pointer copies
nit: Corecheck thinks these should be
explicitmake pointer extraction explicit
Is my understanding correct that the
constexpris only applicable after C++23 - and that it's still fine in C++20, just a noop?nit: a bit confusing that this copies while
get() const&returns a reference, maybe worth a short comment on why.Nit: I like spaceships 🚀. You don't like spaceships? 🚀
I think my shorter comment is clearer, so leaving as-is for now.
Right, but nullptr deref later on will be UB (usually a crash), which is caught by tests. If someone manages to trick clang-tidy, and reviewers, while not writing tests, one of the red teams will hopefully come to the rescue.
Thx, fixed up some of the
explicit,requires, andnoexcepta bit.Added you as co-author for the small nits here. Hope that is fine.
I think the constexpr should work in C++20 as well for hand-written smart pointer types. Though, I can't see a use-case for it, because UB is not allowed at compile-time, so there is no need for NotNull at compile-time.
sure, done
thx, removed the one below.
sure, done
This is only about raw pointers or raw integral types (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c164-avoid-implicit-conversion-operators), so doesn't apply here?
I think it is clear that
operator T()copies, so I'll leave as-is for now.Sure, it could be changed, but I like it as a hint:
so I'll leave as-is for now.
🚧 At least one of the CI tasks failed.
Task
lint: https://github.com/bitcoin/bitcoin/actions/runs/35712238912/job/106695317694LLM reason (✨ experimental): CI failed because the
lint-include-guardscheck reported thatsrc/util/not_null.his missing the expected include guard.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.
Re-ACK
33333abbaaACK
33333abbaaLeft some non-blocking nits in case the author decided to push again.
nit: we could harden these by consting some of the new migrated values
nit: now that
not_null.hwas renamed, consider applying that to the test file as well:If you need to touch again, consider adding a test for this
Assertwith a null smart pointer.Constructing
NotNullSharedPtr<int>from a nullunique_ptr<int>is notnoexcept, so the existing exception test hook can observe the failure.C.164 seems broader to me, but I'm fine either way
Yeah, I am happy to push the change, if there is a reason in this case. Maybe a reason is found in the future, but right now I don't see one. Resolving for now.
force pushed (trivial) to address the two test nits.
edit: force pushed to address two Ralph Review nits: Reject references, and add an Assume to catch weird edge-case ptr classes that may convert to nullptr.
Base:
acaf322fc438e6bd180b23189a5661c8f02d88fbHead:
fa42e2868414544503dcd9ae4bd74c911fedee80🟡 Minor
Cross-type conversion can leave NotNull holding null (src/util/not_null.h:61, head)
The cross-type constructors require only that the target be constructible from the source; they do not require the conversion to preserve non-nullness. For an admitted pointer-like type whose non-null source converts to a target that compares equal to nullptr, Assume does not prevent the resulting NotNull from holding null in ordinary non-checking builds, defeating the wrapper's guarantee. Current production conversions use standard shared_ptr and unique_ptr types, which preserve non-nullness; no production caller that produces a nulling conversion was identified, so production impact is unconfirmed. Enforce the converted-value invariant or constrain cross-type conversions to conversions that preserve non-nullness.
noexcept constructor can prevent observing check failure (src/util/not_null.h:49, head)
For
NotNullSharedPtr<int>{std::shared_ptr<int>{}}, constructing the underlying shared_ptr is noexcept, so this constructor is noexcept even though a failed Assert calls assertion_fail, which throws NonFatalCheckError when the test-only check-failure hook is enabled. The throw therefore terminates instead of being caught by the test. The added null-pointer test uses a unique_ptr-to-shared_ptr conversion, whose construction can throw, and does not cover this same-type case. Remove the noexcept guarantee or otherwise preserve the hook's behavior, and test same-type null construction. No current test uses that path.💡 Suggestion
Clarify when Assume checks the condition (src/util/not_null.h:41, head)
Assume checks the condition only during constant evaluation or when G_ABORT_ON_FAILED_ASSUME is enabled; otherwise, it returns the value unchanged. Moving a NotNull can empty its smart pointer, so clarify that this check is build-dependent and safe access otherwise relies on avoiding use-after-move and on configured static analysis. No moved-from dereference in the converted production callers was identified.
Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial_glm review did not complete.
Full review report
thx, added
Is there a benefit? I mean none of the other fields are const and this could create the false impression when glancing over the code that the object it points to is const. Leaving as-is for now.
thx, done
This seems related to the Windows failure
Thx, excluded MSVC for now. It is buggy and unsupported, see https://github.com/bitcoin/bitcoin/issues/36153.
quick diff review ACK
fa42e28684Re-ACK
fa42e28684re-ACK
fa42e28684nit: could add a positive test to show the test works
nit: the converting move ctor accepts explicit-only conversions (
constructible_from+explicit(...)), but this converting copy ctor does not. Should they be consistent?This looks rfm to me. @maflcko do you want to address/take the remaining nits?
Sure, maybe in the next pull?
I think it is fine to have implicit conversions, like the one in the
check_derivedtest:q = p;If you want I can also add a compile time check for the implicit move conversion and the implicit copy/assignment:
I can also add a
explicit(!std::convertible_to<const U&, T>)orexplicit(false), but they seemed a bit redundant with therequires std::convertible_to<const U&, T>. No strong opinion whichof the three styles to prefer, but they should all be the same.I personally would prefer merging and addressing the leftovers in follow-ups - the PR has been open for a while.
The actual usages need to be migrated, so follow-ups will come.
All the small fixups are in https://github.com/bitcoin/bitcoin/pull/36451. The larger ones are left for later:
GetWalletForJSONRPCRequest, ref https://github.com/bitcoin/bitcoin/pull/34844#discussion_r3305943200CTransaction, ref https://github.com/bitcoin/bitcoin/pull/35569#issuecomment-4835740603Added in
faf85b0321