How does clang manage to compile this code with undefined behavior into this machine code?
问题 It's a variation of code from this tweet, just shorter one and not causing any damage to noobs. We have this code: typedef int (*Function)(); static Function DoSmth; static int Return7() { return 7; } void NeverCalled() { DoSmth = Return7; } int main() { return DoSmth(); } You see that NeverCalled() is never called in the code, don't you? Here's what Compiler Explorer shows when clang 3.8 is selected with -Os -std=c++11 -Wall Code emitted is: NeverCalled(): retq main: movl $7, %eax retq as if