Yes, this is a "bit counter intuitive." With copy permission, all side effects of the constructor are allowed.
#include <iostream> struct X { X() { std::cout << "Construct" << std::endl; } X(X&&) { std::cout << "Move" << std::endl; } ~X() { std::cout << "Destruct" << std::endl; }; }; X f() { return X(); } int main() { X x(f()); return 0; }
Copy elision: g ++ -std = C ++ 11 src-test / main.cc
Construct Destruct
No copy: g ++ -std = C ++ 11 -fno-elide-constructors src-test / main.cc
Construct Move Destruct Move Destruct Destruct
The compiler, knowing the hardware that the program / library creates, can use (optionally) a copy of elision. C ++ itself does not know about hardware return mechanisms. Therefore, it is not possible to build on a specific address in this context.
source share