<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 22, 2014 at 4:10 PM, jahanian <span dir="ltr"><<a href="mailto:fjahanian@apple.com" target="_blank">fjahanian@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div class=""><div>On Jul 22, 2014, at 3:58 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 22, 2014 at 1:03 PM, jahanian <span dir="ltr"><<a href="mailto:fjahanian@apple.com" target="_blank">fjahanian@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Implementation says that it is intentional:<div><br></div><div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(0,132,0)">
<span> </span>// The maximum field alignment overrides the aligned attribute.</div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(79,129,135)"><span> </span><span style="color:#bb2ca2">if</span><span> (!</span>MaxFieldAlignment<span>.</span><span style="color:#31595d">isZero</span><span>()) {</span></div>
<div style="margin:0px;font-size:11px;font-family:Menlo"> FieldAlign = <span style="color:#703daa">std</span>::<span style="color:#3d1d81">min</span>(FieldAlign, <span style="color:#4f8187">MaxFieldAlignment</span>);</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"> UnpackedFieldAlign = <span style="color:#703daa">std</span>::<span style="color:#3d1d81">min</span>(UnpackedFieldAlign, <span style="color:#4f8187">MaxFieldAlignment</span>);</div>
<div style="margin:0px;font-size:11px;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;font-family:Menlo">- Fariborz</div></div></div></blockquote><div><br></div><div>I too find this very surprising. Does this match GCC / MSVC behavior for #pragma pack? I don't think it matches __attribute__((packed)).</div>
</div></div></div></blockquote><div><br></div></div>I don’t have access to GCC. But MSVC’s behavior takes into account current pack setting and enforces alignas() of the field.</div></div></blockquote><div><br></div><div>
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.</div>
<div><br></div><div>Also, Clang does respect alignas in this case when targeting the Microsoft C++ ABI.</div></div></div></div>