https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86980
Jonathan Wakely <redi at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- This is a bug in your code, not GCC. you're returning a reference to a local variable, which goes out of scope, leaving a dangling reference. When you don't give the lambda an explicit return type it returns by value, so works correctly. You should just do: auto f = []() { Traceable tmp; return tmp; }; This returns by value and can elide the move, so is safer and faster.