RFC: C++ PATCH for c++/69763, making C++ alignof match C _Alignof

Jason Merrill jason@redhat.com
Tue Apr 10 17:13:00 GMT 2018


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
__alignof__.

Thoughts?
Jason
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 69763.diff
Type: text/x-patch
Size: 1053 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180410/eb4b95da/attachment.bin>


More information about the Gcc-patches mailing list