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

John McCall rjmccall at apple.com
Fri May 10 17:01:01 UTC 2013


On May 10, 2013, at 1:43 AM, Richard Earnshaw <rearnsha at arm.com> wrote:
> On 09/05/13 19:10, John McCall wrote:
>> On May 9, 2013, at 9:35 AM, Richard Earnshaw <rearnsha at arm.com> wrote:
>>> 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.
>> 
>> This isn't a condition, it's a statement:  it specifies that the data size and
>> non-virtual size of these types is equal to their size.  This is necessary
>> because those values are otherwise computed by the layout algorithm,
>> and, well, we don't run the layout algorithm on types that are POD for
>> the purposes of layout.
>> 
> 
> But that's my point, an Empty class doesn't have it's size equal to it's data size, since the latter is zero, and the former must be non-zero. However, it does currently fit the rule of being POD for the purpose of Layout, so there's a contradiction in the specification.

Why is the data size zero?  You seem to be assuming that the data size is
some emergent property that you can deduce directly from the fact that the
type has no fields.  It is not.  It is defined, directly, by this very sentence, to
be equal to the size of the type.  You should be reading this sentence as:
  "When it matters, all of these types are defined to have a data size and
  non-virtual size equal to their size."

The data size is also *completely irrelevant*, because nothing in the ABI
ever requests the data size of an empty class.

John.


More information about the cxx-abi-dev mailing list