https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70921
Bug ID: 70921 Summary: Initializer for sub-sub-object overrides whole initializer for sub-object Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: ch3root at openwall dot com Target Milestone: --- Source code: ---------------------------------------------------------------------- #include <stdio.h> int main() { struct s { int x, y; } s1 = { 1, 2 }; struct { struct s sub; } s2 = { s1, .sub.y = 4 }; printf("%d %d\n", s2.sub.x, s2.sub.y); } ---------------------------------------------------------------------- Results: ---------------------------------------------------------------------- $ gcc -std=c11 -pedantic -Wall -Wextra example.c && ./a.out 0 4 ---------------------------------------------------------------------- gcc version: gcc (GCC) 7.0.0 20160502 (experimental) It seems wrong that the initializer for the .sub.y subsubobject overrides the previously listed initializer for the whole .sub subobject, loosing explicit initialization of .sub.x. The relevant rule -- C11, 6.7.9p19: "The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject". It doesn't seem to cover this example. But, at least, the lack of warnings from gcc is wrong. For comparison: ---------------------------------------------------------------------- $ clang -std=c11 -Weverything example.c && ./a.out example.c:6:43: warning: subobject initialization overrides initialization of other fields within its enclosing subobject [-Winitializer-overrides] struct { struct s sub; } s2 = { s1, .sub.y = 4 }; ^~~~~~ example.c:6:35: note: previous initialization is here struct { struct s sub; } s2 = { s1, .sub.y = 4 }; ^~ 1 warning generated. 1 4 ----------------------------------------------------------------------