refactor: return std::nullopt instead of {} #21498

pull fanquake wants to merge 1 commits into bitcoin:master from fanquake:return_std_nullopt changing 2 files +2 −2
  1. fanquake commented at 3:28 am on March 22, 2021: member

    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.

    0txmempool.cpp: In member function ‘CTxMemPool::setEntries CTxMemPool::GetIterSet(const std::set<uint256>&) const’:
    1txmempool.cpp:898:13: warning: ‘<anonymous>’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    2  898 |     return {};
    3      |             ^
    
  2. refactor: return std::nullopt instead of {}
    In #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 #21318, #21248, #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 {};
          |             ^
    ```
    5294f0d5a9
  3. fanquake added the label Refactoring on Mar 22, 2021
  4. hebasto approved
  5. hebasto commented at 3:53 am on March 22, 2021: member
    ACK 5294f0d5a94cc7beaf692131fba0cad8beec9f13, I have reviewed the code and it looks OK, I agree it can be merged.
  6. MarcoFalke merged this on Mar 22, 2021
  7. MarcoFalke closed this on Mar 22, 2021

  8. fanquake deleted the branch on Mar 22, 2021
  9. jonatack commented at 7:05 am on March 22, 2021: member
    Posthumous ACK
  10. MarcoFalke commented at 7:11 am on March 22, 2021: member
    Looks like gcc-11 fixed the bug. I couldn’t reproduce the warning before and after this patch.
  11. jnewbery commented at 9:07 am on March 22, 2021: member
    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).
  12. fanquake commented at 9:09 am on March 22, 2021: member

    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.

  13. jnewbery commented at 9:33 am on March 22, 2021: member

    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 {}”

  14. sidhujag referenced this in commit 9f12fb3d2e on Mar 22, 2021
  15. deadalnix referenced this in commit 078ea74aa1 on Apr 6, 2022
  16. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

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: 2024-10-04 19:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me