https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97435
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> --- Yes, this is undefined behaviour. It's equivalent to: const int& f(const int& i) { return i; } const int& i = f(5); int j = i; // undefined Lifetime is only extended if the reference is bound directly to the temporary object, not to another reference that happens to be bound to it inside some function. Consider the case where the body of A::operator+= is not visible to the compiler. How is it supposed to know whether the returned value refers to *this or not, and therefore how is it supposed to know whether to destroy the temporary A(5) immediately or not?