It seems that VS cannot handle the situation when there is more than one empty base class. In your first example, theres is one empty base class, and in the second, two. For example, in my field, this code compiled in VS2013:
#include <iostream> class B1 {}; class B2 {}; class B3 {}; class B4 {}; class B5 {}; class B6 {}; class C1 : B1 {}; class C2 : B1, B2 {}; class C3 : B1, B2, B3 {}; class C4 : B1, B2, B3, B4 {}; class C5 : B1, B2, B3, B4, B5 {}; class C6 : B1, B2, B3, B4, B5, B6 {}; int main() { std::cout << sizeof(C1) << ' ' << sizeof(C2) << ' ' << sizeof(C3) << ' ' << sizeof(C4) << ' ' << sizeof(C5) << ' ' << sizeof(C6) << std::endl; }
exits
1 1 2 3 4 5
So far, both clang and gcc output are 1 1 1 1 1 1 .
But this behavior is still standard, since the standard does not oblige the implementation to optimize empty base classes.
source share