From 14b55d27ee7d577be66c60a457f0e80a28ef274d Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sat, 11 Jul 2020 15:45:15 +0200 Subject: warn on empty initializations Currently sparse accepts an empty initialization like: int a = ; Make this an error. Signed-off-by: Luc Van Oostenryck --- parse.c | 5 ++++- validation/empty-initializer.c | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/parse.c b/parse.c index a9222e7c..d0a41b14 100644 --- a/parse.c +++ b/parse.c @@ -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 ';' -- cgit 1.2.3-korg