user25202923
user25202923

Reputation: 21

Cppcheck error are raised on all code even with macro defined

I am running Cppcheck with MISRA-C:2012 on my project without any -D or -U options for the preprocessor. 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 Cppchack with -DCONFIG_1, 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 options (-D or -U) and 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)

According to the namual, without any specification the code will test as if all the configurations are used and every error should be raised.

I was wondering why the error from the header is not raised in this case.

Upvotes: 2

Views: 223

Answers (0)

Related Questions