In the following example struct E inherits structs C and D and has no other data members:
struct A{};
struct B{};
struct C : A, B {};
struct D : A, B {};
struct E : C, D {};
int main() {
static_assert(sizeof(C) == 1);
static_assert(sizeof(D) == 1);
//static_assert(sizeof(E) == 2); // in Clang and GCC
static_assert(sizeof(E) == 3); //in MSVC
}
In all compilers I have tested, sizeof(C)==1 and sizeof(D)==1, and only in MSVC sizeof(E)==3 so more than the summed size of its parents/members, demo: https://gcc.godbolt.org/z/aEK7rjKcW
Actually I expected to find sizeof(E) <= sizeof(C)+sizeof(D) (less in case empty base optimization). And there is hardly any padding here, otherwise sizeof(E) would be 2 or 4.
What is the purpose of extra space (sizeof(E)-sizeof(C)-sizeof(D) == 1) in E?