https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72818
Bug ID: 72818 Summary: No warning for dereferencing casted pointer Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: pmatos at gcc dot gnu.org Target Milestone: --- GCC appropriately generates a warning for: void f(char c){*(unsigned*)&c=0;} $ gcc -Wall -fsanitize=undefined -Os -c -ocast1.s cast1.c cast1.c: In function âfâ: cast1.c:1:1: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] void f(char c){*(unsigned*)&c=0;} ^ $ But not for: void foo(unsigned char x){unsigned int *y=(unsigned int *)&x; *y=0x12345678;} $ gcc -Wall -fsanitize=undefined -Os -c -ocast.s cast.c $ It would seem this latter case should be caught and reported as well.