Evaluating typical static assertion patterns fails, either cppcheck misses invalid syntax or fails completely.
See the attached example.
Message is: "Analysis failed. If the code is valid then please report this failure."
A gcc, mingw or clang compiler has no problems with the file.
#define NUM_ELEMENTS(arr) (sizeof (struct {int not_an_array:((void*)&(arr) == &((arr)[0]));}) * 0 + sizeof (arr) / sizeof (*(arr)))#define XX_STATIC_ASSERT2(cond,a,b) typedef char a##b[(cond) ? 1 : -1]#define XX_STATIC_ASSERT(cond,a,b) XX_STATIC_ASSERT2(cond,a,b)#define OS_STATIC_ASSERT(cond) XX_STATIC_ASSERT(cond,EXPR_,__LINE__)voidbug_static(){staticconstchar*constnames[]={"P1",/* 0 */"P2"};OS_STATIC_ASSERT(2==2);//!< No problem found - ok#ifdef CPPCHECK_ONLYOS_STATIC_ASSERT(2==3);//!< No problem found - bug - should be reported#endifif(NUM_ELEMENTS(names)==2)//!< No problem found - ok{return0;}OS_STATIC_ASSERT(NUM_ELEMENTS(names)==2);//!< Fails - bug - should neither report nor fail}// Included so that we can compile the stuffvoidmain(intargc){return0;}
The only difference of the gcc and Cppcheck preprocessor output is that Cppcheck (or better simplecpp) uses other line numbers (and two times the same line number!) for the EXPR_<line> arrays.
And even if i use the preprocessed output of gcc i still get the message "Analysis failed. ..." from Cppcheck. So it looks not like an issue with simplecpp (except the thing with the line numbers).
Last edit: versat 2018-12-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Evaluating typical static assertion patterns fails, either cppcheck misses invalid syntax or fails completely.
See the attached example.
Message is: "Analysis failed. If the code is valid then please report this failure."
A gcc, mingw or clang compiler has no problems with the file.
Last edit: Jens Nissen 2018-12-10
testCppCheck.c:
gcc -E:
cppcheck -E (removed/added spaces for easy comparison with the gcc output):
The only difference of the gcc and Cppcheck preprocessor output is that Cppcheck (or better simplecpp) uses other line numbers (and two times the same line number!) for the
EXPR_<line>
arrays.And even if i use the preprocessed output of gcc i still get the message "Analysis failed. ..." from Cppcheck. So it looks not like an issue with simplecpp (except the thing with the line numbers).
Last edit: versat 2018-12-13