https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65685

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There are two facets to this. GCC allows alignas with a weaker alignment on a
type, and ignores it. GCC also allows alignas with a weaker alignment on an
object declaration, and reduces the alignment. In both cases it would be
conforming to issue a warning, even if the current behaviour is retained.

struct alignas(8) S {};
struct alignas(2) U {
  S s;
}; // { dg-error "alignment" }

// This assertion passes, meaning the invalid alignas(2) was silently ignored.
static_assert( alignof(U) == alignof(S), "" );

alignas(1) S s;  // { dg-error "align" }
alignas(1) U u;  // { dg-error "align" }

#ifdef __GNUC__
// These assertions pass, so GCC honours the invalid alignas(1) requests.
static_assert( alignof(s) == 1, "GCC reduced alignment of s" ); // WRONG!
static_assert( alignof(u) == 1, "GCC reduced alignment of u" ); // WRONG!
#endif

Reply via email to