In C++ division of an negative integer by an unsigned integer is implicitely casted to unsigned int first and then divided. This results in a wrong result and will not be detected by the compiler and not by sonar.
This bug cost me more than a week to find
Noncompliant Code:
uint32_t cnt = 5;
int32_t valueInt = -100000;
int32_t resultInt = valueInt / cnt;
expected -20000
computed 858973459
Compilant Code:
int32_t resultInt = valueInt / static_cast<int32_t>(cnt);
This is a critical bug because it works fine as long valueInt is positive.
It would be helpful if this rule would be added.
Thanks