#ifdef TEST1#define A 1#else#define B 2#endif#ifdef TEST2#include"1.h"#endifintmain(void){#ifdef USE_AreturnA;#elsereturnB;#endif}// of all the examples only this one is not reported#ifndef TEST3#define TEST3#endif
1.h:
#define C 1
./cppcheck --enable=all --addon=misra 1.c -DTEST1
I get:
Checking1.c...Checking1.c:TEST1=1...1.c:4:0:style:misraviolation(use--rule-texts=<file>togetproperoutput)[misra-c2012-2.5]#defineA1^1.c:6:0:style:misraviolation(use--rule-texts=<file>togetproperoutput)[misra-c2012-2.5]#defineB2^1.h:3:0:style:misraviolation(use--rule-texts=<file>togetproperoutput)[misra-c2012-2.5]#defineC1^nofile:0:0:information:Activecheckers:295/1002(use--checkers-report=<filename> to see details) [checkersReport]
I would expect none of them be a violation.
The only one that is not reported is the TEST3 which is a special case used for header guards discussed here .
Last edit: Dzid 2024-07-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If this was your explicit real world code then I would argue that the code is not well written. Why have two separate macros TEST1 and USE_A that must always be set to the same value otherwise the compiler will fail.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am so sorry. I don't know why this forum doesn't auto-subscribe to threads.
It was some time and I am trying to find the real world code. But by simply looking at my examples without cross-checking with the real code I tend to agree with you.
Except for unused #define C 1 violation. If the header is not included, I don't think it should be even checked.
Last edit: Dzid 2024-07-26
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Do you have some proof that these violations are technically false positives? According to misra. Do you see some related discussion in the misra forum for instance?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
1.c
:1.h
:./cppcheck --enable=all --addon=misra 1.c -DTEST1
I get:
I would expect none of them be a violation.
The only one that is not reported is the TEST3 which is a special case used for header guards discussed here .
Last edit: Dzid 2024-07-26
If this was your explicit real world code then I would argue that the code is not well written. Why have two separate macros TEST1 and USE_A that must always be set to the same value otherwise the compiler will fail.
I am so sorry. I don't know why this forum doesn't auto-subscribe to threads.
It was some time and I am trying to find the real world code. But by simply looking at my examples without cross-checking with the real code I tend to agree with you.
Except for unused
#define C 1
violation. If the header is not included, I don't think it should be even checked.Last edit: Dzid 2024-07-26
Do you have some proof that these violations are technically false positives? According to misra. Do you see some related discussion in the misra forum for instance?
For information PC-lint Plus also seem to write such warnings. You can open URL https://pclintplus.com/gmp/demo/ and try this code:
Last edit: Daniel Marjamäki 2024-06-14