People often comment that a program can legitimately respond to undefined behavior by deciding to reformat your hard drive. However, in practice undefined behaviors in most languages do something rather unsurprising, for example:
- Fail (e.g. crash, throw an exception, or otherwise interrupt execution).
- Refuse to compile. Yeah, that one is boring. If it happens, people fix the error and probably don't even contemplate it in terms of undefined behavior.
- Pick a specific, somewhat arbitrary choice (mainly when the behavior is undefined because it is ambiguous).
I have yet to see a serious C++ compiler that responds to u = (u++);
by reformatting the hard drive. I also have yet to see a case where this assigned the value of u+2 to u, though this would only be a mildly surprising rather than shocking.
Can anyone offer real-world examples where the undefined behavior was incredibly shocking and/or weird?