diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-11 15:45:15 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-07-14 01:27:55 +0200 |
commit | 14b55d27ee7d577be66c60a457f0e80a28ef274d (patch) | |
tree | 8f495b4acdb25f4c0139503cb3492f9aed17936d | |
parent | 584bf4cd77d422d7f057c9ed167f824955a3c311 (diff) | |
download | sparse-14b55d27ee7d577be66c60a457f0e80a28ef274d.tar.gz |
warn on empty initializations
Currently sparse accepts an empty initialization like:
int a = ;
Make this an error.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | parse.c | 5 | ||||
-rw-r--r-- | validation/empty-initializer.c | 1 |
2 files changed, 4 insertions, 2 deletions
@@ -3117,7 +3117,10 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis for (;;) { if (!is_typedef && match_op(token, '=')) { - token = initializer(&decl->initializer, token->next); + struct token *next = token->next; + token = initializer(&decl->initializer, next); + if (token == next) + sparse_error(token->pos, "expression expected before '%s'", show_token(token)); } if (!is_typedef) { if (validate_decl) diff --git a/validation/empty-initializer.c b/validation/empty-initializer.c index 0ca763f6..95067999 100644 --- a/validation/empty-initializer.c +++ b/validation/empty-initializer.c @@ -2,7 +2,6 @@ static int i = ; // KO /* * check-name: empty-initializer - * check-known-to-fail * * check-error-start empty-initializer.c:1:16: error: expression expected before ';' |