#include <iostream> using namespace std; struct A { A() { cout << "A()" << endl; } ~A() { cout << "~A()" << endl; } A(A&&) { cout << "A(A&&)" << endl; } A& operator =(A&&) { cout << "A& operator =(A&&)" << endl; return *this; } }; struct B { // According to the C++11, the move ctor/assignment operator // should be implicitly declared and defined. The move ctor // /assignment operator should implicitly call class A's move // ctor/assignment operator to move member a. A a; }; B f() { B b; // The compiler knows b is a temporary object, so implicitly // defined move ctor/assignment operator of class B should be // called here. Which will cause A's move ctor is called. return b; } int main() { f(); return 0; } My expected output should be:
A() A(A&&) ~A() ~A() However, the actual output is: (The C++ compiler is: Visual Studio 2012)
A() ~A() ~A() Is this a bug of VC++? or just my misunderstanding?
A's move assignment operator to be called?return bshould do a move ofbinto the return value. Maybe Visual Studio 2012 just doesn't implement C++11 correctly?bshould be moved. But that should result in a call toA's move constructor, not the move assignment operator.