I am running cppcheck with misra_c2012 on my project and I have an issue with the :preprocessor:
part in cppCheck.yml. All the code is analysed on my .c file, even the part only defined under certain conditions (#ifdef MACRO1) but I dont have the same behaviour on the header, where only the code common to every MACRO is analysed.
I made an small piece of code to illustrate my problem:
test.h
void test_noConfiguration(void);
#if defined(CONFIG_1)
void test_configuration1(void);
#endif
#if defined(CONFIG_2)
void test_configuration2(void);
#endif
test.c
#include "test.h"
static uint8_t localFunction(void)
{
return 0U;
}
void test_noConfiguration()
{
localFunction();
uint8_t u8_var = 0U;
}
#if defined(CONFIG_1)
void test_configuration1()
{
localFunction();
uint8_t u8_var = 0U;
}
#endif
#if defined(CONFIG_2)
void test_configuration2()
{
localFunction();
uint8_t u8_var = 0U;
}
#endif
When the analyse is launched with the macro CONFIG_1 defined on the :preprocessor:
part of the cppCheck.yml, all the issues are raised except for the one between #if defined(CONFIG_2)
, both in the .c and .h files, as expected.
When the analyse is launched without any macro defined on the :preprocessor:
part of the cppCheck.yml, all the issues of test.c are raised but in test.h, only the one outside #ifdef CONFIG_1
or #ifdef CONFIG_2
are raised (here, only the line with declaration of void test_noConfiguration(void);
raised the error misra-c2012-8.2
in test.h)
I was wondering, when there is not any macro defined in the cppCheck.yml, if it was supposed to :
- analyse all the code.
- analyse only the code ouside of all the
#ifdef
.
Either way, it seems odd that the behaviour is not the same in the .c and .h.
Thank you for you help
user25202923 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.