From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 3/3] warn on empty initializations
Date: Tue, 14 Jul 2020 02:00:30 +0200 [thread overview]
Message-ID: <20200714000030.85886-4-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20200714000030.85886-1-luc.vanoostenryck@gmail.com>
Currently sparse accepts an empty initialization like:
int a = ;
Make this an error.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
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
prev parent reply other threads:[~2020-07-14 0:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-14 0:00 [PATCH 0/3] warn on empty expressions Luc Van Oostenryck
2020-07-14 0:00 ` [PATCH 1/3] add testcase for incorrect " Luc Van Oostenryck
2020-07-14 0:00 ` [PATCH 2/3] warn on empty assignments Luc Van Oostenryck
2020-07-14 0:00 ` Luc Van Oostenryck [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200714000030.85886-4-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).