Is the Empty Base Class Optimization now a mandatory optimization (at least for standard-layout classes)?

Yes, you’re correct, that was pointed out in the “PODs revisited” proposals: http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2007/n2342.htm#ABI

The Embarcadero compiler docs also state it: http://docwiki.embarcadero.com/RADStudio/en/Is_standard_layout

Another key point is [class.mem]/16

Two standard-layout struct (Clause 9) types are layout-compatible if they have the same number of non-static data members and corresponding non-static data members (in declaration order) have layout-compatible types (3.9).

Note that only data members affect layout compatibility, not base classes, so these two standard layout classes are layout-compatible:

struct empty { };
struct stdlayout1 : empty { int i; };

struct stdlayout2 { int j; };

Leave a Comment