Even worse, checking for overflow before casting can be tricky: https://stackoverflow.com/questions/526070/handling-overflow...
It's sad that comparison operators in C/C++ can lead to UB. Comparing unsigned to signed ints or comparing floats to ints is something the compiler could make work reliably at very little extra cost.