[cxx-abi-dev] Empty Classes and data layout

Richard Earnshaw rearnsha at arm.com
Thu May 9 16:35:23 UTC 2013


We've been looking into a defect that's been raised on our C++ Binding
for ARM relating to the handling of empty classes, that is, something like

struct S {};

In C this is not legal, and our C ABI defines no mechanism for passing
such an object as a function parameter.  However, in C++ this is valid
and at least at first reading matches the definition of a POD class.

However, the C++(98) states (clause 9 [class] para 3) that complete
objects and member sub-objects of class type have non-zero size; which
means that such a class, despite matching the GC++ABI rule for a POD for
the Purposes of Layout definition fails to meet the condition in clause
2.2 that "All of these types have data size and non-virtual size equal
to their size", since the size is one, but the data-size is zero.

It would appear from the rules in clause 2.4 (Non-POD layout) that
treating such classes according to the non-POD rules would lead to the
desired behaviour (size = 1, and base class optimisation happens when
the type is used as a base class); but that would mean that the
definition of POD for the Purposes of Layout would need to be amended to
exclude empty classes that are also POD from the list of matching types.

Have we missed something?  or is this a change/clarification that could
viably be made?

R.



More information about the cxx-abi-dev mailing list