Hi! This patch fixes -Woverride-init. IMHO we don't want to ever warn from within set_nonincremental_init, which moves over values from the constructor_elements vector to constructor_pending_elts AVL. The reason for that is that when switching from the non-incremental mode where values only live in the AVL tree to incremental, we don't remove values from the AVL tree, just copy them to the vector. So, if we go from non-incremental to incremental and back to non-incremental, we warn on all the values that are "added" to the AVL tree while already there, unless we call add_pending_init with IMPLICIT = true as done in this patch.
When we actually want to warn, IMHO we are always in the non-incremental mode, because if we are in incremental mode, we switch to non-incremental mode first if not writing to the next unfilled field, and the next unfilled field can't be present in the AVL, otherwise it would be filled already. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7? 2012-04-19 Jakub Jelinek <ja...@redhat.com> PR c/52880 * c-typeck.c (set_nonincremental_init, set_nonincremental_init_from_string): Pass true instead of false as IMPLICIT to add_pending_init. * gcc.dg/pr52880.c: New test. --- gcc/c-typeck.c.jj 2012-04-19 11:09:13.000000000 +0200 +++ gcc/c-typeck.c 2012-04-19 13:21:15.642080390 +0200 @@ -7597,7 +7597,7 @@ set_nonincremental_init (struct obstack FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value) { - add_pending_init (index, value, NULL_TREE, false, + add_pending_init (index, value, NULL_TREE, true, braced_init_obstack); } constructor_elements = 0; @@ -7690,7 +7690,7 @@ set_nonincremental_init_from_string (tre } value = build_int_cst_wide (type, val[1], val[0]); - add_pending_init (purpose, value, NULL_TREE, false, + add_pending_init (purpose, value, NULL_TREE, true, braced_init_obstack); } --- gcc/testsuite/gcc.dg/pr52880.c.jj 2012-04-19 14:55:14.942948973 +0200 +++ gcc/testsuite/gcc.dg/pr52880.c 2012-04-19 14:54:55.000000000 +0200 @@ -0,0 +1,10 @@ +/* PR c/52880 */ +/* { dg-do compile } */ +/* { dg-options "-Woverride-init" } */ + +struct A { int a; int b; }; +struct B { struct A c; int d, e; }; +struct B f = { .c.a = 0, .e = 1, .d = 2, .c.b = 3 }; +struct C { int g; int h; }; +struct D { int i; struct C j; int k; }; +struct D l = { .j.g = 0, .k = 1, .i = 2, .j.h = 3 }; Jakub