> Fix for range-based for loops<p>Oh man, having different compilers in c++20 mode handle things differently is going to cause more grief, not less.<p>Reminder: Prior to c++23 the following is broken:<p><pre><code> vector<int> const &identity(vector<int> const &a) { return a; }
for (auto a : identity(vector<int>{1,2})) { ... }
</code></pre>
That's because the lifetime of the vector isn't extended through the life of the for loop. That is, the vector is destructed right after identity returns, and the for loop ends up trying to iterate through a vector that's been destructed.<p>But now gcc in c++20 with -frange-for-ext-temps mode will extend the lifetime of the vector and the above code will work, and people will write code like that, and it'll break mysteriously on other c++20 compilers. The usual way it breaks is that the for loop does nothing because in destructing the vector it sets the begin and end pointers to null, so it's a subtle kind of breakage.<p>BTW clang with -Wall doesn't complain about the above broken code.