summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-05-02 17:36:14 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-10-05 03:29:19 +0200
commit89e7785477a5270bba4e5f0b7b59c363659412f7 (patch)
treeea11f1fe7b60b4654c1b218c9c23ac8e984d926b
parentc7f7ccfcf1888965a0dcfccb4f4466ce22b3eeb9 (diff)
downloadsparse-89e7785477a5270bba4e5f0b7b59c363659412f7.tar.gz
enum: warn on bad enums
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 but only if the type of the enumerator is itself not already set to 'bad_ctype' (since it this case a more specific warning has already been issued). Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--parse.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index 3bccc602..50e298c7 100644
--- a/parse.c
+++ b/parse.c
@@ -910,7 +910,7 @@ static struct token *parse_enum_declaration(struct token *token, struct symbol *
* base type is at least "int_ctype".
* - otherwise the base_type is "bad_ctype".
*/
- if (!base_type) {
+ if (!base_type || ctype == &bad_ctype) {
base_type = ctype;
} else if (ctype == base_type) {
/* nothing */
@@ -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)) {