refactor: Enable more tidy bugprone checks #36588

Manually merged
maflcko merged 5 commits from 2610-tidy-bugprone into master 2026-10-27 15:31:55 +00:00 AGit
maflcko commented 2026-10-21 09:57:41 +00:00 (Migrated from github.com)

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.

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.
DrahtBot commented 2026-10-21 09:57:51 +00:00 (Migrated from github.com)

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36588 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36588.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36588#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [hebasto](https://github.com/bitcoin/bitcoin/pull/36588#pullrequestreview-5668639605), [stickies-v](https://github.com/bitcoin/bitcoin/pull/36588#issuecomment-6444739681) | | Stale ACK | [hodlinator](https://github.com/bitcoin/bitcoin/pull/36588#pullrequestreview-5610972246) | 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-->
First-time contributor

Base: 631b0065a7f2696a7240db4bbb63589444dc96b8
Head: facb2209061ce40f558d9e1feaaf8e9a627117e5

Findings

Suggestions

Replace the unused <algorithm> include (src/qt/walletcontroller.cpp:182, head)

The std::remove call was replaced, and this file has no remaining <algorithm> use. std::erase is available through the vector header, while the remaining std::make_pair and std::move uses need <utility>. Replace <algorithm> with <utility> to keep the direct standard-library dependencies explicit.

Previously reported; verified as still present in this revision. Status: still_present. Author position: none. Originally reported at facb2209061ce40f558d9e1feaaf8e9a627117e5. The file still includes , while the former std::remove call has been replaced by std::erase. The file continues to use std::make_pair and std::move without directly including , so the reported include-maintenance issue remains; the change removed the prior algorithm use, so it is not unchanged.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:07e6f9b519d677c46869e755d75661fb116896a6f8263852f18f7dadf6dbfe40:7904dbcc7b2243bfe123ccb0aaaca2ac080b278ec99bb35aa62cf1481ce82fc1 --> Base: `631b0065a7f2696a7240db4bbb63589444dc96b8` Head: `facb2209061ce40f558d9e1feaaf8e9a627117e5` <!-- ralph-case:eb7511416427bd83908276403e871dabb0e9c2521dcfb0efe12eb5c59a1d9fd0 --> ##### Findings **Suggestions** **Replace the unused `<algorithm>` include** (src/qt/walletcontroller.cpp:182, head) The `std::remove` call was replaced, and this file has no remaining `<algorithm>` use. `std::erase` is available through the vector header, while the remaining `std::make_pair` and `std::move` uses need `<utility>`. Replace `<algorithm>` with `<utility>` to keep the direct standard-library dependencies explicit. Previously reported; verified as still present in this revision. Status: still_present. Author position: none. Originally reported at `facb2209061ce40f558d9e1feaaf8e9a627117e5`. The file still includes <algorithm>, while the former std::remove call has been replaced by std::erase. The file continues to use std::make_pair and std::move without directly including <utility>, so the reported include-maintenance issue remains; the change removed the prior algorithm use, so it is not unchanged. [Full review report](<https://review.fish.foo/traces/36588-facb2209061ce40f558d9e1feaaf8e9a627117e5-1486-8.html>)
DrahtBot commented 2026-10-21 10:50:52 +00:00 (Migrated from github.com)

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

Hints

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.

<!--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>
hebasto commented 2026-10-21 10:55:43 +00:00 (Migrated from github.com)

Enable some bugprone clang-tidy checks...

Concept ACK.

> Enable some bugprone clang-tidy checks... Concept ACK.
hodlinator (Migrated from github.com) reviewed 2026-10-22 07:28:47 +00:00
hodlinator (Migrated from github.com) left a comment

Concept ACK fa60b2ae8d

Concept ACK fa60b2ae8db2072f5a851f7f9669cb6606fb7806
hodlinator (Migrated from github.com) commented 2026-10-22 07:18:26 +00:00

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.

> [fa077e9](https://github.com/bitcoin/bitcoin/pull/36588/changes/fa077e9f79b9d5533991e208ad25e35474ed4ca2) _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 (Migrated from github.com) reviewed 2026-10-22 07:49:44 +00:00
maflcko (Migrated from github.com) commented 2026-10-22 07:49:44 +00:00

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,...)

> 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 (Migrated from github.com) reviewed 2026-10-22 07:59:29 +00:00
hodlinator (Migrated from github.com) commented 2026-10-22 07:59:29 +00:00

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.

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.
hodlinator (Migrated from github.com) approved these changes 2026-10-22 08:00:19 +00:00
hodlinator (Migrated from github.com) left a comment
ACK fa60b2ae8db2072f5a851f7f9669cb6606fb7806
maflcko (Migrated from github.com) reviewed 2026-10-22 08:02:20 +00:00
maflcko (Migrated from github.com) commented 2026-10-22 08:02:20 +00:00

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.

> 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.
stickies-v (Migrated from github.com) approved these changes 2026-10-22 09:10:33 +00:00
stickies-v (Migrated from github.com) left a comment
ACK fa60b2ae8db2072f5a851f7f9669cb6606fb7806
stickies-v (Migrated from github.com) reviewed 2026-10-22 09:10:47 +00:00
stickies-v (Migrated from github.com) commented 2026-10-22 09:10:47 +00:00

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.

git diff on fa60b2ae8d
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)

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 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 (Migrated from github.com) reviewed 2026-10-23 15:23:33 +00:00
maflcko (Migrated from github.com) commented 2026-10-23 15:23:33 +00:00

thx, done

thx, done
hebasto (Migrated from github.com) approved these changes 2026-10-27 14:23:02 +00:00
hebasto (Migrated from github.com) left a comment

ACK facb220906.

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

ACK facb2209061ce40f558d9e1feaaf8e9a627117e5. `""sv` in `util_tests.cpp` needs `#include <string_view>`.
stickies-v commented 2026-10-27 14:32:49 +00:00 (Migrated from github.com)

re-ACK facb220906

re-ACK facb2209061ce40f558d9e1feaaf8e9a627117e5
maflcko commented 2026-10-27 15:07:33 +00:00 (Migrated from github.com)

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

> `""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)
maflcko (Migrated from github.com) reviewed 2026-10-28 09:35:04 +00:00
maflcko (Migrated from github.com) commented 2026-10-28 09:35:04 +00:00
put the follow-up in https://github.com/bitcoin/bitcoin/pull/36682
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36588
No description provided.