https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112307
--- Comment #7 from Raffael Casagrande <raffael at casagrande dot ch> --- @Jonathan Wakely Thanks very much for the detailed analysis. But there is one point which I don't understand: > BUT, the self-referential pointer is set to the address of the range_ member > before the return value is copied, and so goes out of scope when that object > is copied via registers and then copied again into the automatic variable > in main(). I can't follow/understand how Next() is called before the return value is copied. If we look at the constructor of EnumeratorRange, we see that `enumerator_` is initialized before end_reached_. And afterwards the enumerator_ is not moved/copied anymore because of copy elision? This can be verified by adding some extra print statements to the copy/move constructor of Enumerator.