alignas and clang
Thomas Stüfe
thomas.stuefe at gmail.com
Mon Mar 6 14:18:56 UTC 2023
Hi,
I'm not sure if this has been discussed before. With alignas, on clang, if
the natural type of the data has a larger alignment than what I requested
with alignas, I get a compile error if the specified alignment is smaller
than what would be the natural alignment of the type.
Example:
struct alignas(2) XX {
void* p;
};
gives: error: requested alignment is less than minimum alignment of 8 for
type 'XX'
Happens on both MacOS and Linux clang build. Does not happen with GCC. Does
not happen with ATTRIBUTE_ALIGN(2).
Is this a clang bug? The standard [1] says:
"The object or the type declared by such a declaration will have its
alignment requirement equal to the strictest (largest) non-zero expression
of all alignas specifiers used in the declaration, unless it would weaken
the natural alignment of the type. "
That reads to me like gcc is correct.
This is a bit of a drawback compared to ATTRIBUTE_ALIGN, especially if
coding for different 32-bit and 64-bit platforms.
[1] https://en.cppreference.com/w/cpp/language/alignas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/hotspot-dev/attachments/20230306/1d46cf1d/attachment-0001.htm>
More information about the hotspot-dev
mailing list