* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
@ 2006-01-10 10:17 ` rguenth at gcc dot gnu dot org
2008-04-27 22:14 ` manu at gcc dot gnu dot org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-01-10 10:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2006-01-10 10:17 -------
Confirmed. Same in the C++ frontend.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
GCC build triplet|i686-pld-linux |
GCC host triplet|i686-pld-linux |
GCC target triplet|i686-pld-linux |
Keywords| |diagnostic
Known to fail|3.4.5 4.1.0 |2.95.3 3.3.6 3.4.5 4.0.2
| |4.1.0
Last reconfirmed|0000-00-00 00:00:00 |2006-01-10 10:17:07
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
2006-01-10 10:17 ` [Bug c/25733] " rguenth at gcc dot gnu dot org
@ 2008-04-27 22:14 ` manu at gcc dot gnu dot org
2008-04-28 22:15 ` ianw at vmware dot com
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2008-04-27 22:14 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from manu at gcc dot gnu dot org 2008-04-27 22:13 -------
*** Bug 36050 has been marked as a duplicate of this bug. ***
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ianw at vmware dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
2006-01-10 10:17 ` [Bug c/25733] " rguenth at gcc dot gnu dot org
2008-04-27 22:14 ` manu at gcc dot gnu dot org
@ 2008-04-28 22:15 ` ianw at vmware dot com
2008-04-28 22:16 ` ianw at vmware dot com
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ianw at vmware dot com @ 2008-04-28 22:15 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from ianw at vmware dot com 2008-04-28 22:14 -------
As another data-point,
if ( (a=10) ) ;
also doesn't warn. I'm not sure what the standard says on that, but other
contemporary compilers do give the an "assignment used as truth value" warning
for the example above.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (2 preceding siblings ...)
2008-04-28 22:15 ` ianw at vmware dot com
@ 2008-04-28 22:16 ` ianw at vmware dot com
2008-04-28 22:18 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ianw at vmware dot com @ 2008-04-28 22:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from ianw at vmware dot com 2008-04-28 22:16 -------
Oh, just to be clear, my point was if (a=10) warns, but the extra parenthesis
hide the warning.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (3 preceding siblings ...)
2008-04-28 22:16 ` ianw at vmware dot com
@ 2008-04-28 22:18 ` pinskia at gcc dot gnu dot org
2008-04-28 22:28 ` ianw at vmware dot com
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-28 22:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2008-04-28 22:17 -------
(In reply to comment #4)
> Oh, just to be clear, my point was if (a=10) warns, but the extra parenthesis
> hide the warning.
That is by design.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (4 preceding siblings ...)
2008-04-28 22:18 ` pinskia at gcc dot gnu dot org
@ 2008-04-28 22:28 ` ianw at vmware dot com
2010-02-21 0:30 ` manu at gcc dot gnu dot org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ianw at vmware dot com @ 2008-04-28 22:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from ianw at vmware dot com 2008-04-28 22:28 -------
(In reply to comment #5)
> (In reply to comment #4)
> > Oh, just to be clear, my point was if (a=10) warns, but the extra parenthesis
> > hide the warning.
>
> That is by design.
Ok, I did try looking but is that documented anywhere?
It would seem to have ramifications for people that do things like make an
ASSERT statement something like
#define ASSERT(v) {if (!(v))}
A quick search on google codesearch showed this was a very common idiom...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (5 preceding siblings ...)
2008-04-28 22:28 ` ianw at vmware dot com
@ 2010-02-21 0:30 ` manu at gcc dot gnu dot org
2010-02-21 0:33 ` manu at gcc dot gnu dot org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21 0:30 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from manu at gcc dot gnu dot org 2010-02-21 00:30 -------
(In reply to comment #3)
> As another data-point,
>
> if ( (a=10) ) ;
>
> also doesn't warn. I'm not sure what the standard says on that, but other
> contemporary compilers do give the an "assignment used as truth value" warning
> for the example above.
>
How do other compilers deal with false positives? That is, how can a programmer
specify that they really want to do an assignment?
We could use a cast to bool.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (6 preceding siblings ...)
2010-02-21 0:30 ` manu at gcc dot gnu dot org
@ 2010-02-21 0:33 ` manu at gcc dot gnu dot org
2010-02-21 0:34 ` manu at gcc dot gnu dot org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21 0:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from manu at gcc dot gnu dot org 2010-02-21 00:33 -------
*** Bug 32587 has been marked as a duplicate of this bug. ***
--
manu at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |fritz at intrinsity dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (7 preceding siblings ...)
2010-02-21 0:33 ` manu at gcc dot gnu dot org
@ 2010-02-21 0:34 ` manu at gcc dot gnu dot org
2010-02-21 1:25 ` bangerth at gmail dot com
2010-02-21 1:44 ` manu at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21 0:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from manu at gcc dot gnu dot org 2010-02-21 00:34 -------
Another testcase:
int bar(int a, int b, int c)
{
if ((b = c) && (a == 0))
{
return 0;
}
return 1;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (8 preceding siblings ...)
2010-02-21 0:34 ` manu at gcc dot gnu dot org
@ 2010-02-21 1:25 ` bangerth at gmail dot com
2010-02-21 1:44 ` manu at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: bangerth at gmail dot com @ 2010-02-21 1:25 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from bangerth at gmail dot com 2010-02-21 01:25 -------
(In reply to comment #7)
> (In reply to comment #3)
> > As another data-point,
> >
> > if ( (a=10) ) ;
> >
> > also doesn't warn. I'm not sure what the standard says on that, but other
> > contemporary compilers do give the an "assignment used as truth value" warning
> > for the example above.
> >
>
> How do other compilers deal with false positives? That is, how can a programmer
> specify that they really want to do an assignment?
>
> We could use a cast to bool.
I think at least in C++ the warning is useful. Conditions in if(...) statements
have type bool, and things like
if (a=10)
use the implicit conversion from int to bool. If a programmer wants to avoid
the warning, one can always be explicit and write
if ( (a=10) != 0)
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c/25733] missed diagnostic about assignment used as truth value.
2006-01-10 9:00 [Bug c/25733] New: missed diagnostic about assignment used as truth value pluto at agmk dot net
` (9 preceding siblings ...)
2010-02-21 1:25 ` bangerth at gmail dot com
@ 2010-02-21 1:44 ` manu at gcc dot gnu dot org
10 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu dot org @ 2010-02-21 1:44 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from manu at gcc dot gnu dot org 2010-02-21 01:43 -------
I am not saying that the warning is not useful. I am saying that the current
behaviour of not warning if there are parenthesis is not ideal.
So either:
if ((bool) a = 0)
or
if ( (a=0) != 0)
seem much better choices for avoiding warning.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733
^ permalink raw reply [flat|nested] 12+ messages in thread