refactor: Enable more tidy bugprone checks #36588

pull maflcko wants to merge 5 commits into bitcoin:master from maflcko:2610-tidy-bugprone changing 5 files +24 −9
  1. maflcko commented at 9:57 AM on October 21, 2026: member

    Enable some bugprone clang-tidy checks, which seem useful.

    Apart from a test-only bug, they didn't find anything severe, but I think it still makes sense to enable them, so that it is easier to read the resulting code. Also, it is trivial to disable them, if they turn out annoying.

  2. DrahtBot renamed this:
    refactor: Enable more tidy bugprone checks
    refactor: Enable more tidy bugprone checks
    on Oct 21, 2026
  3. DrahtBot added the label Refactoring on Oct 21, 2026
  4. DrahtBot commented at 9:57 AM on October 21, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    ACK hebasto, stickies-v
    Stale ACK hodlinator

    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-->

  5. DrahtBot added the label CI failed on Oct 21, 2026
  6. DrahtBot commented at 10:50 AM on October 21, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/39580996840/job/119158281831</sub> <sub>LLM reason (✨ experimental): The build failed because Clang treated the unused copy_target variable in util_not_null_tests.cpp as an error (-Werror).</sub>

    <details><summary>Hints</summary>

    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.

    </details>

  7. maflcko force-pushed on Oct 21, 2026
  8. hebasto commented at 10:55 AM on October 21, 2026: member

    Enable some bugprone clang-tidy checks...

    Concept ACK.

  9. maflcko force-pushed on Oct 21, 2026
  10. DrahtBot removed the label CI failed on Oct 21, 2026
  11. refactor: Enable bugprone-unused-raii
    The code change does not change any behavior, because the name is not
    used in the compile-time context.
    fab3062590
  12. maflcko force-pushed on Oct 21, 2026
  13. in src/qt/walletcontroller.cpp:182 in fa077e9f79 outdated
     178 | @@ -179,7 +179,7 @@ void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
     179 |      // Unregister wallet model.
     180 |      {
     181 |          QMutexLocker locker(&m_mutex);
     182 | -        m_wallets.erase(std::remove(m_wallets.begin(), m_wallets.end(), wallet_model));
     183 | +        std::erase(m_wallets, wallet_model);
    


    hodlinator commented at 7:18 AM on October 22, 2026:

    fa077e9 refactor: Enable bugprone-inaccurate-erase:

    What do you mean by this?

    Note: Wallets are unique, so the code change does not change any behavior.

    https://en.cppreference.com/cpp/container/vector/erase2 seems to specify that they are equivalent.


    maflcko commented at 7:49 AM on October 22, 2026:

    https://en.cppreference.com/cpp/container/vector/erase2 seems to specify that they are equivalent.

    Heh, the docs say that

    std::erase(c,v);

    is equivalent to

    c.erase(std::remove(c.begin(), c.end(), value), c.end());

    However, the code here is:

    m_wallets.erase(std::remove(m_wallets.begin(), m_wallets.end(), wallet_model)); // note the "missing" end

    This is harmless in this case, but confusing, because:

    • It doesn't follow the idiom.
    • Apparently reviewers (including myself) aren't familiar with the idiom, unless they look it up.

    So my recommendation would be to completely get rid of std::vector::erase and instead use the C++20 std::erase(vector,...)


    hodlinator commented at 7:59 AM on October 22, 2026:

    Dang, missed it. :D

    nit: The commit message could be made clearer:

    Note: Wallets are unique, so even through we previously weren't specifying a range of iterators to vector::erase(), the behavior does not change.


    maflcko commented at 8:02 AM on October 22, 2026:

    nit: The commit message could be made clearer:

    Thx, will leave this thread open for now, so that reviewers see it, and so that I can avoid a push and review churn.


    maflcko commented at 9:35 AM on October 28, 2026:
  14. hodlinator commented at 7:28 AM on October 22, 2026: contributor

    Concept ACK fa60b2ae8db2072f5a851f7f9669cb6606fb7806

  15. hodlinator approved
  16. hodlinator commented at 8:00 AM on October 22, 2026: contributor

    ACK fa60b2ae8db2072f5a851f7f9669cb6606fb7806

  17. DrahtBot requested review from hebasto on Oct 22, 2026
  18. stickies-v approved
  19. stickies-v commented at 9:10 AM on October 22, 2026: contributor

    ACK fa60b2ae8db2072f5a851f7f9669cb6606fb7806

  20. refactor: Enable bugprone-string-literal-with-embedded-nul
    Also, fix some test bugs.
    fafce023b3
  21. refactor: Enable bugprone-inaccurate-erase
    Also, instead of using the erase-remove idiom consistenly, just use the
    C++20 std::erase here.
    
    Note: Wallets are unique, so the code change does not change any
    behavior.
    faa76b44c6
  22. refactor: Enable some useful bugprone checks, which are clean right now
    Also, sort
    fa211896e5
  23. refactor: Enable bugprone-return-const-ref-from-parameter to find missing LIFETIMEBOUND annotations
    Whenever the check fires, a missing LIFETIMEBOUND should be added.
    facb220906
  24. in src/test/util_tests.cpp:1177 in fa60b2ae8d outdated
    1173 | @@ -1174,7 +1174,7 @@ BOOST_AUTO_TEST_CASE(test_Capitalize)
    1174 |  {
    1175 |      BOOST_CHECK_EQUAL(Capitalize(""), "");
    1176 |      BOOST_CHECK_EQUAL(Capitalize("bitcoin"), "Bitcoin");
    1177 | -    BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"), "\x00\xfe\xff");
    1178 | +    BOOST_CHECK_EQUAL(Capitalize("\x00\xfe\xff"s), "\x00\xfe\xff"sv);
    


    stickies-v commented at 9:10 AM on October 22, 2026:

    note: it seems like string-literal-with-embedded-nul only checks std::string constructors, not std::string_view. Similar ToLower (:1156) and ToUpper (:1170) tests have the same bug and don't get flagged. For example, the below diff passes the test.

    <details> <summary>git diff on fa60b2ae8d</summary>

    diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
    index 6db2f90908..f3cdec9063 100644
    --- a/src/test/util_tests.cpp
    +++ b/src/test/util_tests.cpp
    @@ -1153,7 +1153,7 @@ BOOST_AUTO_TEST_CASE(test_ToLower)
     
         BOOST_CHECK_EQUAL(ToLower(""), "");
         BOOST_CHECK_EQUAL(ToLower("#HODL"), "#hodl");
    -    BOOST_CHECK_EQUAL(ToLower("\x00\xfe\xff"), "\x00\xfe\xff");
    +    BOOST_CHECK_EQUAL(ToLower("\x00\xfe\xff"), "");
     }
     
     BOOST_AUTO_TEST_CASE(test_ToUpper)
    @@ -1167,7 +1167,7 @@ BOOST_AUTO_TEST_CASE(test_ToUpper)
     
         BOOST_CHECK_EQUAL(ToUpper(""), "");
         BOOST_CHECK_EQUAL(ToUpper("#hodl"), "#HODL");
    -    BOOST_CHECK_EQUAL(ToUpper("\x00\xfe\xff"), "\x00\xfe\xff");
    +    BOOST_CHECK_EQUAL(ToUpper("\x00\xfe\xff"), "");
     }
     
     BOOST_AUTO_TEST_CASE(test_Capitalize)
    
    

    </details>


    maflcko commented at 3:23 PM on October 23, 2026:

    thx, done

  25. maflcko force-pushed on Oct 23, 2026
  26. hebasto approved
  27. hebasto commented at 2:23 PM on October 27, 2026: member

    ACK facb2209061ce40f558d9e1feaaf8e9a627117e5.

    ""sv in util_tests.cpp needs #include <string_view>.

  28. DrahtBot requested review from hodlinator on Oct 27, 2026
  29. DrahtBot requested review from stickies-v on Oct 27, 2026
  30. stickies-v commented at 2:32 PM on October 27, 2026: contributor

    re-ACK facb2209061ce40f558d9e1feaaf8e9a627117e5

  31. maflcko commented at 3:07 PM on October 27, 2026: member

    ""sv in util_tests.cpp needs #include <string_view>.

    thx, will leave this for iwyu to fix, to limit the review churn here. (The include exists indirectly, so this is just a iwyu style issue)

  32. fanquake merged this on Oct 27, 2026
  33. fanquake closed this on Oct 27, 2026

  34. maflcko deleted the branch on Oct 27, 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-10-30 09:40 UTC