A loop erases the element its iterator points to and then increments that iterator, which is no longer valid
What it finds
v.erase(it) invalidates it; the loop's ++it then steps from a dangling iterator. The iterator that erase returns is the next valid one: it = v.erase(it); with the increment moved to the other branch. Loops that leave right after the erase are left alone.
From the rule's source, erase_invalidates_loop_iterator.rs.
Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/cpp:erase-invalidates-loop-iterator" = "error"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/cpp:erase-invalidates-loop-iterator] reason="..."tx0 explain tx0/cpp:erase-invalidates-loop-iterator shows the same in the terminal. Found a false positive? Report it.