Reading ES.43: Avoid expressions with undefined order of evaluation, it states that the result of this expression
v[i] = ++i;
is undefined. I'm assuming that's another way to say we got undefined behavior (UB).
Reading SO posts on this topic, specifically Why is i = i++ + 1
undefined behavior in C++11? and Undefined behavior and sequence points, I conclude that the expression should be well-defined since:
- Value computation of right operand is sequenced before value computation of left operand for assignment operator (N4835, §[expr.ass]/1.)
- Side-effect of pre-increment operator is sequenced before value computation of the preincrement (sub)expression (hopefully; don't have source for this)
meaning we do not have any side-effect unsequenced to value computation or another side-effect for the same object.
What am I missing?
Note: My question is intended for C++20. If there is any changes regarding this in previous Standards (up until C++11; so C++11, C++14 and C++17) I would like to know the changes as well. Also, I've noticed a similar post on this Why is i = v[i++] undefined?, but it's about post-increment so I didn't find an answer there.