The point is that the code is only checked for UB with the arguments it is given at compile time. There is no guarantee that it can't invoke UB with other arguments it might receive at runtime.
For example, here is a modification of the original program that does invoke UB, but compiles just fine:
For example, here is a modification of the original program that does invoke UB, but compiles just fine:
https://godbolt.org/z/MaqhcEYqn