From: Dan Carpenter <dan.carpenter@oracle.com>
To: linux-sparse@vger.kernel.org
Subject: handling C99 declarations after a case statement
Date: Fri, 12 Aug 2022 12:48:26 +0300 [thread overview]
Message-ID: <20220812094826.GL3438@kadam> (raw)
The kernel recently "moved to modern C99". https://lwn.net/Articles/885941/
We still have the -Wdeclaration-after-statement but one thing that we
can do now which trips up Sparse is declare variables immediately
after a case statement.
int x;
int test(void)
{
switch (x) {
case 4:
int a; <-- before you would have to add {} around this
break;
}
}
Sparse makes the "int a" into a STMT_EXPRESSION instead of a
STMT_DECLARATION and test-inspect doesn't like it:
$ ./test-inspect test.c
test.c:7:17: error: typename in expression
test.c:7:21: error: Expected ; at end of statement
test.c:7:21: error: got a
test.c:7:17: error: undefined identifier 'int'
This causes a Smatch warning as well about a statement without any
effect. The first code to trigger this was introduced in linux-next
yesterday.
regards,
dan carpenter
reply other threads:[~2022-08-12 9:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220812094826.GL3438@kadam \
--to=dan.carpenter@oracle.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).