diff --git a/tccgen.c b/tccgen.c index d5b915b..ce76291 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2740,7 +2740,7 @@ static void parse_attribute(AttributeDef *ad) /* enum/struct/union declaration. u is either VT_ENUM or VT_STRUCT */ static void struct_decl(CType *type, int u, int tdef) { - int a, v, size, align, maxalign, c, offset; + int a, v, size, align, maxalign, c, offset, flexible; int bit_size, bit_pos, bsize, bt, lbit_pos, prevbt; Sym *s, *ss, *ass, **ps; AttributeDef ad; @@ -2814,7 +2814,11 @@ static void struct_decl(CType *type, int u, int tdef) prevbt = VT_INT; bit_pos = 0; offset = 0; + flexible = 0; while (tok != '}') { + if (flexible) + tcc_error("invalid type for '%s'", + get_tok_str(v, NULL)); parse_btype(&btype, &ad); while (1) { bit_size = -1; @@ -2824,6 +2828,13 @@ static void struct_decl(CType *type, int u, int tdef) type_decl(&type1, &ad, &v, TYPE_DIRECT | TYPE_ABSTRACT); if (v == 0 && (type1.t & VT_BTYPE) != VT_STRUCT) expect("identifier"); + if (type_size(&type1, &align) < 0) { + if ((type1.t & VT_ARRAY) && c) + flexible = 1; + else + tcc_error("field '%s' has incomplete type", + get_tok_str(v, NULL)); + } if ((type1.t & VT_BTYPE) == VT_FUNC || (type1.t & (VT_TYPEDEF | VT_STATIC | VT_EXTERN | VT_INLINE))) tcc_error("invalid type for '%s'",