From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org,
Dan Carpenter <dan.carpenter@oracle.com>,
Marek Lindner <mareklindner@neomailbox.ch>
Subject: [PATCH] checkpatch: Improve "no space is necessary after a cast" test
Date: Fri, 20 Feb 2015 11:52:35 -0800 [thread overview]
Message-ID: <1424461955.18211.15.camel@perches.com> (raw)
In-Reply-To: <7679509.IB7arj1Sb8@voltaire>
The "no space is necessary after a cast" sizeof exclusion
doesn't work properly.
The test reports a false positive for code like:
BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6);
Make it work, simplify the exclusions, and add some comments.
Signed-off-by: Joe Perches <joe@perches.com>
Reported-by: Marek Lindner <mareklindner@neomailbox.ch>
---
scripts/checkpatch.pl | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d124359..2898e49 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2552,9 +2552,16 @@ sub process {
}
}
- if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ &&
- (!defined($1) || $1 !~ /sizeof\s*/)) {
- if (CHK("SPACING",
+# check for space after cast like "(int) foo" or "(struct foo) bar"
+# avoid checking a few false positives:
+# "sizeof(<type>)" or "__alignof__(<type>)"
+# function pointer declarations like "(*foo)(int) = bar;"
+# structure definitions like "(struct foo) { 0 };"
+# multiline macros that define functions
+# known attributes or the __attribute__ keyword
+ if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
+ (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
+ if (CHK("SPACING",
"No space is necessary after a cast\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~
prev parent reply other threads:[~2015-02-20 19:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-19 5:35 checkpatch: CHECK: No space is necessary after a cast Marek Lindner
2015-02-19 19:55 ` Joe Perches
2015-02-20 11:56 ` [B.A.T.M.A.N.] " Marek Lindner
2015-02-20 19:52 ` Joe Perches [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=1424461955.18211.15.camel@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=dan.carpenter@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mareklindner@neomailbox.ch \
/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