when used with string initialization the size of nested struct flex array member was tested too late for < 0. GCC accepts but discards such initializers (the flex array member will become zero sized). TCC supports flex arrays members only in top-level structs and gives an error in this case.
Unified · Split
| @@ -8237,6 +8237,7 @@ static void decl_initializer(init_params *p, CType *type, unsigned long c, int f · 8236 unmodified lines | ||
| 8237 | 8237 | goto do_init_array; |
| 8238 | 8238 | } |
| 8239 | 8239 | |
| 8240 | + decl_design_flex(p, s, len); | |
| 8240 | 8241 | if (!(flags & DIF_SIZE_ONLY)) { |
| 8241 | 8242 | int nb = n; |
| 8242 | 8243 | if (len < nb) |
| @@ -8270,8 +8271,6 @@ static void decl_initializer(init_params *p, CType *type, unsigned long c, int f · 27 unmodified lines | ||
| 8270 | 8271 | init_putv(p, t1, c + i * size1); |
| 8271 | 8272 | } |
| 8272 | 8273 | } |
| 8273 | − } else { | |
| 8274 | − decl_design_flex(p, s, len); | |
| 8275 | 8274 | } |
| 8276 | 8275 | } else { |
| 8277 | 8276 | |
| @@ -354,6 +354,12 @@ struct c1 c1 = { 1, { 2, 3, 4 } }; · 353 unmodified lines | ||
| 354 | 354 | struct c2 { int c; struct c1 c1; }; |
| 355 | 355 | struct c2 c2 = { 1, { 2, { 3, 4, 5 }}}; |
| 356 | 356 | |
| 357 | +#elif defined test_var_array3 | |
| 358 | +/* similar to test_var_array2 but with string initializers */ | |
| 359 | +struct A { int a; char b[]; }; | |
| 360 | +struct A a = { 1, "1" }; | |
| 361 | +struct B { struct A a; }; | |
| 362 | +struct B b = { { 1, "1" } }; | |
| 357 | 363 | /******************************************************************/ |
| 358 | 364 | #elif defined test_default_int_type |
| 359 | 365 | n; // warn |
| @@ -166,20 +166,23 @@ bar : 3 ; 3 · 165 unmodified lines | ||
| 166 | 166 | [test_var_array2] |
| 167 | 167 | 60_errors_and_warnings.c:355: error: flexible array has zero size in this context |
| 168 | 168 | |
| 169 | +[test_var_array3] | |
| 170 | +60_errors_and_warnings.c:362: error: flexible array has zero size in this context | |
| 171 | + | |
| 169 | 172 | [test_default_int_type] |
| 170 | −60_errors_and_warnings.c:359: warning: type defaults to int | |
| 173 | +60_errors_and_warnings.c:365: warning: type defaults to int | |
| 171 | 174 | |
| 172 | 175 | [test_invalid_global_stmtexpr] |
| 173 | −60_errors_and_warnings.c:363: error: statement expression outside of function | |
| 176 | +60_errors_and_warnings.c:369: error: statement expression outside of function | |
| 174 | 177 | |
| 175 | 178 | [test_invalid_tokckill] |
| 176 | −60_errors_and_warnings.c:366: error: ';' expected (got "3") | |
| 179 | +60_errors_and_warnings.c:372: error: ';' expected (got "3") | |
| 177 | 180 | |
| 178 | 181 | [test_duplicate_member] |
| 179 | −60_errors_and_warnings.c:372: error: duplicate member 'a' | |
| 182 | +60_errors_and_warnings.c:378: error: duplicate member 'a' | |
| 180 | 183 | |
| 181 | 184 | [test_duplicate_member_anon] |
| 182 | −60_errors_and_warnings.c:385: error: duplicate member 'd' | |
| 185 | +60_errors_and_warnings.c:391: error: duplicate member 'd' | |
| 183 | 186 | |
| 184 | 187 | [test_conflicting_array_definition] |
| 185 | −60_errors_and_warnings.c:390: error: incompatible types for redefinition of 'array' | |
| 188 | +60_errors_and_warnings.c:396: error: incompatible types for redefinition of 'array' | |