[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-trivial] [PATCH v2 7/7] checkpatch: Enforce proper do/while (0) st

From: Eric Blake
Subject: [Qemu-trivial] [PATCH v2 7/7] checkpatch: Enforce proper do/while (0) style
Date: Fri, 1 Dec 2017 17:24:33 -0600

Use of a loop construct for code that is not intended to repeat
does not make much idiomatic sense, except in one place: it is a
common usage in macros in order to wrap arbitrary code with
single-statement semantics.  But when used in a macro, it is more
typical for the caller to supply the trailing ';' when calling
the macro.

Although qemu coding style frowns on bare:
  if (cond)
where extra semicolons actually cause syntax errors, we still
want our macro styles to be easily copied to other projects.
Thus, declare it an error if we encounter any form of 'while (0)'
with a semicolon in the same line.

Signed-off-by: Eric Blake <address@hidden>
 scripts/checkpatch.pl | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 34df753571..27800a4ed9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1622,6 +1622,11 @@ sub process {

+# 'do ... while (0/false)' only makes sense in macros, without trailing ';'
+               if ($line =~ /while\s*\((0|false)\);/) {
+                       ERROR("suspicious ; after while (0)\n" . $herecurr);
+               }
 # Check relative indent for conditionals and blocks.
                if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ 
/^.\s*#/ && $line !~ /\}\s*while\s*/) {
                        my ($s, $c) = ($stat, $cond);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]