Skip to content

Conversation

fanquake
Copy link
Member

@fanquake fanquake commented Mar 22, 2021

In #21415 we decided 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 #21318, #21248, #20797.

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 {};
      |             ^

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 {};
      |             ^
```
Copy link
Member

@hebasto hebasto left a 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.

@maflcko maflcko merged commit 786654a into bitcoin:master Mar 22, 2021
@fanquake fanquake deleted the return_std_nullopt branch March 22, 2021 05:43
@jonatack
Copy link
Member

Posthumous ACK

@maflcko
Copy link
Member

maflcko commented Mar 22, 2021

Looks like gcc-11 fixed the bug. I couldn't reproduce the warning before and after this patch.

@jnewbery
Copy link
Contributor

This seems completely pointless unless you're going to update the style guide to say that we shouldn't use return {} to return a default-initialized object (which I don't think we should do - there's absolutely nothing wrong with that style and it's used in many places in the code).

@fanquake
Copy link
Member Author

This seems completely pointless unless

This was worthwhile just to stop the flow of GCC false positive reports. GCC 10.2 wont be going anywhere for a long time.

@jnewbery
Copy link
Contributor

This was worthwhile just to stop the flow of GCC false positive reports.

I think that's a slightly better motivation than "we decided to return std::optional rather than {}"

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 22, 2021
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
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 6, 2022
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants