From: Andreas Mohr <andi@lisas.de>
To: Joe Perches <joe@perches.com>
Cc: Alfonso Lima <alfonsolimaastor@gmail.com>,
apw@canonical.com, linux-kernel@vger.kernel.org
Subject: Re: [bug report] checkpatch: if statement does not need to be enclosed in parentheses
Date: Sun, 9 Apr 2017 10:55:31 +0200 [thread overview]
Message-ID: <20170409085531.GA26418@rhlx01.hs-esslingen.de> (raw)
In-Reply-To: <1491672799.3250.41.camel@perches.com>
On Sat, Apr 08, 2017 at 10:33:19AM -0700, Joe Perches wrote:
> On Sat, 2017-04-08 at 17:07 +0100, Alfonso Lima wrote:
> > Hi,
> >
> > In current linux-next, if you run the script on this piece of
> > code:
> >
> > #define FOO(a) \
> > if (a) { \
> > something(); \
> > something_else(); \
> > }
> >
> > You should get:
> >
> > ERROR: Macros with complex values should be enclosed in parentheses
> > #1: FILE: foo.c:1:
> > +#define FOO(a) \
> > + if (a) { \
> > + something(); \
> > + something_else(); \
> > + }
> >
> > We could silence checkpatch.pl using "do {} while ()" around the
> > if statement. However, the "if () {}" statement should be
> > enough. If someone could confirm this, I'll go and fix it.
>
> Multiple if/else use is the reason do {} while (0) is suggested.
>
> if (bar())
> FOO(a);
> else
> baz(b);
>
So, if I read this right checkpatch.pl is generating a correct complaint
in this case after all?
However, then we seem to have the following issues remaining:
- "Macros with complex values should be enclosed in parentheses" != "do {} while (0) is suggested" --> this is an imprecision which may cause confusion
- *further* cases of this issue occurring may just as well suggest again
"fixing" (i.e., "damaging") checkpatch.pl rather than
simply obeying (following through on) its correct diagnosis
--> checkpatch.pl behaviour is confusing enough that
it may prompt incorrect core handling "repair actions",
and this danger will remain permanently until
checkpatch.pl reporting is improved to be
less confusing/insufficient about its diagnosis
Or perhaps this imprecision here
again simply is due to
the very frequently observable case of
saying "thou shan't do this" without then also
giving some tried-and-true *reason(s)* for such advice.
("ERROR: Macros with complex values should be enclosed in parentheses")
HTH,
Andreas Mohr
next prev parent reply other threads:[~2017-04-09 9:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-08 16:07 Alfonso Lima
2017-04-08 17:33 ` Joe Perches
2017-04-09 8:55 ` Andreas Mohr [this message]
2017-04-09 17:45 ` [PATCH 1/2] checkpatch: Clarify the EMBEDDED_FUNCTION_NAME message Joe Perches
2017-04-09 17:45 ` [PATCH 2/2] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test Joe Perches
2017-04-09 17:46 ` Joe Perches
2017-04-09 17:59 ` [PATCH V2] " Joe Perches
2017-04-10 0:28 ` [PATCH V3] " Joe Perches
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=20170409085531.GA26418@rhlx01.hs-esslingen.de \
--to=andi@lisas.de \
--cc=alfonsolimaastor@gmail.com \
--cc=apw@canonical.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®