The exception to the MISRA rule 5.9 described in the guidelines, regarding static inlined functions in header files, is not taken into account by the cppcheck misra add-on. For example, when using the following files:
//filea.hstaticinlineintf(void) {
return;
}
// file b.c#include"a.h"
// file c.c#include"a.h"
Running cppcheck with the misra add-on triggers a rule 5.9 violation when I believe it shoulnd't:
I do not recommend that you run cppcheck on the headers directly.
The command cppcheck --addon=misra b.c c.c should be used instead. since b.c and c.c include a.h , the header will be checked in those translation units more properly.
If you check a header directly you can for instance expect false positives for unusedStructMember.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you for bringing it to my attention Daniel! I've been passing headers to cppcheck, both with and without misra add-on, since I started using it.
Nevertheless, the issue it's still there if only passing the c files. I took a look at the code yesterday, and I believe it is a simple matter to fix. I'll probably submit a PR later today.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
While trying to fix this issue, I came across another issue where sometimes the inline keyword is ignored when we use a multiple word return type (e.g. unsigned long). For example, using misra rule 8.10 for illustration purposes:
The exception to the MISRA rule 5.9 described in the guidelines, regarding static inlined functions in header files, is not taken into account by the cppcheck misra add-on. For example, when using the following files:
Running cppcheck with the misra add-on triggers a rule 5.9 violation when I believe it shoulnd't:
Best regards,
José
Thanks! I have created https://trac.cppcheck.net/ticket/10820
I do not recommend that you run cppcheck on the headers directly.
The command
cppcheck --addon=misra b.c c.c
should be used instead. since b.c and c.c include a.h , the header will be checked in those translation units more properly.If you check a header directly you can for instance expect false positives for unusedStructMember.
Thank you for bringing it to my attention Daniel! I've been passing headers to cppcheck, both with and without misra add-on, since I started using it.
Nevertheless, the issue it's still there if only passing the c files. I took a look at the code yesterday, and I believe it is a simple matter to fix. I'll probably submit a PR later today.
I assume you fixed https://trac.cppcheck.net/ticket/10820 ? I can't reproduce the FP right now. I have closed it.
While trying to fix this issue, I came across another issue where sometimes the inline keyword is ignored when we use a multiple word return type (e.g. unsigned long). For example, using misra rule 8.10 for illustration purposes:
Running
cppcheck --addon=misra r8_10.c
correctly yields:However, a slight change to the file to use a multi-word return type:
No longer triggers any violation.
I believe I also have a suggestion to patch this issue, although I'm not completely confident it is the best approach. PR later.