Reputation: 10911
According to cppreference.com
Specifies the alignment requirement of a type or an object.
alignas( expression )
alignas( type-id )
alignas( pack ... )
alignas(expression)
must be an integral constant expression that evaluates to zero, or to a valid value for an alignment or extended alignment.
Equivalent to alignas(alignof(type))
Equivalent to multiple alignas specifiers applied to the same declaration, one for each member of the parameter pack, which can be either type or non-type parameter pack.
So why don't the following work for g++, clang or VC++?
struct alignas(1, 4) A {};
or
struct alignas(int, double) A {};
Is this a defect?
Apparently this works for g++ 8.2 and not for clang++ 8.0 or VC++ 19.20.27508.1 so seems to be a defect, and the compilers haven't caught up.
Apparently, running MinGW's g++ compiler in a cygwin bash shell causes weird behaviour. Works fine when running in a MinGW's bash shell. So, no, this doesn't work under g++ 8.2 either.
Upvotes: 5
Views: 842
Reputation: 171167
1, 4
or int, double
are not parameter packs. This would be an example of a parameter pack used in this context:
template <class... T>
struct Widget
{
struct alignas(T...) A {};
};
Note that it's possible to apply multiple alignas
specifiers to the same declaration, so your examples can be written as alignas(1) alignas(4)
and alignas(int) alignas(double)
respectively.
Upvotes: 2