https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94337
Bug ID: 94337 Summary: Incorrect "dereferencing type-punned pointer will break strict-aliasing rules" warning Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- Consider the following example. #include <stdio.h> struct s1 { int a; }; struct s2 { int a, b; }; int main (void) { union { struct s1 m1[1]; struct s2 m2[1]; } u; (u.m2)->b = 17; printf ("%d\n", ((struct s2 *) (struct s1 *) u.m2)->b); printf ("%d\n", ((struct s2 *) u.m1)->b); return 0; } zira:~> gcc-10 tst.c -o tst -O2 -Wstrict-aliasing tst.c: In function ‘main’: tst.c:22:20: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 22 | printf ("%d\n", ((struct s2 *) u.m1)->b); | ~^~~~~~~~~~~~~~~~~~~ But there is no type-punning here. All accesses are done via struct s2. Everything else is pointer conversions, which are not related to the aliasing rules.