https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69560
Bug ID: 69560 Summary: x86_64: alignof(uint64_t) produces incorrect results with -m32 Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: david.merillat at gmail dot com Target Milestone: --- Sample Program (test.cpp): ####################################################################### #include <cstdint> #include <cstdio> #include <cstddef> using namespace std; typedef struct { int32_t i32; int64_t i64; } DefaultStruct; typedef struct { int32_t i32; int64_t i64 __attribute__((aligned(8))); } AlignedStruct; int main(void) { DefaultStruct s; printf( "DefaultStruct: offset=%d, struct align=%d, member align=%d, type align=%d\n", offsetof(DefaultStruct,i64), alignof(s), alignof(s.i64), alignof(int64_t) ); AlignedStruct s2; printf( "AlignedStruct: offset=%d, struct align=%d, member align=%d, type align=%d\n", offsetof(AlignedStruct,i64), alignof(s2), alignof(s2.i64), alignof(int64_t) ); return 0; } ##################################################### Compile command line: g++ -m32 --std=c++14 test.cpp -o test ##################################################### Expected program output: DefaultStruct: offset=4, struct align=4, member align=4, type align=4 AlignedStruct: offset=8, struct align=8, member align=8, type align=8 ##################################################### Actual program output: DefaultStruct: offset=4, struct align=4, member align=4, type align=8 AlignedStruct: offset=8, struct align=8, member align=8, type align=8 ##################################################### Comments: Note that the difference is alignof(uint64_t) returns 8, while the correct value appears to be 4. I checked the ISO C++ spec, section 3.11, and it says "The alignment requirement of a complete type can be queried using an alignof expression", so if alignof(int64_t) yields 8, then it shouldn't be legal to place an int64_t at offset 4 in a structure. Disclaimer: I checked the draft specification. I don't have $212 lying around to purchase the final spec. This is a possible duplicate with 61053 or 61447, however 61053 doesn't deal with the output of alignof(), and 61447 has been suspended because the standards were ambiguous. Here they seem more clear-cut.