On 10/04/18 13:12 -0400, Jason Merrill wrote:
In Joseph's patch for bug 52023, making _Alignof(double) 4 rather than
8 on x86, he deliberately didn't change the C++ behavior, based on
this wording in the C++ standard:

The alignment required for a type might be different when it is used
as the type of a complete object and when it is used as the type of a
subobject. [ Example:
 struct B { long double d; };
 struct D : virtual B { char c; };
When D is the type of a complete object, it will have a subobject of
type B, so it must be aligned appropriately for a long double. If D
appears as a subobject of another object that also has B as a virtual
base class, the B subobject might be part of a different subobject,
reducing the alignment requirements on the D subobject. — end example
] The result of the alignof operator reflects the alignment
requirement of the type in the complete-object case.

This suggests that alignof shouldn't consider alignment of non-static
data members.  I think that this wording is wrong, that "subobject"
was intended only to refer to base subobjects.

But really this is beside the point: the x86 ABI says that the
alignment of double is 4, so alignof(double) should be 4 regardless of
what GCC wants to do internally.  And I think the same is true of


I don't have a view on what's more correct, but better alignment (pun
intended) with C's _Alignof seems good to me.

Reply via email to