[PATCH 3/3] warn on empty initializations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently sparse accepts an empty initialization like:
	int a = ;

Make this an error.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 parse.c                        | 5 ++++-
 validation/empty-initializer.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/parse.c b/parse.c
index a9222e7cbf08..d0a41b14b914 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 0ca763f699a0..950679991401 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 ';'
-- 
2.27.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux