[cfe-dev] c++11's alignas() ignored inside #pragma pack

Reid Kleckner rnk at google.com
Tue Jul 22 17:26:00 PDT 2014


On Tue, Jul 22, 2014 at 4:10 PM, jahanian <fjahanian at apple.com> wrote:

>
> On Jul 22, 2014, at 3:58 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>
> On Tue, Jul 22, 2014 at 1:03 PM, jahanian <fjahanian at apple.com> wrote:
>
>> Implementation says that it is intentional:
>>
>>   // The maximum field alignment overrides the aligned attribute.
>>   if (!MaxFieldAlignment.isZero()) {
>>     FieldAlign = std::min(FieldAlign, MaxFieldAlignment);
>>     UnpackedFieldAlign = std::min(UnpackedFieldAlign, MaxFieldAlignment);
>>   }
>> - Fariborz
>>
>
> I too find this very surprising. Does this match GCC / MSVC behavior for
> #pragma pack? I don't think it matches __attribute__((packed)).
>
>
> I don’t have access to GCC. But MSVC’s behavior takes into account current
> pack setting and enforces  alignas() of the field.
>

Presumably they handle alignas the same way they handle
__declspec(align(N)), which overrides packing.  MSVC appears to have two
notions of alignment, required and advisory, while the C++ standard, Clang,
and GCC only have one.  One way to observe this is to see that they will
align an int64 to 8 bytes in a struct, but they will not realign the stack
to 8 bytes when that struct is stack allocated.

Also, Clang does respect alignas in this case when targeting the Microsoft
C++ ABI.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140722/50dffe73/attachment.html>


More information about the cfe-dev mailing list