2012/4/11 Ian Lance Taylor <i...@google.com>: > Andrew Haley <a...@redhat.com> writes: > >> On 04/05/2012 01:28 PM, Michael Veksler wrote: >> >>> As for specific warnings, I hate that the the code (a&&b || c&&d), >>> which did not cause a warning on older gcc version now gives a >>> warning. I would not want it on by default since it forces users to >>> write too many parentheses in ((a&&b)||(c&&d)) which makes the >>> expression less readable. What next? Warn about (a*b+c*d) ? I would >>> hate to write ((a*b)+(c*d)). >>> >>> Sure, the precedence of: << vs. +; & vs. == ; & vs. && ; is less >>> clear and deserves a warning, but: & vs. | ; && vs. || ; are at >>> least as common as * vs. + that programmers ought to know them. >> >> Absolutely so, yes. I'd consider this a bug in gcc, just as if it >> warned for arithmetic. > > This one is an interesting case, since there are strong arguments on > both sides. > > I enabled the C++ warning about the precedence of && and || (it's been > in C for many years). It found real bugs in real code, bugs that had > existed for years.
I've got a radically different experience here, real bugs were introduced while trying to remove this warning, and as far as I can tell, I've never found any bugs involving precedence of && and || -- in the code I'm working on --, whose precedence is really well known from everyone. In the real life, things are not as simple as (a && b) || ( c && d), some checks usually lie over more than five lines. This warning applied to such checks are really a pain to remove. We shall definitely have an option to remove this very warning, without getting rid of the whole sets of usefull warnings embedded in -Wparentheses. -- Fabien