diff mbox

[8/9] enum: warn on bad enums

Message ID 20180509234853.20821-9-luc.vanoostenryck@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Luc Van Oostenryck May 9, 2018, 11:48 p.m. UTC
During the parsing of enums definition, 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 will be used that some sign of a problem will appear.

Fix this by issuing a warnings when the base type is set to bad.

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

Patch

diff --git a/parse.c b/parse.c
index 0b5524e5e..4e853d1b9 100644
--- a/parse.c
+++ b/parse.c
@@ -912,8 +912,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)) {