https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96917
Guillaume Racicot <gufideg at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |gufideg at gmail dot com --- Comment #2 from Guillaume Racicot <gufideg at gmail dot com> --- Seems this bug also apply to deduced return type: template <typename T> void foo(); void bar() { int i; auto l = [&i]() -> decltype(auto) { foo<decltype(i)>(); return i; }; l(); foo<decltype(l())>(); } Yield the assembly: bar(): sub rsp, 8 call void foo<int>() add rsp, 8 jmp void foo<int&>() Strangely, replacing the return expression to `return static_cast<decltype(i)>(i);` seems to fix the behaviour.