Discussion:
Disabling warning: suggest parentheses around && within ||
Andre Majorel
2009-05-09 07:19:54 UTC
Permalink
Is there a way to have -Wall without all the
"warning: suggest parentheses around && within ||" noise ?

-Wno-parentheses works, and seems to be supported at least as far
back as GCC 2.95, but probably also disables other, potentially
useful, warnings.

Thanks in advance.
--
André Majorel <URL:http://www.teaser.fr/~amajorel/>
Andrew Haley
2009-05-09 08:45:02 UTC
Permalink
Post by Andre Majorel
Is there a way to have -Wall without all the
"warning: suggest parentheses around && within ||" noise ?
This is amazing. I have only ever seen that warning on a few occasions,
and it's always been right. I can't imagine what your code might look
like!
Post by Andre Majorel
-Wno-parentheses works, and seems to be supported at least as far
back as GCC 2.95, but probably also disables other, potentially
useful, warnings.
It doesn't. I just looked at the gcc source, and -Wno-parentheses
only affects "suggest parentheses around X in Y" warnings.

Why don't you just put the parentheses in? It's good advice.

Andrew.
Andre Majorel
2009-05-13 11:37:16 UTC
Permalink
Post by Andrew Haley
Post by Andre Majorel
Is there a way to have -Wall without all the
"warning: suggest parentheses around && within ||" noise ?
-Wno-parentheses works, and seems to be supported at least as far
back as GCC 2.95, but probably also disables other, potentially
useful, warnings.
It doesn't. I just looked at the gcc source, and -Wno-parentheses
only affects "suggest parentheses around X in Y" warnings.
Meaning that it does. Some of those warnings are actually useful.

Thank you.
--
André Majorel <URL:http://www.teaser.fr/~amajorel/>
John (Eljay) Love-Jensen
2009-05-13 11:40:24 UTC
Permalink
Hi Andre,
Post by Andre Majorel
Meaning that it does. Some of those warnings are actually useful.
If you want to remove "warning: suggest parentheses around && within ||" and keep any other "warning: suggest parentheses around FOO within BAR" warnings, you can use grep -v -e to post process the output.

Or in your source, you can add in the parentheses, as suggested by the warning.
Post by Andre Majorel
From your initial inquiry, it appeared that you wanted -Wall without any parentheses warnings (-Wno-parentheses).
Sincerely,
--Eljay
Andre Majorel
2009-05-13 13:45:30 UTC
Permalink
Post by John (Eljay) Love-Jensen
Post by Andre Majorel
Meaning that it does. Some of those warnings are actually useful.
If you want to remove "warning: suggest parentheses around &&
within ||" and keep any other "warning: suggest parentheses
around FOO within BAR" warnings, you can use grep -v -e to post
process the output.
Which will only work in one locale. If GCC messages ever
acquire unique identifiers, it will be a welcome evolution.

Until then, the warnings are annoying but probably not annoying
enough for me to go to the trouble of making my makefiles so
GCC-specific.

Thank you.
--
André Majorel <URL:http://www.teaser.fr/~amajorel/>
Ian Lance Taylor
2009-05-13 14:39:55 UTC
Permalink
Post by Andre Majorel
Post by John (Eljay) Love-Jensen
Post by Andre Majorel
Meaning that it does. Some of those warnings are actually useful.
If you want to remove "warning: suggest parentheses around &&
within ||" and keep any other "warning: suggest parentheses
around FOO within BAR" warnings, you can use grep -v -e to post
process the output.
Which will only work in one locale. If GCC messages ever
acquire unique identifiers, it will be a welcome evolution.
You can use -fdiagnostics-show-option to see which command line option
controls a particular warning. You can use that as a locale-independent
identifier for this purpose.
Post by Andre Majorel
Until then, the warnings are annoying but probably not annoying
enough for me to go to the trouble of making my makefiles so
GCC-specific.
I've seen this specific warning, about the precedence of && and ||,
catch a surprising number of real errors in real code. However, since
some people know the precedence of && and || just as well as they know
the precedence of + and *, I would be sympathetic to breaking them out
into a separate -Wparentheses-and-or warning. Please feel free to file
that as an enhancement request at http://gcc.gnu.org/bugzilla .

Ian

Andrew Haley
2009-05-13 12:52:40 UTC
Permalink
Post by Andre Majorel
Post by Andrew Haley
Post by Andre Majorel
Is there a way to have -Wall without all the
"warning: suggest parentheses around && within ||" noise ?
-Wno-parentheses works, and seems to be supported at least as far
back as GCC 2.95, but probably also disables other, potentially
useful, warnings.
It doesn't. I just looked at the gcc source, and -Wno-parentheses
only affects "suggest parentheses around X in Y" warnings.
Meaning that it does. Some of those warnings are actually useful.
AFAIK all of them are. You haven't explained why you like some of
them but not others. As far as I can tell your complaint is wholly
arbitrary.

Andrew.
Loading...