diff --git a/tccgen.c b/tccgen.c index 2ee91a76..b7e0fcfc 100644 --- a/tccgen.c +++ b/tccgen.c @@ -6783,13 +6783,14 @@ static int decl_designator(CType *type, Section *sec, unsigned long c, c += index * elem_size; nb_elems = index_last - index + 1; } else { - int cumofs = 0; + int cumofs; next(); l = tok; struct_field: next(); if ((type->t & VT_BTYPE) != VT_STRUCT) expect("struct/union type"); + cumofs = 0; f = find_field(type, l, &cumofs); if (!f) expect("field"); diff --git a/tests/tests2/90_struct-init.c b/tests/tests2/90_struct-init.c index 48401c1d..ade7fad7 100644 --- a/tests/tests2/90_struct-init.c +++ b/tests/tests2/90_struct-init.c @@ -175,6 +175,12 @@ void foo (struct W *w, struct pkthdr *phdr_) struct T lt2 = { { [1 ... 5] = 9, [6 ... 10] = elt, [4 ... 7] = elt+1 }, 1 }; struct SSU lssu1 = { 5, 3 }; struct SSU lssu2 = { .y = 5, .x = 3 }; + /* designated initializers in GNU form */ +#if defined(__GNUC__) || defined(__TINYC__) + struct S ls4 = {a: 1, b: 2, c: {3, 4}}; +#else + struct S ls4 = {.a = 1, .b = 2, .c = {3, 4}}; +#endif print(ls); print(ls2); print(lt); @@ -194,6 +200,7 @@ void foo (struct W *w, struct pkthdr *phdr_) print(lssu1); print(lssu2); print(flow); + print(ls4); } #endif diff --git a/tests/tests2/90_struct-init.expect b/tests/tests2/90_struct-init.expect index 46248afa..c55cb476 100644 --- a/tests/tests2/90_struct-init.expect +++ b/tests/tests2/90_struct-init.expect @@ -39,6 +39,7 @@ lt2: 0 9 9 9 43 43 43 43 42 42 42 0 0 0 0 0 1 lssu1: 5 0 0 0 3 0 0 0 lssu2: 5 0 0 0 3 0 0 0 flow: 9 8 7 6 0 0 0 0 0 0 0 0 0 0 0 0 6 5 4 3 0 0 0 0 0 0 0 0 0 0 0 0 +ls4: 1 2 3 4 one two three