https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107274
Bug ID: 107274 Summary: Incorrect -Wuninitialized on indexed initialization Product: gcc Version: 12.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: keegan at undefinedbehaviour dot org Target Milestone: --- Given: void example(unsigned long val) { unsigned char b[4]; b[0] = val; b[1] = val >> 8; b[2] = val >> 16; b[3] = val >> 24; val = *(unsigned long *)b; } GCC 12.2 issues the following (incorrect) diagnostic: issue.c: In function 'example': issue.c:11:13: warning: 'b' is used uninitialized [-Wuninitialized] 11 | val = *(unsigned long *)b; | ~~~~^~~~~~~~~~~~~~~~~~~~~ issue.c:4:23: note: 'b' declared here 4 | unsigned char b[4]; | ^ Instead this code is correct in that it initializes all fields of "b". It appears the cast indirection is what is causing the issue, because I cannot get the diagnostic to be issued for other uses.