This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -Wparentheses lumps too much together
Ian Lance Taylor wrote:
> I have no objection to splitting -Wparentheses into separate warnings
> controlled by separate options.
Thank you, Ian.
> > which yields (as you know) advice to parenthesize the two && pairs.
>
> That particular warning happened to find dozens of real errors when I
> ran it over a large code base. It may be noise for you, but I know
> from personal experience that it is very useful.
I would like to hear more about that, if you wouldn't mind. I'm really
quite surprised. Honestly.
I don't claim to be the last arbiter in good taste. It sounds like you're
saying that this warning, when applied to code of uncertain quality,
turned up errors -- cases when the code didn't reflect (what must have
been) the programmer's intentions. My untested (and consequently firmly
held) hypothesis is that
1) most combinations of && and || don't need parentheses because
(a && b) || (c && d)
is by far more common than
a && (b || c) && d
and, moreover, broken code fails at runtime, and
2) Most programmers know (because they need to know) that && comes before
||.
I'm sure a few years spent working with the GCC and fielding questions
about it would lower my opinion of the average programmer, so I won't try
to convince you. But I would like to know more about what you found,
because that's at least objective evidence. I was unable to find any
metrics supporting the inclusion of this particular warning in -Wall.
I would hold to this, though: the warnings about precedence are of a
different order than warnings about nesting. I suggest that well vetted
code doesn't benefit from the kind of false positives that -Wparentheses
can generate.
I very much appreciate your time and effort.
Kind regards,
--jkl