struct Foo { Foo(Foo && from) { } Foo() { } ~Foo() { } /*private: Foo(const Foo & from) { }*/ }; Foo CreateFoo(bool b) { Foo f; if (b) return Foo(); return f; } int main () { Foo f(CreateFoo(false)); }
The problem might also be a spurious destructor call. The symptom is that the constructor without parameters is called once, the move constructor never and the destructor twice. With the traditional copy constructor included, the programme works as intended, with one additional move constructor call, but no copy constructor calls. Without the "if (b) return Foo();" line the programme also works. I've tested with these builds and -std=gnu++0x: g++-4.3 (Debian 4.3.2-1.1) 4.3.2 g++ (Debian 20090129-1) 4.4.0 20090129 (experimental) [trunk revision 143770] -- Summary: Missing "move" constructor call (C++0x rvalue references) Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: gbrammer at gmx dot de GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39126