diff mbox series

[11/12] enum: warn on bad enums

Message ID 20180908000046.65842-12-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series fixes for enum's base type | expand

Commit Message

Luc Van Oostenryck Sept. 8, 2018, midnight UTC
During the parsing of enum definitions, if some invalid
type combination is reached, the base type is forced to
'bad_ctype'. Good.

However, this is done without a warning and it's only when
the enum is used that some sign of a problem may appear,
with no hint toward the true cause.

Fix this by issuing a warning when the base type becomes invalid.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/parse.c b/parse.c
index 3bccc6023..41d5fd93a 100644
--- a/parse.c
+++ b/parse.c
@@ -925,8 +925,10 @@  static struct token *parse_enum_declaration(struct token *token, struct symbol *
 				info(expr->pos, "   expected: %s", show_typename(base_type));
 				info(expr->pos, "        got: %s", show_typename(ctype));
 				base_type = &bad_ctype;
-			} else
+			} else if (base_type != &bad_ctype) {
+				sparse_error(token->pos, "bad enum definition");
 				base_type = &bad_ctype;
+			}
 			parent->ctype.base_type = base_type;
 		}
 		if (is_int_type(base_type)) {