Why is move constructor not picked when returning a local object of type derived from the function's return type?
问题 The following code is rejected by both Clang and GCC (trunk versions): #include <memory> struct Base { Base() = default; Base(Base const&) = delete; Base(Base&&) = default; }; struct Derived : Base { Derived() = default; Derived(Derived const&) = delete; Derived(Derived&&) = default; }; auto foo() -> Base { Derived d; return d; // ERROR HERE } Causing the following error: prog.cc: In function 'Base foo()': prog.cc:21:12: error: use of deleted function 'Base::Base(const Base&)' return d; ^