I came across the Order of evaluation page on cppreference and I can't undestand why these lines are considered undefined behavior.
i = ++i + 2; // undefined behavior until C++11
f(i = -2, i = -2); // undefined behavior until C++17
In the first case, isn't the ++i
assignment computed and then the sum and then the final assignment to i
?
How about the second case? It seems to me that the function will get both arguments as -2
and the value of i
will always be -2
after the execution.