Possible Duplicate:
Undefined, unspecified and implementation-defined behavior
I’m trying to deepen my understanding of undefined behavior in C++. Suppose a C++ compiler will intentionally detect some cases of undefined behavior – for example, modifying the variable twice between two sequence points:
x++ = 2;
Once that imaginary compiler reliably detects such a situation it will say emit ten totally random machine instructions into the produced machine code.
According to C++ standard, wherever something is classified as UB there’re no requirements on what happens. Will the described imaginary compiler be conformant to the C++ standard?
Yes. The standard imposes no requirements, so it can do whatever it wants:
Just as a note, that is undefined behavior, but it’s not necessarily a good example. On g++ 4.4.1, it will refuse to compile with:
because the result of a post-increment is not an lvalue.