[cfe-dev] Side effect of conditional operator

Chris Lattner clattner at apple.com
Tue Nov 13 09:46:34 PST 2007


On Nov 11, 2007, at 4:44 PM, Sanghyeon Seo wrote:

> Conditional operator expression may have side effect if one of its
> operands does.
>
> A patch with a test is attached.

This is a very nice patch, but I don't think it is appropriate.

?: itself doesn't have side effects.  The warning is reasonable in  
this code:

   i < j ? (sum += i) : (sum += j);

The issue is that the ?: expression itself returns a value, and that  
value is being ignored.  Why not use an if statement in this case?

-Chris



More information about the cfe-dev mailing list