[cfe-dev] [PATCH] -Wconversion-null

James K. Lowden jklowden at schemamania.org
Thu Mar 15 18:31:08 PDT 2012


On Thu, 15 Mar 2012 12:32:30 +0100
Lubos Lunak <l.lunak at suse.cz> wrote:

> On Thursday 15 of March 2012, James K. Lowden wrote:
> > No, I can't agree.  The purpose of a warning is to indicate when a
> > particular operation or construction might be unsafe.  A warning
> > about something that cannot possibly be an error (as far as the
> > machine is concerned) is just noise.
> 
> Clang has a lot of noise then. Just one random example:
> 
> $clang++ a.cpp 
> a.cpp:6:16: warning: '&&' within '||' [-Wlogical-op-parentheses]
>     if( a == 1 && b == 2 || c == 3 )
>         ~~~~~~~^~~~~~~~~ ~~
> a.cpp:6:16: note: place parentheses around the '&&' expression to
> silence this warning
>     if( a == 1 && b == 2 || c == 3 )
>                ^
>         (               )
> 1 warning generated.

	"Saying a true thing twice doesn't make it truer."  

Babysitting good code is really, really easy. It also distracts from
harder and more important work, never mind those of us who want to
use it as a *tool*, not an instructional video.  And it's not good for
the community.  

I you squint really hard at the gcc archives, you'll find my name
raising an objection to including that warning in -Wall, which many
projects use as the "gold standard".  

Why do people think Boolean operations are hard?  Why don't
they get their knickers in a twist over !, too?  When I looked into it
back then, I could find only two kinds of languages: those that define
logical precedence and those that don't.  Of those that do, all bind AND
before OR.  

The code above is absolutely clear. If you don't know && comes
before ||, and has for the last 25 years, learn!  

That's the real poverty of that warning:  instead of allowing clear
code that uses the language correctly to instruct the less
knowledgeable, it discourages such code and such learning.   In
assuming incompetence it begets incompetence.  If we keep it up, we'll
eventually arrive at 

	ADD 1 to X GIVING Y

just as Grace Hopper always wanted.  

When I see extra parentheses for Boolean operations, I treat the code
with skepticism.  Why?  Either something tricky is going on, or *not*
but the programmer was unsure.  In such a place do bugs lurk of the
kind no compiler can warn.  

--jkl



More information about the cfe-dev mailing list