Since error_init doesn't have a location parameter, all of these invalid initializers have wrong column info in diagnostics. /* -std=gnu99 -fshort-enums -fshort-wchar -pedantic */ typedef enum { A } schar; extern int e; struct S { int a[3]; }; struct f { int w; int x[]; }; struct g { struct f f; }; char w1[] = L"foo"; __WCHAR_TYPE__ w2[] = "foo"; __WCHAR_TYPE__ w3[] = U "foo"; schar a1[] = "foo"; int a2[] = (int[]) { 1 }; int a3 = e; int a4 = (e, 1); int a5 = a1[0]; int a6 = &a3 - &a4; int a7[] = a7; struct S s = { {1}, {3} }; struct g g1 = { {0, {1}} }; struct g g2 = { .f[0] = 1 }; __extension__ int a8 = { }; int a9[10] = {[1.2] = 2 }; int a10[10] = {[e] = 2 }; __extension__ int a11[10] = {[1 ... e] = 1 }; int a12 = {[1] = 2 }; int a13[2] = {[-1] = 4 }; int a14[2] = {[64] = 4 }; __extension__ int a15[10] = {[2 ... 1] = 4 }; __extension__ int a16[10] = {[2 ... 100] = 4 }; int a17[] = { .B = 1 }; int a18[] = { e }; char a19[1] = { "x", "x" }; void bar (void) { struct f f = { 2, "c" }; }
Another testcase: struct s { char c[1]; }; extern struct s foo (void); void bar (void) { char *t = (foo ()).c; }
Another testcase: struct { char *v; } s[] = { .v = 0 };
Note that there are 3 error_init calls that seem unreachable (?): 6783 6784 if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) 6785 { 6786 error_init ("variable-sized object may not be initialized"); 6787 return error_mark_node; 6788 } 7491 else if (vec_safe_length (constructor_elements) != 1) 7492 { 7493 error_init ("extra elements in scalar initializer"); 7494 ret.value = (*constructor_elements)[0].value; 7495 } 8590 if (constructor_stack->replacement_value.value != 0) 8591 { 8592 error_init ("excess elements in struct initializer"); 8593 return; 8594 }
Author: mpolacek Date: Fri May 9 17:50:25 2014 New Revision: 210280 URL: http://gcc.gnu.org/viewcvs?rev=210280&root=gcc&view=rev Log: PR c/61096 * c-parser.c (c_parser_braced_init): Pass brace_loc to push_init_level. (c_parser_initelt): Pass location to set_init_label. Pass array index location to set_init_index. * c-tree.h (push_init_level): Update declaration. (pop_init_level): Likewise. (set_init_index): Likewise. (set_init_label): Likewise. * c-typeck.c (error_init): Add location parameter. Call error_at instead of error. (digest_init): Pass init_loc to error_init. (really_start_incremental_init): (push_init_level): Add location parameter. Pass loc to pop_init_level and error_init. (pop_init_level): Likewise. (set_designator): Add location parameter. Pass loc to pop_init_level, push_init_level, and error_init. (set_init_index): Add location parameter. Pass loc to error_init and set_designator. (set_init_label): Likewise. (output_init_element): Pass loc to error_init. (process_init_element): Pass loc to error_init, pop_init_level, pedwarn_init, and push_init_level. * gcc.dg/pr61096-1.c: New test. * gcc.dg/pr61096-2.c: New test. Added: trunk/gcc/testsuite/gcc.dg/pr61096-1.c trunk/gcc/testsuite/gcc.dg/pr61096-2.c Modified: trunk/gcc/c/ChangeLog trunk/gcc/c/c-parser.c trunk/gcc/c/c-tree.h trunk/gcc/c/c-typeck.c trunk/gcc/testsuite/ChangeLog
Fixed.