diff options
author | Michael Forney <mforney@mforney.org> | 2021-07-01 01:51:42 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2021-07-01 01:52:13 -0700 |
commit | b4f89ba90b6ca3233cc80aef9d42055266fac8df (patch) | |
tree | 97cacdf57fd04ae584578ece56ec9c65383977dc /decl.c | |
parent | eb4320fcc6caf885038fe8b7b7d33ed87eb56608 (diff) |
decl: Check that the flexible array member (if present) is last
Diffstat (limited to 'decl.c')
-rw-r--r-- | decl.c | 12 |
1 files changed, 9 insertions, 3 deletions
@@ -685,11 +685,17 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, ui struct member *m; size_t end; - /* XXX: flexible array member must be last */ - if (mt.type->incomplete && mt.type->kind != TYPEARRAY) - error(&tok.loc, "struct member '%s' has incomplete type", name); + if (t->flexible) + error(&tok.loc, "struct member '%s' is after flexible array member", name); + if (mt.type->incomplete) { + if (mt.type->kind != TYPEARRAY) + error(&tok.loc, "struct member '%s' has incomplete type", name); + t->flexible = true; + } if (mt.type->kind == TYPEFUNC) error(&tok.loc, "struct member '%s' has function type", name); + if (mt.type->flexible) + error(&tok.loc, "struct member '%s' contains flexible array member", name); assert(mt.type->align > 0); if (name || width == -1) { m = xmalloc(sizeof(*m)); |