Using the MISRA-C:2012 plugin I'm seeing a number of, what look to me to be false positive, warnings.
The rule states that all if ... else if constructs should be terminated with an else, using the following example I don't believe that there should be a warning, however one does get raised.
void SomeFunction(void)
{
if (true)
{
SomeFunction();
}
else
{
if (false)
{
SomeFunction();
} // Should this really fail here?
}
}
I'm using cppcheck 1.87 via the GUI.
On the subject of this particular MISRA-C rule I also feel that the amplification is not being taken into consideration which calls for the terminating else to contain at least one side effect (e.g. some code / function call) or a comment.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I've had the same issue in our code base but I haven't been able to re-produce it with a more complex test case. The current simple test case passes. If you can produce a good test case then please add that to the bug.
Thanks for the test case. Unfortunatly, that is not very different than what is already in the test cases.
See void misra_15_7()
in ./addons/test/misra-test.c
and it passes there.
There seems to be some code context specific thing that creates the false positive.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using the MISRA-C:2012 plugin I'm seeing a number of, what look to me to be false positive, warnings.
The rule states that all if ... else if constructs should be terminated with an else, using the following example I don't believe that there should be a warning, however one does get raised.
I'm using cppcheck 1.87 via the GUI.
On the subject of this particular MISRA-C rule I also feel that the amplification is not being taken into consideration which calls for the terminating else to contain at least one side effect (e.g. some code / function call) or a comment.
Hi, I've had the same issue in our code base but I haven't been able to re-produce it with a more complex test case. The current simple test case passes. If you can produce a good test case then please add that to the bug.
https://trac.cppcheck.net/ticket/8657
I don't have an account for the bugtracker, so I'll attach my sample code, along with screenshot of it failing here.
This sample fails 100% of the time for me.
Looking over my production code that has these failures it only appears that the first if statement inside the else clause triggers a false positive.
Thanks for the test case. Unfortunatly, that is not very different than what is already in the test cases.
See void misra_15_7()
in ./addons/test/misra-test.c
and it passes there.
There seems to be some code context specific thing that creates the false positive.
I stand corrected. If I add your code into the misra-test.c it fails. Perfect! Now we have another test case. Thank you
You're welcome, glad you found it helpful.