alignas and clang

Kim Barrett kim.barrett at oracle.com
Tue Mar 7 01:38:39 UTC 2023


> On Mar 6, 2023, at 12:58 PM, Thomas Stüfe <thomas.stuefe at gmail.com> wrote:
> On Mon, Mar 6, 2023 at 5:23 PM Julian Waters <tanksherman27 at gmail.com> wrote:
> Ahhh, I see what you mean. Seems to me that this may actually be compiler dependent, since C++14 simply states such situations are ill-formed and makes no promises of instead choosing the larger alignment when this happens.
> 
> Oh, you are right, I stopped reading before it got interesting.
> 
> "If the strictest (largest) alignas on a declaration is weaker than the alignment it would have without any alignas specifiers (that is, weaker than its natural alignment or weaker than alignas on another declaration of the same object or type), the program is ill-formed."
> 
> Never mind then, I'll find a different solution.

It looks like you found the explanation for the error.

In case you forgot or hadn’t noticed, a solution is to use multiple `alignas` attributes for the declaration,
and include one which provides the “natural” alignment.  There’s even an example of doing this in the
standard - C++14 7.6.2/7.

So you could add `alignas(void*)` to the alignment specifiers in the example.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <https://mail.openjdk.org/pipermail/hotspot-dev/attachments/20230307/3f7361c5/signature-0001.asc>


More information about the hotspot-dev mailing list