maflcko
commented at 4:58 pm on February 5, 2026:
member
Legacy code often used a function signature of the form bool Get...(const& in, mut& in_out); to implement a getter that optionally returns a value.
In modern code, this can be replaced by std::optional<_> Get...(const& in);.
However, some legacy code remains. To ensure that the “imaginary optional” is not unwrapped when the getter returns false, add a C++17 [[nodiscard]] attribute to all those legacy functions.
There were only a few places that ignored the return value. I’ve fixed them in separate commits.
This should be easy to review via --word-diff-regex=. and then confirming that the attribute was added to such a getter.
refactor: Add [[nodiscard]] to GetOp/GetScriptOp
Also, use the return value in the test. Otherwise, compilation warns:
src/test/transaction_tests.cpp:906:9: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
906 | t.vin[0].scriptSig.GetOp(pc, opcode); // advance to next op
| ^~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~
1 warning generated.
fa3a40a4a8
refactor: Add [[nodiscard]] to GetCachedLastHardenedExtPubKey
Also, mark the return value as unused in one place, which is checked in
the line after. This avoids a compile warning:
src/script/descriptor.cpp:552:13: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
552 | cache->GetCachedLastHardenedExtPubKey(m_expr_index, xpub);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~
1 warning generated.
fa18a0c2d9
DrahtBot renamed this:
refactor: Add [[nodiscard]] to functions returning bool+mutable ref
refactor: Add [[nodiscard]] to functions returning bool+mutable ref
on Feb 5, 2026
DrahtBot added the label
Refactoring
on Feb 5, 2026
DrahtBot
commented at 4:58 pm on February 5, 2026:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviews
See the guideline for information on the review process.
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.
refactor: Add [[nodiscard]] to GetProxy
Also, refactor the rpc code to check the return value (which is
identical to proxy.IsValid()). Otherwise, the compiler would warn:
src/rpc/net.cpp:622:9: warning: ignoring return value of function declared with 'nodiscard' attribute [-Wunused-result]
622 | GetProxy(network, proxy);
| ^~~~~~~~ ~~~~~~~~~~~~~~
1 warning generated.
fa17ce6465
maflcko force-pushed
on Feb 5, 2026
HowHsu
commented at 11:15 am on February 6, 2026:
none
ACKfac5685
yuvicc
commented at 6:17 am on February 18, 2026:
contributor
ACKfac5685e867b4a9ec334ed1ee31aabacd1c3124e
sedited
commented at 11:16 am on February 25, 2026:
contributor
Concept ACK
This looks like a good thing to add, but I wonder if handling these cases incrementally is the correct approach. Outside of these “getter” functions there are so many cases where adding [[nodiscard]] make sense too. There is modernize-use-nodiscard, but that is too noisy. An alternative might be to roll our own clang tidy plugin that checks for bool return + mutable ref or pointer argument.
Do you also want to add these couple of cases (also added one that takes a mutable pointer):
refactor: Add [[nodiscard]] to functions returning bool+mutable reffa4db474a8
maflcko force-pushed
on Feb 26, 2026
DrahtBot added the label
CI failed
on Feb 26, 2026
maflcko
commented at 1:36 pm on February 26, 2026:
member
This looks like a good thing to add, but I wonder if handling these cases incrementally is the correct approach.
I wondered that, too. The patch here was written in 2018, but fell off the table. While I rebased it, some places where transformed to std::optional (which should be used in a few more places instead of nodiscard).
Outside of these “getter” functions there are so many cases where adding [[nodiscard]] make sense too.
Are there? I think the attribute should only be used where it really makes sense.
modernize-use-nodiscard
I think this will do the exact opposite of what we want: It ignores functions that have a mutable ref param. It only adds it to functions that don’t really need it in the first place.
Happy to take a look at writing a clang-tidy plugin, maybe as a follow-up?
dbwrapper.h
I’ve also seen this one, but left it for a follow-up, because it is not trivial to see if and why (void) would be the correct fix here. I wanted to keep this pull focussed on mostly mechanical changes for now.
getAddressData
Thx, done
DrahtBot removed the label
CI failed
on Feb 26, 2026
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-03-04 00:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me