From: Andy Whitcroft <apw@canonical.com>
To: Joe Perches <joe@perches.com>
Cc: Schrober <franzschrober@yahoo.de>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] checkpatch: Add control statement test to SINGLE_STATEMENT_DO_WHILE_MACRO
Date: Thu, 2 Aug 2012 17:23:22 +0100 [thread overview]
Message-ID: <20120802162322.GI2501@dm> (raw)
In-Reply-To: <1343921213.2011.9.camel@joe2Laptop>
On Thu, Aug 02, 2012 at 08:26:53AM -0700, Joe Perches wrote:
> The patch below is tested with:
> $ cat t.c
>
> #define bar_1(foo) \
> if (foo) \
> baz(); \
>
> #define bar_2(foo) \
> do { \
> if (foo) \
> baz(); \
> } while (0)
>
> #define bar_3(foo) \
> do { \
> baz(); \
> } while (0)
>
> #define bar_4(foo) \
> do { \
> baz(); \
> } while (0);
>
> #define bar_5(foo) \
> do { \
> while (foo) \
> baz(); \
> } while (0)
>
> #define bar_6(foo) \
> do { \
> switch (foo) { \
> case 1: \
> baz(); \
> } \
> } while (0)
>
> $
>
> So perhaps...
>
> scripts/checkpatch.pl | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 913d6bd..ca05ba2 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3016,7 +3016,8 @@ sub process {
> $herectx .= raw_line($linenr, $n) . "\n";
> }
>
> - if (($stmts =~ tr/;/;/) == 1) {
> + if (($stmts =~ tr/;/;/) == 1 &&
> + $stmts !~ /^\s*(if|while|for|switch)\b/) {
> WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
> "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
> }
>
>
Looks reasonable enough.
Acked-by: Andy Whitcroft <apw@canonical.com>
-apw
next prev parent reply other threads:[~2012-08-02 16:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-02 8:00 checkpatch.pl: Wrong check SINGLE_STATEMENT_DO_WHILE_MACRO Schrober
2012-08-02 14:20 ` Andy Whitcroft
2012-08-02 15:26 ` [PATCH] checkpatch: Add control statement test to SINGLE_STATEMENT_DO_WHILE_MACRO Joe Perches
2012-08-02 16:23 ` Andy Whitcroft [this message]
2012-08-02 16:44 ` Schrober
2012-08-02 22:10 ` Stephen Rothwell
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=20120802162322.GI2501@dm \
--to=apw@canonical.com \
--cc=akpm@linux-foundation.org \
--cc=franzschrober@yahoo.de \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.