https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107850
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> --- See also https://cplusplus.github.io/LWG/issue2542 which was another change in the same vein. Generally, we're getting stricter about rejecting predicates like yours, because reasoning about the program because harder (and sometimes implementing those algorithms because unreasonably complex) if predicates have non-obvious side effects like modifying elements.