-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: return std::nullopt instead of {} #21498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In bitcoin#21415 we decided to return `std::optional` rather than `{}` for uninitialized values. This PR repalces the two remaining usages of `{}` with `std::nullopt`. As a side-effect, this also quells the spurious GCC 10.2.x warning that we've had reported quite a few times. i.e bitcoin#21318, bitcoin#21248, bitcoin#20797. ```bash txmempool.cpp: In member function ‘CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>&) const’: txmempool.cpp:898:13: warning: ‘<anonymous>’ may be used uninitialized in this function [-Wmaybe-uninitialized] 898 | return {}; | ^ ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 5294f0d, I have reviewed the code and it looks OK, I agree it can be merged.
Posthumous ACK |
Looks like gcc-11 fixed the bug. I couldn't reproduce the warning before and after this patch. |
This seems completely pointless unless you're going to update the style guide to say that we shouldn't use |
This was worthwhile just to stop the flow of GCC false positive reports. GCC 10.2 wont be going anywhere for a long time. |
I think that's a slightly better motivation than "we decided to return std::optional rather than {}" |
5294f0d refactor: return std::nullopt instead of {} (fanquake) Pull request description: In bitcoin#21415 [we decided](bitcoin#21415 (comment)) to return `std::optional` rather than `{}` for uninitialized values. This PR replaces the two remaining usages of `{}` with `std::nullopt`. As a side-effect, this also quells the spurious GCC 10.2.x warning that we've had reported quite a few times. i.e bitcoin#21318, bitcoin#21248, bitcoin#20797. ```bash txmempool.cpp: In member function ‘CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>&) const’: txmempool.cpp:898:13: warning: ‘<anonymous>’ may be used uninitialized in this function [-Wmaybe-uninitialized] 898 | return {}; | ^ ``` ACKs for top commit: hebasto: ACK 5294f0d, I have reviewed the code and it looks OK, I agree it can be merged. Tree-SHA512: 5b776be79ab26e5a3a5fc2b463b394ea5ce6797ed5558424873fa4ecee2898170eff76d6da9d69394d28f8f98974117fc63b922a3e19c52f5294c83073e79bb0
Summary: This is a backport of [[bitcoin/bitcoin#21498 | core#21498]] Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D11305
In #21415 we decided to return
std::optional
rather than{}
foruninitialized values. This PR replaces the two remaining usages of
{}
with
std::nullopt
.As a side-effect, this also quells the spurious GCC 10.2.x warning that
we've had reported quite a few times. i.e #21318, #21248, #20797.