From logic, it should report 5.5 error when ERRTEST is defined. And no error when ERRTEST is not defined.
The real test result is it report error when ERRTEST not defined, but it's ok when ERRTEST is defined.
$ cppcheck --addon=misra -UERRTEST --cppcheck-build-dir=out test.c
Checking test.c ...
test.c:7:6: style: Identifiers shall be distinct from macro names (Required)[misra-c2012-5.5]
int testmacro;
^
If ERRTEST is defined then after preprocessing there will be no identifier testmacro in the code. As I read the "Amplification" there should therefore not be a warning if ERRTEST is defined.
When ERRTEST is not defined.. maybe you are right I am not sure. There will be a "testmacro" identifier in the code after preprocessing. I am not sure what "regardless of whether the definition is still in force" in the amplification means.
Last edit: Daniel Marjamäki 2021-11-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
for the "regardless of whether the definition is still in force when the identifier is declared", I guess it's for the case add "#undef" before identifier? because it said "STILL in force". In -UERRTEST case here, the macro is never in "in force" status.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
test code:
From logic, it should report 5.5 error when ERRTEST is defined. And no error when ERRTEST is not defined.
The real test result is it report error when ERRTEST not defined, but it's ok when ERRTEST is defined.
$ cppcheck --version
Cppcheck 2.6
If ERRTEST is defined then after preprocessing there will be no identifier testmacro in the code. As I read the "Amplification" there should therefore not be a warning if ERRTEST is defined.
When ERRTEST is not defined.. maybe you are right I am not sure. There will be a "testmacro" identifier in the code after preprocessing. I am not sure what "regardless of whether the definition is still in force" in the amplification means.
Last edit: Daniel Marjamäki 2021-11-05
I updated the test code as below, it report 5.5 violation in both -DERRTEST and -UERRTEST cases.
for the "regardless of whether the definition is still in force when the identifier is declared", I guess it's for the case add "#undef" before identifier? because it said "STILL in force". In -UERRTEST case here, the macro is never in "in force" status.