https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108594
Bug ID: 108594 Summary: GCC ignores deleted movement constructor is not used on return Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: dev at gutoehrlein dot eu Target Milestone: --- Hello, im not 100% certain, but the following code should probably not compile, but instead produce an error. In gcc (Version 12.2, also in trunk) the code compiles. Both the MSVC compiler and clang (Version 15.0.0) produce an error: * MSVC: error C2280: 'ClassA::ClassA(ClassA &&)': attempting to reference a deleted function * CLANG: error: call to delete constructor of 'Class A' Since the movement constructor in class a is defined but deleted, shouldn't it be selected by the return in the function fA to avoid copying? If so, the return should produce an error, because the constructor is deleted. Sincerly Robin Example in godbold.org: https://godbolt.org/z/1fnr6zKx4 -------------------- class ClassA { public: ClassA() {} ClassA(const ClassA& v) {} ClassA(ClassA&& v) = delete; }; ClassA fA() { return ClassA(); } // Here the movement constructor should be selected int main() { ClassA a { fA() }; return 0; }