Can the compiler optimize out the empty base if the class contains a member of base class type as first element, followed by other members?

Viewed 325

Consider:

struct empty {};
struct child : empty {
    empty a[sizeof(int) / sizeof(empty)];
    int b;
};
// Assume sizeof(int) >= sizeof(empty)

Does the standard mandate that sizeof(child) is more than 2 * sizeof(int)?

The way I see it, nothing prohibits the baseclass-subobject from sharing its address with member b.

If not, are there any common ABIs exploiting that at all?

2 Answers
Related