Skip to contentSkip to conversation

checkpatch: brackets around single statements fix

PATCH Joe Korty 2 participants 3 messages May 2, 2012 Checkpatch

lore
Share & tools
lore

Joe Korty

author
#0 lore raw

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

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

scripts/checkpatch.pl +1 -1
Index: linux/scripts/checkpatch.pl
===================================================================
@@ -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.
maintainer
#1 lore raw
Quoted 12 lines · Joe Korty

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

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

Index: linux/scripts/checkpatch.pl
===================================================================

scripts/checkpatch.pl line 3044

Quoted 8 lines
scripts/checkpatch.pl +1 -1
@@ -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

author
#2 lore raw
Quoted 2 lines · Andy Whitcroft

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.

tmp/x.c renamed from tmp/y.c +4 -0
@@ -1,6 +1,10 @@
 struct abc abc = {
 	{ a, "a " },
 	{ b, "b " },
+#ifdef CONFIG_REPURPOSE
+	{ d, "d " },
+#else
 	{ c, "c " },
+#endif
 	{ },
 };