public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/25733] missed diagnostic about assignment used as truth value.
       [not found] <bug-25733-4@http.gcc.gnu.org/bugzilla/>
@ 2012-01-19 14:00 ` manu at gcc dot gnu.org
  0 siblings, 0 replies; 12+ messages in thread
From: manu at gcc dot gnu.org @ 2012-01-19 14:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25733

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aravindvijayan224185 at
                   |                            |gmail dot com

--- Comment #12 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-01-19 13:48:48 UTC ---
*** Bug 51894 has been marked as a duplicate of this bug. ***


^ 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: " 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

* [Bug c/25733] missed diagnostic about assignment used as truth value.
  2006-01-10  9:00 [Bug c/25733] New: " 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: " 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: " 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: " 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: " 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: " 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: " 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: " 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: " 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: " 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

end of thread, other threads:[~2012-01-19 13:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-25733-4@http.gcc.gnu.org/bugzilla/>
2012-01-19 14:00 ` [Bug c/25733] missed diagnostic about assignment used as truth value manu at gcc dot gnu.org
2006-01-10  9:00 [Bug c/25733] New: " 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
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).