While setting up cppcheck for a larger codebase (and working around my other problems) I've uncovered another issue, this time concering some... gymnastics using the preprocessor. It's not as contrived but I can't share the original.
I've condensed it into this example:
#define ADD_INT(x, y) x+y int main() { return ADD_INT(1, #if 1 5 #else 6 #endif ); }
cppcheck (both latest master and last release) give the following* error:
$ cppcheck preprocessorError.c Checking preprocessorError.c ... preprocessorError.c:5:0: error: failed to expand 'ADD_INT', it is invalid to use a preprocessor directive as macro parameter [preprocessorErrorDirective] #if 1 ^
*: Perhaps interestingly, the build from master gives the error twice:
$ cppcheck preprocessorError.c Checking preprocessorError.c ... preprocessorError.c:5:0: error: failed to expand 'ADD_INT', it is invalid to use a preprocessor directive as macro parameter [preprocessorErrorDirective] #if 1 ^ preprocessorError.c:5:1: error: failed to expand 'ADD_INT', it is invalid to use a preprocessor directive as macro parameter [preprocessorErrorDirective] #if 1 ^
Note that replacing #if 1 with #ifdef NOT_DEFINED doesn't change this behaviour.
#if 1
#ifdef NOT_DEFINED
both clang and gcc build this code just fine, their preprocessor output behaves as expected (I've removed a few blank lines):
$ cpp preprocessorError.c # 0 "preprocessorError.c" # 0 "<built-in>" # 0 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 0 "<command-line>" 2 # 1 "preprocessorError.c" int main() { return 1 +5 ; }
See https://github.com/danmar/simplecpp/issues/328
Log in to post a comment.
While setting up cppcheck for a larger codebase (and working around my other problems) I've uncovered another issue, this time concering some... gymnastics using the preprocessor. It's not as contrived but I can't share the original.
I've condensed it into this example:
cppcheck (both latest master and last release) give the following* error:
*: Perhaps interestingly, the build from master gives the error twice:
Note that replacing
#if 1
with#ifdef NOT_DEFINED
doesn't change this behaviour.both clang and gcc build this code just fine, their preprocessor output behaves as expected (I've removed a few blank lines):
See https://github.com/danmar/simplecpp/issues/328