------- 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

Reply via email to