refactor: enable readability-container-contains clang-tidy rule #34095

pull l0rinc wants to merge 2 commits into bitcoin:master from l0rinc:l0rinc/readability-container-contains2 changing 7 files +13 −12
  1. l0rinc commented at 10:51 pm on December 17, 2025: contributor

    Replace the last few instances of .count() != 0 and .count() == 0 and bare count() patterns with the more expressive C++20 .contains() method:

    • std::set<std::string> in getblocktemplate RPC;
    • std::map<std::string, ...> in transaction_tests;
    • other bare std::unordered_set and std::map count calls.

    Also fixes #34101 by reverting boost::multi_index::contains calls not available in our minimum supported version.

    With no remaining violations, enable the readability-container-contains clang-tidy check to prevent future regressions.

    Follow-up to https://github.com/bitcoin/bitcoin/pull/33192

  2. DrahtBot added the label Refactoring on Dec 17, 2025
  3. DrahtBot commented at 10:51 pm on December 17, 2025: contributor

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

    Code Coverage & Benchmarks

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, pablomartin4btc, janb84, rkrux
    Stale ACK Chand-ra, marcofleon

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  4. l0rinc force-pushed on Dec 17, 2025
  5. DrahtBot added the label CI failed on Dec 17, 2025
  6. DrahtBot commented at 11:13 pm on December 17, 2025: contributor

    🚧 At least one of the CI tasks failed. Task lint: https://github.com/bitcoin/bitcoin/actions/runs/20319772315/job/58372602822 LLM reason (✨ experimental): Lint check failed: subtree check did not pass (subtree is not a pure subtree).

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  7. l0rinc force-pushed on Dec 17, 2025
  8. l0rinc force-pushed on Dec 17, 2025
  9. l0rinc marked this as ready for review on Dec 17, 2025
  10. DrahtBot removed the label CI failed on Dec 18, 2025
  11. Chand-ra commented at 9:35 am on December 18, 2025: none
    I performed a quick grep '\.count()' and it looks like there are quite a few instances that seem eligible for this change but aren’t included here, is there some reason for doing so? For example, I found 1, 2, 3, 4 such instances in src/net.cpp.
  12. janb84 commented at 9:51 am on December 18, 2025: contributor

    I performed a quick grep '\.count()' and it looks like there are quite a few instances that seem eligible for this change but aren’t included here, is there some reason for doing so? For example, I found 1, 2, 3, 4 such instances in src/net.cpp.

    The change is not about removing .count() everywhere. But to change it in cases where the count() statement is used to count the number of occurrences to indicate if something is in the collection. The example you reference eg bool has_received{last_recv.count() != 0}; is a “correct” usage of count() (is it not empty)

  13. maflcko commented at 10:40 am on December 18, 2025: member

    Task lint: https://github.com/bitcoin/bitcoin/actions/runs/20319772315/job/58372602822

    Looks like GitHub nuked all historic commits and historic CI runs here?

  14. rkrux approved
  15. rkrux commented at 12:40 pm on December 18, 2025: contributor

    lgtm, code review ACK 31c8ef3d9c885fbe810d5454ba1041ee87efa917

    Nice, I missed reviewing the predecessor PR.

  16. Chand-ra commented at 12:48 pm on December 18, 2025: none

    The change is not about removing .count() everywhere. But to change it in cases where the count() statement is used to count the number of occurrences to indicate if something is in the collection. The example you reference eg bool has_received{last_recv.count() != 0}; is a “correct” usage of count() (is it not empty)

    Makes sense! I seem to have mistaken count() in std::chrono with the ones for container classes.

    ACK 31c8ef3.

  17. l0rinc commented at 1:03 pm on December 18, 2025: contributor

    Thanks for checking @Chand-ra - your mentioned examples are not “contains” alternatives but “exists” alternatives for chrono::duration (which is orthogonal to this change and doesn’t seem to exist in C++20 anyway).

    Looks like GitHub nuked all historic commits and historic CI runs here?

    I did push a few versions while CI was running, maybe that was confusing - is there anything you need me to do here?

  18. fanquake marked this as a draft on Dec 18, 2025
  19. fanquake commented at 1:25 pm on December 18, 2025: member
    Moved to draft for now, given these refactors have broken our minimum version requirements (#34101). That should be resolved before doing anything else here.
  20. l0rinc force-pushed on Dec 18, 2025
  21. l0rinc commented at 2:52 pm on December 18, 2025: contributor
    Reverted the boost changes (already merged ones and new ones), clang-tidy should still pass.
  22. fanquake marked this as ready for review on Dec 18, 2025
  23. marcofleon commented at 4:06 pm on December 18, 2025: contributor

    code review ACK a8a0a0ff77309a95645f6de00595c1dc39cd6eff

    Tested with boost 1.74, good to go.

  24. DrahtBot requested review from rkrux on Dec 18, 2025
  25. pablomartin4btc approved
  26. pablomartin4btc commented at 4:19 pm on December 18, 2025: member

    cr-ACK a8a0a0ff77309a95645f6de00595c1dc39cd6eff

    Verified the revert of boost::multi_index::contains instances (2).

  27. janb84 commented at 4:38 pm on December 18, 2025: contributor

    cr ACK a8a0a0ff77309a95645f6de00595c1dc39cd6eff

    Also confirmed that clang-tidy (still) works

  28. hebasto commented at 7:42 pm on December 18, 2025: member

    Tested a8a0a0ff77309a95645f6de00595c1dc39cd6eff on Fedora 43 with the downloaded Boost 1.73.0 and the following patch:

     0--- a/cmake/module/AddBoostIfNeeded.cmake
     1+++ b/cmake/module/AddBoostIfNeeded.cmake
     2@@ -29,7 +29,7 @@ function(add_boost_if_needed)
     3     endif()
     4   endif()
     5 
     6-  find_package(Boost 1.73.0 REQUIRED CONFIG)
     7+  find_package(Boost 1.73.0 REQUIRED)
     8   mark_as_advanced(Boost_INCLUDE_DIR boost_headers_DIR)
     9   # Workaround for a bug in NetBSD pkgsrc.
    10   # See: https://github.com/NetBSD/pkgsrc/issues/167.
    11--- a/src/ipc/CMakeLists.txt
    12+++ b/src/ipc/CMakeLists.txt
    13@@ -20,6 +20,7 @@ target_link_libraries(bitcoin_ipc
    14   PRIVATE
    15     core_interface
    16     univalue
    17+    Boost::headers
    18 )
    19 
    20 if(BUILD_TESTS)
    

    The compilation fails for another similar reason:

     0$ cmake -B build -DBoost_INCLUDE_DIR=/home/hebasto/Downloads/boost_1_73_0
     1$ cmake --build build
     2[398/621] Building CXX object src/CMakeFiles/bitcoin_node.dir/txmempool.cpp.o
     3FAILED: [code=1] src/CMakeFiles/bitcoin_node.dir/txmempool.cpp.o 
     4/usr/bin/ccache /usr/lib64/ccache/c++ -DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION -DBOOST_NO_CXX98_FUNCTION_BASE -I/home/hebasto/dev/bitcoin/build/src -I/home/hebasto/dev/bitcoin/src -I/home/hebasto/dev/bitcoin/src/leveldb/include -I/home/hebasto/dev/bitcoin/src/minisketch/include -I/home/hebasto/dev/bitcoin/src/univalue/include -isystem /home/hebasto/Downloads/boost_1_73_0 -O2 -g -std=c++20 -fPIC -fno-extended-identifiers -fdebug-prefix-map=/home/hebasto/dev/bitcoin/src=. -fmacro-prefix-map=/home/hebasto/dev/bitcoin/src=. -fstack-reuse=none -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -Wstack-protector -fstack-protector-all -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wformat -Wformat-security -Wvla -Wredundant-decls -Wdate-time -Wduplicated-branches -Wduplicated-cond -Wlogical-op -Woverloaded-virtual -Wsuggest-override -Wimplicit-fallthrough -Wunreachable-code -Wbidi-chars=any -Wundef -Wleading-whitespace=spaces -Wtrailing-whitespace=any -Wno-unused-parameter -MD -MT src/CMakeFiles/bitcoin_node.dir/txmempool.cpp.o -MF src/CMakeFiles/bitcoin_node.dir/txmempool.cpp.o.d -o src/CMakeFiles/bitcoin_node.dir/txmempool.cpp.o -c /home/hebasto/dev/bitcoin/src/txmempool.cpp 
     5/home/hebasto/dev/bitcoin/src/txmempool.cpp: In member function void CTxMemPool::Apply(ChangeSet*):
     6/home/hebasto/dev/bitcoin/src/txmempool.cpp:205:48: error: CTxMemPool::indexed_transaction_set {aka class boost::multi_index::multi_index_container<CTxMemPoolEntry, CTxMemPool::CTxMemPoolEntry_Indices>} has no member named extract
     7  205 |         auto node_handle = changeset->m_to_add.extract(tx_entry);
     8      |                                                ^~~~~~~
     9[415/621] Building CXX object src/CMakeFiles/bitcoin_node.dir/validation.cpp.o
    10ninja: build stopped: subcommand failed.
    

    UPDATE: Boost 1.74 compiles without the error.

  29. hebasto commented at 8:47 pm on December 18, 2025: member

    @l0rinc

    Feel free to incorporate #34107 into this PR, if that makes sense.

  30. l0rinc commented at 8:52 pm on December 18, 2025: contributor
    Thanks @hebasto, I think the two can be merged independently.
  31. hebasto commented at 8:57 pm on December 18, 2025: member

    Approach ACK a8a0a0ff77309a95645f6de00595c1dc39cd6eff.

    Also fixes #34101 by reverting boost::multi_index::contains calls not available in our minimum supported version.

    I’d prefer having this change in a separate commit.

    Also there’s a typo in the commit message: “… available in Boost 1.74.0 only” –> “… available in Boost since 1.78.0 only”

  32. Fix compilation for old Boost versions
    Fixes https://github.com/bitcoin/bitcoin/issues/34101 by reverting `boost::multi_index::contains` calls only available in Boost 1.78.0
    fd9f1accbd
  33. refactor: enable `readability-container-contains` clang-tidy rule
    Replace the last few instances of `.count() != 0` and `.count() == 0` and `.count()` patterns with the more expressive C++20 `.contains()` method:
    
    * `std::set<std::string>` in `getblocktemplate` RPC;
    * `std::map<std::string, ...>` in `transaction_tests`;
    * other bare `std::unordered_set` and `std::map` count calls.
    
    With no remaining violations, enable the `readability-container-contains`
    clang-tidy check to prevent future regressions.
    1e94e562f7
  34. l0rinc force-pushed on Dec 18, 2025
  35. l0rinc commented at 9:40 pm on December 18, 2025: contributor
    Rebased and split into two commits and updated commit message to reference Boost 1.78.0 instead.
  36. hebasto approved
  37. hebasto commented at 9:50 pm on December 18, 2025: member
    ACK 1e94e562f76e6152dffb2a2d07dc3429137098b5.
  38. DrahtBot requested review from janb84 on Dec 18, 2025
  39. DrahtBot requested review from marcofleon on Dec 18, 2025
  40. DrahtBot requested review from pablomartin4btc on Dec 18, 2025
  41. pablomartin4btc approved
  42. pablomartin4btc commented at 10:00 pm on December 18, 2025: member

    re-ACK 1e94e562f76e6152dffb2a2d07dc3429137098b5

    Boost fix/ revert split in a separate commit.

  43. janb84 commented at 9:11 am on December 19, 2025: contributor

    ACK 1e94e562f76e6152dffb2a2d07dc3429137098b5

    changes since last ack:

    • reverted boost library contains calls
    • split out the revert in separate commit.
  44. rkrux commented at 9:41 am on December 19, 2025: contributor
    re-ACK 1e94e562f76e6152dffb2a2d07dc3429137098b5
  45. fanquake referenced this in commit acba51101b on Dec 19, 2025
  46. fanquake merged this on Dec 19, 2025
  47. fanquake closed this on Dec 19, 2025

  48. l0rinc deleted the branch on Dec 20, 2025

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-01-01 12:13 UTC

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