https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118386
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #2) > > Yet it works fine when compiling in -std=c++23 > > C++23 changed the lifetime of the temporaries inside a range for. Before c++23, temporaries for initialization of the range (except for the outer most one) was destroyed right the finish of the expression but in c++23, they now live until the end of the for.