From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24075 invoked by alias); 21 Feb 2010 01:25:36 -0000 Received: (qmail 23977 invoked by uid 48); 21 Feb 2010 01:25:23 -0000 Date: Sun, 21 Feb 2010 01:25:00 -0000 Message-ID: <20100221012523.23976.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/25733] missed diagnostic about assignment used as truth value. In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "bangerth at gmail dot com" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-02/txt/msg02112.txt.bz2 ------- 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