https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70195
Bug ID: 70195 Summary: GCC silently drops erroneous assignments in flexible arrays Product: gcc Version: 5.3.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: frederic.petrot at gmail dot com Target Milestone: --- Even though using flexible arrays and returning them through functions may not be the wisest thing to do, ... The following code compiles without warnings: typedef struct w { int x; int y[]; } w; w xy(int z) { w v; v.x = 3; v.y[0]=z; v.y[2]=z+1; v.y[11]=z+22; return v; } Interestingly enough, but as expected indeed, it produces different behaviors at asm level depending on the optimization level. Without optimization, it accesses the caller stack to mess it up, with optimization on, it simply sets the x field in the caller stack (mips) or returns it (x86).