Quote:
Right; what I'm asking is what goes on behind the scenes.
That depends on the specific compiler.
Quote:
The way I see it, i++ is a single self contained operation - "increment, return old value." Obviously it's not a single instruction in assembly.
It doesn't matter whether or not it's a single assembly instruction; nor does it matter whether you conceptualize the operation as a single one or an aggregation of many operations. The assembly and the precedence of the operators doesn't matter. What matters is what the C++ standard says, and the standard explicitly calls modification of a scalar value more than once between sequence points "undefined."
Quote:
Thus I want to understand how a non-overloaded operator= works such that it may cause undefined behavior in this case.
It will cause undefined behavior. Always.
Remember, undefined behavior (in the sense of the C++ standard) isn't necessarily going to have apparently malignant results. It can, in fact, do exactly what you would think it correct and logical. That does not preclude it from being undefined behavior. Undefined behavior is the standard saying "we do not account for this scenario" or "we do not consider this scenario to be well-formed" even those it is syntactically valid. Thus, compilers are free to behave however they like. In practice this generally might translate for "do not write code to detect or handle this case," thus the compiler continues code generation as normal. This may cause the compiler to produce code that would crash, or perform an operation out of order... it may cause the compiler to produce slightly different code each time (maybe some sort or algorithm isn't stable under these conditions, for example) -- it all really depends on how the compiler is implemented.