> However, if your program avoids the code paths which trigger undefined behavior, then you are safe.<p>This seems incorrect as demonstrated by the other undefined behavior story I read on HN today[1], the tl;dr of which, as I understood it, is since UB is not allowed, the compiler can elide checks that would protect against UB for the sake of optimization since a correct program wouldn't have caused the UB in the first place and the compiler doesn't have to respect the semantics of incorrect programs.<p>[1] <a href="https://news.ycombinator.com/item?id=41146860">https://news.ycombinator.com/item?id=41146860</a>