https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102070
Bug ID: 102070 Summary: missing warning initializing aggregate member with itself Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- This is the C "subset" of pr97931. The test case shows that GCC diagnoses assigning an uninitialized member of an aggregate to itself but it fails to warn when the same happens as part of an initializer. $ cat z.c && gcc -S -Wall -Winit-self -fdump-tree-original=/dev/stdout z.c struct S { int i, j; }; void f (void*); void ga (void) { int a[2]; a[0] = a[0]; // -Wuninitialized (good) f (a); } void gs (void) { struct S s; s.i = s.i; // -Wuninitialized (good) f (&s); } void ha (void) { int a[2] = { [0] = a[0] }; // missing warning f (a); } void hs (void) { struct S s = { s.i }; // missing warning f (&s); } ;; Function ga (null) ;; enabled by -tree-original { int a[2]; int a[2]; a[0] = a[0]; f ((void *) &a); } ;; Function gs (null) ;; enabled by -tree-original { struct S s; struct S s; s.i = s.i; f ((void *) &s); } ;; Function ha (null) ;; enabled by -tree-original { int a[2] = {a[0]}; int a[2] = {a[0]}; f ((void *) &a); } ;; Function hs (null) ;; enabled by -tree-original { struct S s = {.i=s.i}; struct S s = {.i=s.i}; f ((void *) &s); } z.c: In function ‘ga’: z.c:8:11: warning: ‘a’ is used uninitialized [-Wuninitialized] 8 | a[0] = a[0]; // -Wuninitialized (good) | ~^~~ z.c:7:7: note: ‘a’ declared here 7 | int a[2]; | ^ z.c: In function ‘gs’: z.c:15:10: warning: ‘s.i’ is used uninitialized [-Wuninitialized] 15 | s.i = s.i; // -Wuninitialized (good) | ~^~ z.c:14:12: note: ‘s’ declared here 14 | struct S s; | ^