3 ms·
It's not that the compiler does not agree. It's that it operates under the assumption that there is no UB. If the compiler knew for sure that there is going to
by jstimpfle 5y ago
It's not that the compiler does not agree. It's that it operates under the assumption that there is no UB. If the compiler knew for sure that there is going to be UB (which happens at runtime, not compile time) of course it would tell. (Surely in some cases, the compiler needs to be improved to see UB that can be detected statically without much effort).
And if you don't request heavy optimization, what happens when UB occurs is likely just what you expected to happen on that particular machine. If you do request optimization, the results might be more off (perhaps the compiler removes some codepath for example). But I always have the impression that UB horror stories are mainly that: stories. I'm only slightly ashamed that I can't tell one from my personal experiences.