In the following code:
struct A {
A() {}
A(A &&) { printf("moving A\n"); }
~A() { printf("destructing A\n"); }
};
struct B : A {
B() {}
B(B &&) { printf("moving B\n"); }
~B() { printf("destructing B\n"); }
};
B func() {
B b;
return b;
}
int main() {
A a = func();
printf("hello\n");
}
The following output is produced:
moving A
destructing B
destructing A
hello
destructing A
Why isn't the move elided? Why is the move constructor of A called but not that of B? What's actually happening here?