From fc05a07d20b7c5baf312faaab46247d9057233b1 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 13 Apr 2024 21:21:18 -0700 Subject: decl: Include offending struct member in error messages --- decl.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/decl.c b/decl.c index 655e4b9..1fc57af 100644 --- a/decl.c +++ b/decl.c @@ -777,16 +777,16 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, un size_t end; if (t->flexible) - error(&tok.loc, "struct has member after flexible array member"); + error(&tok.loc, "struct has member '%s' after flexible array member", name); if (mt.type->incomplete) { if (mt.type->kind != TYPEARRAY) - error(&tok.loc, "struct member has incomplete type"); + error(&tok.loc, "struct member '%s' has incomplete type", name); t->flexible = true; } if (mt.type->kind == TYPEFUNC) - error(&tok.loc, "struct member has function type"); + error(&tok.loc, "struct member '%s' has function type", name); if (mt.type->flexible) - error(&tok.loc, "struct member contains flexible array member"); + error(&tok.loc, "struct member '%s' contains flexible array member", name); assert(mt.type->align > 0); if (name || width == -1) { m = xmalloc(sizeof(*m)); @@ -804,7 +804,7 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, un m->bits.after = 0; if (align < mt.type->align) { if (align) - error(&tok.loc, "specified alignment of struct member is less strict than is required by type"); + error(&tok.loc, "specified alignment of struct member '%s' is less strict than is required by type", name); align = b->pack ? 1 : mt.type->align; } if (t->kind == TYPESTRUCT) { @@ -818,15 +818,15 @@ addmember(struct structbuilder *b, struct qualtype mt, char *name, int align, un b->bits = 0; } else { /* bit-field */ if (!(mt.type->prop & PROPINT)) - error(&tok.loc, "bit-field has invalid type"); + error(&tok.loc, "bit-field '%s' has invalid type", name); if (align) - error(&tok.loc, "alignment specified for bit-field"); + error(&tok.loc, "alignment specified for bit-field '%s'", name); if (b->pack) - error(&tok.loc, "bit-field in packed struct is not supported"); + error(&tok.loc, "bit-field '%s' in packed struct is not supported", name); if (!width && name) - error(&tok.loc, "bit-field with zero width must not have declarator"); + error(&tok.loc, "bit-field '%s' with zero width must not have declarator", name); if (width > mt.type->size * 8) - error(&tok.loc, "bit-field exceeds width of underlying type"); + error(&tok.loc, "bit-field '%s' exceeds width of underlying type", name); align = mt.type->align; if (t->kind == TYPESTRUCT) { /* calculate end of the storage-unit for this bit-field */ -- cgit v1.2.3