AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 15 Bitcoin

Merge bitcoin/bitcoin#36682: refactor: Use std::erase and std::erase_if

Public commit record

What the developer wrote

Authored by merge-script

93/100 · Strong
Merge bitcoin/bitcoin#36682: refactor: Use std::erase and std::erase_if

fa87bfe31dfda2d102c4e0cb5d39813cf84c7d1e refactor: Use std::erase and std::erase_if over iterator-based erase (MarcoFalke)
fa93a02563145aca3f96badaabe302b2dfa331d5 refactor: Use std::erase and std::erase_if over list removal or vector erase-remove (MarcoFalke)

Pull request description:

Convert `remove` and `remove_if` to the C++20 `std::erase` and `std::erase_if` overloads.

The legacy ones can be confusing, because:

* Array-based containers (like vector) must use the erase-remove idiom. Forgetting the erase, or forgetting to pass the end iterator (`bugprone-inaccurate-erase`) can be a bug, see also https://github.com/bitcoin/bitcoin/pull/36588#discussion_r4345799022. So a call only to "remove" will not erase.
* Node-based containers (like list or set) must not use the idiom. Using it will be a pessimization or won't compile. And correctly not using the idiom reads confusing, because a call to "remove" will actually erase.
* They are more verbose.

Also convert simple iterator-erase (which is verbose, but fine) to the std overload.

ACKs for top commit:
jpk68:
ACK fa87bfe31dfda2d102c4e0cb5d39813cf84c7d1e
hodlinator:
ACK fa87bfe31dfda2d102c4e0cb5d39813cf84c7d1e
w0xlt:
ACK fa87bfe31dfda2d102c4e0cb5d39813cf84c7d1e

Tree-SHA512: 08fca3ecb73a5c45371a2e65339d9e35911f89dc717568cc29564f1a1395a44d84e939b9d38a21cadf5f2cbd64463c2564b1f7239ca75f53cf0bb30ae724dafd
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit is a code cleanup that replaces older, more verbose ways of removing items from lists and vectors with newer C++20 standard helpers called std::erase and std::erase_if. It does not change what the program does, only how the source code expresses it. There is no security bug being fixed here.

Recommended action

No security action required. Treat as a normal code-quality refactor during review.

Security signals we found

No strong security signals were identified.

Risk score

Why this scored 15/100

Our methodology →
Potential impact 0/30
Exploitability 0/25
Stealth signal 0/15
Affected reach 0/15
Confidence 10/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.