The initialization of copying is still dependent on copying, and I assume this is happening. Theoretically, temporary B built from a , and the copy constructor is used to create B from temporary. In practice, the copy can be optimized.
To verify this, you can make the copy constructor private:
class B{ public: B(const A &a){cout << "B construct from A" << endl;} private: B(const B &b){cout << "B copy constructor" << endl;} };
and get a compilation error. This means that the compiler expects the copy constructor to be available, but does not need to be called.
Copying elision is the only case where the observed behavior can be changed.
source share