Using ccpcheck on main.c results in the following output:
foo.h:1:6: [misra-c2012-8.7] Advisory: Functions and objects should not be defined with external linkage if the are referenced in only one translation unit
void foo(void);
^
Here, the function is part of an API for foo.c and it is called in main.c.
If you look at this thread on the misra forum, the official answer to a similar suggestion of a false positive from misra is that:
The term "referenced" in the headline includes both the a call of a function and the definition of a function. A function which is defined in one translation unit and called in a different translation unit is compliant with this rule.
An example of this compliant situation occurs in the example suite. Function R_8_7_2 is declared in a header (R_08_07.h), defined in R_08_07_2.c and called in R_08_07_1.c.
Thus, I suggest modifying the checker to only trigger a fault of 8.7 when a function is not called from a different translation unit. Thoughts on this?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Henrik, I've submitted a pull request which I believe fixes this false positive as well as a couple others. If you could please make sure it also fixes the FPs from your end, it would be much appreciated.
👍
1
Last edit: José Martins 2022-02-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I think there is a false positive on misra-c2012-8.7 in the following scenario:
Using ccpcheck on main.c results in the following output:
Here, the function is part of an API for foo.c and it is called in main.c.
If you look at this thread on the misra forum, the official answer to a similar suggestion of a false positive from misra is that:
Thus, I suggest modifying the checker to only trigger a fault of 8.7 when a function is not called from a different translation unit. Thoughts on this?
Thanks!
(also, there is a small typo: ...if the are referenced... --> if they are referenced)
Thanks! Good input. I created ticket https://trac.cppcheck.net/ticket/10814
Daniel, just to note the ticket has a typo: the reported false positive is regarding rule 8.7, not rule 8.2
Thanks!
Henrik, I've submitted a pull request which I believe fixes this false positive as well as a couple others. If you could please make sure it also fixes the FPs from your end, it would be much appreciated.
Last edit: José Martins 2022-02-19
I have closed https://trac.cppcheck.net/ticket/10814 because I can't reproduce the false positive with the given code.