False positive in MISRA C++ 2008 Rule 6–2–2
Describe the bug
The bug is found in the checker for MISRA C++ 2008 Rule 6–2–2, which states that floating point numbers should not be checked for equality or inequality. The program seems to apply this rule to any floating point comparison, not just floating point equality or inequality checks (i.e. == or !=).
For example, the following snippet of code (with a method that's actually recommended within the MISRA C++ standard to do floating point equality tests) is
bool relativelyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon())
{
return std::abs(a - b) <= epsilon * std::max(std::abs(a), std::abs(b));
}
This is flagged by Analyze as a rule 6-2-2 violation, possibly due to the use of <= symbol. Other simple comparisons such as if (a > 0.0) where a is a float or double also results in a 6-2-2 violation.
To Reproduce Steps to reproduce the behavior:
- Analyze any code with a floating point comparison as stated above
- The software will report this as a 6-2-2 violation
Expected behavior The violation should not be flagged by the software.
Desktop (please complete the following information):
- OS: Fedora 40 running Analyze through Podman
- Version: latest