HI! First of all, thank you for implementing MISRA C checks in cppcheck. We just started applying these checks to our code as a request from a customer. My past experience has shown that most of these checks will provide real benefit and I have seen/fixed many of them in my career.
It appears that the way rule 3.1 is applied by cppcheck is too restrictive (cppcheck 1.84). Granted, I believe the rule needs some clarification by the committee. The example code given:
x=y // /* non-compliant
+x
// */
;
//// should be compliant?
The first sequence of // / is reported as non-compliant by cppcheck, good.
The second sequence of // / is not reported but is not explicitly addressed by MISRA, not an issue right now.
But the third sequence (added by me for testing) is multiple // sequences together, ie ////. cppcheck complains that these are non-compliant. But there is a stated exception for this in rule 3.1. As a comparison, we have access to the Altium TASKING compiler and it allows the multiple // sequence.
I believe cppcheck should address the exception stated in the MISRA doc. An updated check for the misra.py script would look like:
def misra_3_1(rawTokens):
for token in rawTokens:
if token.str.startswith('/*'):
if '//' in token.str[2:] or '/*' in token.str[2:]:
reportError(token, 3, 1)
elif token.str.startswith('//'):
if '/*' in token.str[2:]:
reportError(token, 3, 1)
Cheers,
Rob
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HI! First of all, thank you for implementing MISRA C checks in cppcheck. We just started applying these checks to our code as a request from a customer. My past experience has shown that most of these checks will provide real benefit and I have seen/fixed many of them in my career.
It appears that the way rule 3.1 is applied by cppcheck is too restrictive (cppcheck 1.84). Granted, I believe the rule needs some clarification by the committee. The example code given:
The first sequence of // / is reported as non-compliant by cppcheck, good.
The second sequence of // / is not reported but is not explicitly addressed by MISRA, not an issue right now.
But the third sequence (added by me for testing) is multiple // sequences together, ie ////. cppcheck complains that these are non-compliant. But there is a stated exception for this in rule 3.1. As a comparison, we have access to the Altium TASKING compiler and it allows the multiple // sequence.
I believe cppcheck should address the exception stated in the MISRA doc. An updated check for the misra.py script would look like:
Cheers,
Rob
Thanks! I agree. I made a fix for this.