net: Simplify `AddressPosition` comparitor #35770

pull rustaceanrob wants to merge 1 commits into bitcoin:master from rustaceanrob:26-7-21-addrpos-const changing 1 files +1 −5
  1. rustaceanrob commented at 9:48 AM on July 22, 2026: member

    Picked from #35713 because this appears unintentional. There were no cases where the source attempted to compare AddressPosition by const reference, but such a comparison is valid. This may be fixed by simplifying the comparison operator here, which also avoids copying the value.

    Found in #35713:

    <AddressPosition>' requested here
      817 |     BOOST_CHECK(addr_pos1 == addr_pos2);
          |                           ^
    /bitcoin-core/bitcoin/src/addrman.h:76:10: note: candidate function not viable: 'this' argument has type 'const AddressPosition', but method is not marked const
       76 |     bool operator==(AddressPosition other) {
    
  2. DrahtBot added the label P2P on Jul 22, 2026
  3. DrahtBot commented at 9:48 AM on July 22, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35770.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK maflcko, sedited

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. sedited approved
  5. sedited commented at 11:14 AM on July 22, 2026: contributor

    ACK 1534e9fb83b5291f27bd16fdf447dd8069537662

  6. net: Simplify `AddressPosition` comparitor
    There were no cases where the source attempted to compare
    `AddressPosition` by const reference, but such a comparison is valid.
    This may be fixed by simplifying the comparison operator here, which
    also avoids copying the value.
    
    Found in #35713:
    ```
    <AddressPosition>' requested here
      817 |     BOOST_CHECK(addr_pos1 == addr_pos2);
          |                           ^
    /bitcoin-core/bitcoin/src/addrman.h:76:10: note: candidate function not viable: 'this' argument has type 'const AddressPosition', but method is not marked const
       76 |     bool operator==(AddressPosition other) {
    ```
    075e7f4218
  7. in src/addrman.h:76 in 1534e9fb83
      72 | @@ -73,7 +73,7 @@ struct AddressPosition {
      73 |      const int bucket;
      74 |      const int position;
      75 |  
      76 | -    bool operator==(AddressPosition other) {
      77 | +    bool operator==(AddressPosition other) const noexcept {
    


    maflcko commented at 12:14 PM on July 22, 2026:

    Why create a copy when only read-only access is needed?

    This should probably be const&, also clang-format for touched code.

    or it can be:

        bool operator==(const AddressPosition&) const = default;
    

    rustaceanrob commented at 12:56 PM on July 22, 2026:

    Because no one ran into this error before, I was wondering if there was a particular reason a copy was used here. If there is none, then yes it should just be const&. std::tie also seems unnecessary, so I will take your suggestion.

  8. rustaceanrob force-pushed on Jul 22, 2026
  9. maflcko commented at 1:09 PM on July 22, 2026: member

    lgtm ACK 075e7f421876f9b4eeffa2977abc50708831844c

  10. DrahtBot requested review from sedited on Jul 22, 2026
  11. sedited approved
  12. sedited commented at 1:10 PM on July 22, 2026: contributor

    Re-ACK 075e7f421876f9b4eeffa2977abc50708831844c

  13. rustaceanrob renamed this:
    net: Make `AddressPosition` comparitor `const noexcept`
    net: Simplify `AddressPosition` comparitor
    on Jul 22, 2026
  14. fanquake merged this on Jul 22, 2026
  15. fanquake closed this on Jul 22, 2026

  16. Kino1994 referenced this in commit a310de88bf on Jul 26, 2026
  17. Kino1994 referenced this in commit d1ac91094a on Aug 19, 2026
  18. rustaceanrob deleted the branch on Aug 20, 2026

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: 2026-08-24 09:51 UTC

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