This rule finds function calls whose result type is a floating point type, which are implicitly cast to an integral type. Such code may not behave as intended when the floating point return value has a fractional part, or takes an extreme value outside the range that can be represented by the integer type.

Consider changing the surrounding expression to match the floating point type. If rounding is intended, explicitly round using a standard function such as trunc, floor or round.

In this example, the result of the call to getWidth() is implicitly cast to int, resulting in an unintended loss of accuracy. To fix this, the type of variable width could be changed from int to double.

  • Microsoft Visual C++ Documentation: Type Conversions and Type Safety (Modern C++).
  • Cplusplus.com: Type conversions.