C++ float-to-int conversion can be undefined behavior

Converting a float to an int in C++ is undefined behavior when the truncated float does not fit into the destination integer. C++ makes it easy to do this accidentally. Much code gets this wrong. void foo(float f) { int i0 = f; int i1 = int(f); int i2 = static_cast<int>(f); } This code does not generate any warnings, not even with -Wall and -Wextra . -Wconversion only warns about the implicit…