https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87481
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- There is actually nothing weird on that, with smaller ones we terminate the inner loop early and then stop. With the debugging -O0 build I have around, the constexpr processing is very slow though, so I get about 35 iterations of the outer loop when inner loop has 10000 iterations per second, so that would be about 7500 seconds for the whole testcase. Of course with optimized build that could be say 10 times faster. In any case, I think the total loop nesting limit would be helpful here, perhaps have two global vars, one loop nesting, incremented at the start of cxx_eval_loop_expr and decremented at the end (or just bool if the current loop is nested) and then have a global counter compared against the new limit, with say a default of 524288, that would be incremented next to the automatic count, and that would be cleared at the end of cxx_eval_loop_expr if it was not nested (i.e. the nesting count would be 0 when that function was called).