In code like this:
class X {
X(const X&) {
// ...
}
X(const X&&) {
// ...
}
// ...
};
void f() {
X a;
// ...
X b = a;
// ... code that doesn't use a
}
My understanding is that the last statement calls the copy constructor not the move constructor. Assuming a
is never used again in f()
, can the compiler automatically optimize this statement to use the move constructor instead?
P.S. I know about std::move()
, but I'm asking about automatic move.