[Bug c/23964] -Wparentheses doesn't catch all assignments used as truth value
glebius at FreeBSD dot org
gcc-bugzilla@gcc.gnu.org
Mon Sep 19 13:06:00 GMT 2005
------- Additional Comments From glebius at FreeBSD dot org 2005-09-19 13:06 -------
Subject: Re: -Wparentheses doesn't catch all assignments used as truth value
On Mon, Sep 19, 2005 at 12:28:55PM -0000, falk at debian dot org wrote:
f> ------- Additional Comments From falk at debian dot org 2005-09-19 12:28 -------
f> (In reply to comment #0)
f> > The -Wparentheses switch (as well as -Wall) doesn't catch logical assignments
f> used as truth values. For example:
f> >
f> > int i = 0;
f> >
f> > if (i |= 1) {};
f> > if (i ^= 1) {};
f> > if (i &= 1) {};
f>
f> What kind of confusion could the code above create in a reader? This code
f> seems pretty unambiguous to me, so why warn?
Well, all these examples are assignments. I don't agree that '=' is a somewhat
unique or special assignment. According to documentation (and that would be
logically correct) any kind of assignment should be caught when used as truth
value without additional parentheses.
`-Wparentheses'
Warn if parentheses are omitted in certain contexts, such as when
there is an assignment in a context where a truth value is
expected, or when operators are nested whose precedence people
often get confused about.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23964
More information about the Gcc-bugs
mailing list