A simple question but I can not find the set of rules that proves that the behavior of the following code example is correct. It seems here that only strDerived is moved from b, but strBase is copied? Will the implicitly declared move assignment operator of Derived (=> rule of zero) always call the implicitly declared copy assignment operator of Base when it is not finding any move assignment operator there? Is that guaranteed? (Does the same apply when doing move-construction instead of move-assignment in the example?)
#include <string>
struct Base
{
~Base() = default;
std::string strBase{ "Base"};
};
struct Derived : public Base
{
std::string strDerived{ "Derived" };
};
int main()
{
Derived a, b;
a = std::move( b );
return 0;
}
Of course: this is the fallback for a C++11 class containing a C++03 (thus copy-only) class as a (member or base) subobject. Apparently early versions of the rules would break explicitly defaulting such a move constructor, but that’s long been fixed: in the current draft, [class.copy.ctor]/10.1 refers merely to overload resolution failing rather than to a specific corresponding special member function.