2012-05-02 15:47:21

by Joe Korty

[permalink] [raw]
Subject: checkpatch: brackets around single statements fix

Checkpatch thinks '#else' is the same as 'else' in its check for
this error:

WARNING: braces {} are not necessary for single statement blocks

Signed-off-by: Joe Korty <[email protected]>

Index: linux/scripts/checkpatch.pl
===================================================================
--- linux.orig/scripts/checkpatch.pl 2012-04-17 05:00:37.000000000 -0400
+++ linux/scripts/checkpatch.pl 2012-05-02 10:29:03.000000000 -0400
@@ -3038,7 +3038,7 @@
}
}
if (!defined $suppress_ifbraces{$linenr - 1} &&
- $line =~ /\b(if|while|for|else)\b/) {
+ $line =~ /[^#]\b(if|while|for|else)\b/) {
my $allowed = 0;

# Check the pre-context.


2012-05-02 15:32:16

by Andy Whitcroft

[permalink] [raw]
Subject: Re: checkpatch: brackets around single statements fix

On Wed, May 02, 2012 at 11:10:46AM -0400, Joe Korty wrote:
> Checkpatch thinks '#else' is the same as 'else' in its check for
> this error:
>
> WARNING: braces {} are not necessary for single statement blocks
>
> Signed-off-by: Joe Korty <[email protected]>
>
> Index: linux/scripts/checkpatch.pl
> ===================================================================
> --- linux.orig/scripts/checkpatch.pl 2012-04-17 05:00:37.000000000 -0400
> +++ linux/scripts/checkpatch.pl 2012-05-02 10:29:03.000000000 -0400
> @@ -3038,7 +3038,7 @@
> }
> }
> if (!defined $suppress_ifbraces{$linenr - 1} &&
> - $line =~ /\b(if|while|for|else)\b/) {
> + $line =~ /[^#]\b(if|while|for|else)\b/) {
> my $allowed = 0;
>
> # Check the pre-context.

Interesting. Got an example I can use to add to the test suite.

-apw

2012-05-02 15:56:16

by Joe Korty

[permalink] [raw]
Subject: Re: checkpatch: brackets around single statements fix

On Wed, May 02, 2012 at 11:32:12AM -0400, Andy Whitcroft wrote:
> On Wed, May 02, 2012 at 11:10:46AM -0400, Joe Korty wrote:
> Interesting. Got an example I can use to add to the test suite.



Test case for scripts/checkpatch.pl: thinks '#else'
is the same as 'else', prints an error for brackets
around single statements.

Signed-off-by: Joe Korty <[email protected]>

--- /tmp/y.c 2012-05-02 11:53:28.000000000 -0400
+++ /tmp/x.c 2012-05-02 11:52:28.000000000 -0400
@@ -1,6 +1,10 @@
struct abc abc = {
{ a, "a " },
{ b, "b " },
+#ifdef CONFIG_REPURPOSE
+ { d, "d " },
+#else
{ c, "c " },
+#endif
{ },
};