Commit 6ab3a970 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: improve "no space is necessary after a cast" test

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: default avatarJoe Perches <joe@perches.com>
Reported-by: default avatarMarek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d43698e8
...@@ -2552,8 +2552,15 @@ sub process { ...@@ -2552,8 +2552,15 @@ sub process {
} }
} }
if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && # check for space after cast like "(int) foo" or "(struct foo) bar"
(!defined($1) || $1 !~ /sizeof\s*/)) { # 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", if (CHK("SPACING",
"No space is necessary after a cast\n" . $herecurr) && "No space is necessary after a cast\n" . $herecurr) &&
$fix) { $fix) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment