public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bangerth at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/25733] missed diagnostic about assignment used as truth value.
Date: Sun, 21 Feb 2010 01:25:00 -0000 [thread overview]
Message-ID: <20100221012523.23976.qmail@sourceware.org> (raw)
In-Reply-To: <bug-25733-7667@http.gcc.gnu.org/bugzilla/>
------- 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
next prev parent reply other threads:[~2010-02-21 1:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2010-02-21 1:44 ` manu at gcc dot gnu dot org
[not found] <bug-25733-4@http.gcc.gnu.org/bugzilla/>
2012-01-19 14:00 ` manu at gcc dot gnu.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100221012523.23976.qmail@sourceware.org \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).