Arthur Schwarz wrote:
I don't know what 'UB' is
Undefined behavior.
That means the compiler is free to make choices that would change the
result.
I would have expected operator precedence to force evaluation of the left side of the == operator for complex expressions,
Operator precedence says nothing about which side of an operator is
evaluated first. It only says which operator bindings occur first as
the linear version of an expression is converted to the tree version.
and left-to-right associativity to mandate the execution ordering otherwise.
Nothing in these examples involves left-to-right associativity.
I can't see as how the compiler has an option on evaluation order given the precedence and associativity of the operators.
For most infix operators, the sequence is not defined.
In (A == B++) the value used for B must be the value before B is
incremented.
In (A == ++B) the value used for B must be the value after B is incremented.
But in both those cases, C++ does not define whether the value used for
A is computed before or after B is incremented.
I would assume that the order is determined subject only to the immutability of results if any optimization is done.
Correct optimization cannot change defined behavior, but it can change
undefined behavior.