To verify, declare a POD type plus aligned attribute as a custom type. typedef struct S_ { short f[3]; } S __attribute__ ((aligned (8))); Then make an array of such type. S test[16]={}; Then the code won't compile, with "error: alignment of array elements is greater than element size". Basically the `__attribute__ ((aligned (8)));` left the size of such type unchanged, as opposed to including the alignment/padding in the size and violates the C standard that `sizeof` operator returns the storage size plus all necessary padding and maintain `sizeof(Type[N])==N*sizeof(Type)`. This error is added in 2005 ( https://gcc.gnu.org/ml/gcc-patches/2005-09/msg01853.html ) to prevent GCC from generating broken code, and is brought up again in a stackoverflow.com question (http://stackoverflow.com/questions/36211864/how-can-i-apply-attribute-aligned32-to-an-int) . Note that clang-3.8 does include the extra padding as the size and allow declaring arrays of extra-aligned types. This problem is verified on GCC 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1) and also here https://ideone.com/oxGyiN . If this bug is not to be fixed, please update the documentation (https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes) and mark it as a feature.
Confirmed as a documentation issue. Note that typedef struct S_ { short f[3] __attribute((aligned(8))); } S; works (and increases sizeof (S_)).
(In reply to Richard Biener from comment #1) > Confirmed as a documentation issue. Note that > > typedef struct S_ { short f[3] __attribute((aligned(8))); } S; > > works (and increases sizeof (S_)). So for a struct, aligning the first field of it is effectively aligning the struct. But that seems a variable attribute rather than type attribute, a very different usage. (as is documented here https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes). And for typedef int more_aligned_int __attribute__ ((aligned (8))); it's still an issue.