https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107850
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> --- The problem with side effects is not that they happen more than once, but that they happen at all. The algorithm is called "erase_if" so it's surprising if it actually mutates the remaining elements, rather than just removing some. What you want is a different algorithm, and so should have a different name.