C++ Migration Guide

Conditional Expressions

The C++ standard introduced a change in the rules for conditional expressions. The difference shows up only in an expression like

e ? a : b = c

The critical issue is having an assignment following the colon when no grouping parentheses are present.

The 4.2 compiler used the original C++ rule and treats that expression as if you had written

(e ? a : b) = c

That is, the value of c will be assigned to either a or b depending on the value of e.

The 5.0 compiler in both compatibility and standard mode uses the new C++ rule. It treats that expression as if you had written

e ? a : (b = c)

That is, c will be assigned to b if and only if e is false.

Solution: Always use parentheses to indicate which meaning you intend. You can then be sure the code will have the same meaning when compiled by any compiler.