https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79024
--- Comment #4 from Xidorn Quan <gnu-9fbaow at upsuper dot org> --- (In reply to Jonathan Wakely from comment #3) > (In reply to Xidorn Quan from comment #2) > > That's interesting. But I > > think developers (I mean, users of compilers) are generally more interested > > on alignment requirement in struct rather than that for ABI, and most > > description of the concept "alignment" refers to that in struct, so it is > > probably better make alignof / alignas report that value. > > It's arguable whether that would be standard conforming. alignas(T) tells > you the alignment needed for an obejct of type T. The standard says "Object types have alignment requirements (3.9.1, 3.9.2) which place restrictions on the addresses at which an object of that type may be allocated." (3.11.1) I think it indicates that the alignment requirement is something that an object of type must always be aligned to, which, in case of 64bit integers on 32bit platform, should be 4 bytes instead of 8 bytes, since you do place them on non-8byte aligned addresses. > If you want the alignment > for a subobject of type T that's a different question, and you can get it by > doing: > > struct S { T t; }; > alignas(S) This is not always doable. Sometimes you may want to get alignment of an abstract class, which you cannot put in a struct. And in Mozilla's codebase, I do see this kind of usages. (We currently have a macro for doing alignment query which uses similiar technique, and when I tried to use that macro in our internal aligned_storage equivalent, it fails to compile due to those usages.) It is doable, though, via using a more complicated helper template to handle primitives and classes separately. But I still think this is something should be fixed.