don't know how others do but I find I have to recompile a program without optimization flags in order to be able to fully debug a live C++ program. Understandable but annoying.
In most languages compilers are allowed to do whatever they want as long as the semantic outcome stays the same.