https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80130
Bug ID: 80130 Summary: Wrong diagnostic: dereferencing type-punned pointer Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ahmad at a3f dot at Target Milestone: --- /* gcc -c -Wstrict-aliasing -fstrict-aliasing snippet.c */ union punu { char _Alignas(_Alignof(int)) buf[sizeof(int)]; int i; }; extern char _Alignas(_Alignof(int)) buf[sizeof(int)]; int main(void) { int i; /* (1) Warning: dereferencing type-punned pointer will break strict-aliasing rules */ i = *(int*)buf; /* (2) No warning */ union punu* u = (union punu*)buf; i = *(int*)u; /* (3) Warning: dereferencing type-punned pointer will break strict-aliasing rules */ i = *(int*)(union punu*)buf; return i; } On Compiler Explorer: https://godbolt.org/g/n13LRq Is (2) a permissible way to tell GCC that buf and i may share the same memory? In any case, (2) and (3) should exhibit the same behavior.