https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94888
Jason Merrill <jason at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jason at gcc dot gnu.org --- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> --- G++ doesn't elide the copy because the constructor template is not eligible for copy elision: only non-template constructors are considered to be copy/move constructors. Without a destructor, the implicitly declared move constructor is a better candidate than the template, but a user-declared destructor prevents the implicit declaration of a move constructor. Adding Function(Function&&) = default; to Function fixes the problem. I don't know why other compilers do something different with this testcase.