Thats undefined behaviour. I suggest you read https://www.kb.cert.org/vuls/id/162289 on how undefined behaviour causes compilers to remove error handling code. Its about mistaken overflow checks but the principle is the same. Compilers assume that any code that can only be reached through undefined behaviour is unreachable.