See also this question and my answer to it . I am not going to vote to close this as a duplicate, because you are asking about C ++ and not about C, but I believe that the problem in both languages ​​is the same.
access to the previous value is possible only to determine the stored value.
This seems like an odd claim; why is standard care about why access to a value is required? It makes sense when you understand that if the previous value is read to determine the value that should be stored in the same object, this implicitly imposes order on the two operations, so reading should happen before writing. Because of this ordering, two accesses to the same object (one read and one write) are safe. The compiler cannot reorder (optimize) the code so that it interferes with each other.
On the other hand, in an expression like
a[i] = i++
There are three accesses to i : reading on the left to determine which element a should be changed, reading on the right to determine the value to be increased, and writing that saves the additional value to i . Reading and writing to RHS is okay ( i++ is safe in itself), but there is no definite order between reading on LHS and writing to RHS. Thus, the compiler can freely change the code in such a way as to change the relationship between these read and write operations, while the standard one figuratively throws up its hands and leaves the behavior undefined, not to mention the possible consequences.
Both C11 and C ++ 11 change the wording in this area, making some ordering requirements explicit. The "prior value" form no longer exists. Quote from the draft standard C ++ 11, 1.9p15:
Except where noted, estimates of the operands of individual operators and subexpressions of individual expressions are not affected. [...] Calculations of operator operand values ​​are sequenced before calculating the value of the operator result. If the side influence on the scalar object is independent of another effect on the same scalar object or the calculation of the value using the value of the same scalar object, the behavior is undefined.
source share