lkml.org 
[lkml]   [2012]   [Aug]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] checkpatch: Add control statement test to SINGLE_STATEMENT_DO_WHILE_MACRO
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


\
 
 \ /
  Last update: 2012-08-02 19:01    [from the cache]
©2003-2011 Jasper Spaans