https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119999
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- Using -fno-finite-loops prevents the assertion from failing: -ffinite-loops Assume that a loop with an exit will eventually take the exit and not loop indefinitely. This allows the compiler to remove loops that otherwise have no side-effects, not considering eventual endless looping as such. This option is enabled by default at -O2 for C++ with -std=c++11 or higher. I think GCC is behaving as expected (although I'm not sure why r14-2709 changed it).