Well yes, that would be UB, but even if the C++ compiler had no concept of UB, it would still be wrong code.