Page 1 of 1
Pass -D options to ccpcheck
Posted: Mon May 19, 2014 5:17 am
by Gibbon1
In my code I pass some defines to the compiler via the -D option (settings->compiler preprocessor:)
Is there a way, or perhaps this is a 'feature' to pass preprossor defines to ccpcheck? as well?
ccpcheck complains about things like #if(UNIT_TYPE = BLARGE) because UNIT_TYPE is passed to the compiler via -D UNIT_TYPE=BLARGE
Re: Pass -D options to ccpcheck
Posted: Mon May 19, 2014 1:09 pm
by DavidGH
Hi,
CodeLite acts as a front-end to cppcheck, and afaict from a quick manual-read and google, cppcheck doesn't have the ability to 'see' such defines.
If I'm wrong, or if you can see a way for CodeLite to pass them to cppcheck, please correct me
.
Regards,
David
Re: Pass -D options to ccpcheck
Posted: Tue May 20, 2014 1:16 am
by Gibbon1
There is a chapter on Preprocessor configurations the (short) manual that
http://cppcheck.sourceforge.net/manual.pdf
Seems to say you can add -D options to ccpcheck.
Re: Pass -D options to ccpcheck
Posted: Tue May 20, 2014 1:23 am
by DavidGH
Yes, I read it. But it seems to be talking about passing cppcheck-specific defines, to alter cppcheck's behaviour, rather than ones used in the program being checked.
Why not try it yourself using cppcheck direct to check your program, not through CodeLite. If you confirm that passing your program's defines works there, it shouldn't be difficult to implement within CodeLite too.
Re: Pass -D options to ccpcheck
Posted: Tue May 20, 2014 1:41 am
by Gibbon1
I did a check running ccpcheck from the command line and the -D option feature works.
I think all you have to do (he says in full humble ignorance) is pass the preprocessor defines as you would to gcc
Re: Pass -D options to ccpcheck
Posted: Tue May 20, 2014 12:27 pm
by DavidGH
OK, I'll see what I can do.
Thanks for testing it.
Re: Pass -D options to ccpcheck
Posted: Wed May 21, 2014 1:26 am
by Gibbon1
I did a little test with
#if defined(MONKEY_BUTT)
uint8_t *test = alloca(10);
#endif
adding the -DMONKEY_BUTT results in a warning about depreciated alloca();
I admit the manual for ccpcheck is confusing.
Re: Pass -D options to ccpcheck
Posted: Fri May 23, 2014 12:53 pm
by DavidGH
I'm trying to create a failing test for cppcheck, otherwise I won't be able to test any fix. And I'm failing...
Using this simple console code:
Code: Select all
#include <wx/init.h>
#include <wx/string.h>
int main( int argc, char** argv )
{
// initialize wxWidgets
wxInitializer init;
#if (FOO == 1)
int i = FOO;
void *test = alloca(10);
#endif
wxPrintf( wxT("Hello in wxWidgets World! i = %i\n\n"), i );
return 0;
}
compiled with -DFOO=1, and testing with CL 5.4 (which uses cppcheck 1.54) I get in only the expected:
"Found obsolete function 'alloca'..."
error.
CL trunk has cppcheck 1.63. and this results in just:
"style: Variable 'test' is assigned a value that is never used."
Which version of CodeLite are you using? And which standalone cppcheck did you test? What do you get with the above test, and what would you want to see?
Re: Pass -D options to ccpcheck
Posted: Fri May 23, 2014 5:29 pm
by Jarod42
with:
Code: Select all
int main() {
#ifdef TOTO
int i;
#else
int j;
#endif
return 0;
}
I got:
$ ./codelite_cppcheck.exe --enable=style main.cpp
Checking main.cpp...
[main.cpp:5]: (style) Unused variable: j
Checking main.cpp: TOTO...
[main.cpp:3]: (style) Unused variable: i
$ ./codelite_cppcheck.exe --enable=style -DTOTO main.cpp
Checking main.cpp...
[main.cpp:3]: (style) Unused variable: i
$ ./codelite_cppcheck.exe --enable=style -UTOTO main.cpp
Checking main.cpp...
[main.cpp:5]: (style) Unused variable: j
So, providing -D (define) or -U (undefine) allow cpp_check to not check all possible configurations.
Re: Pass -D options to ccpcheck
Posted: Mon May 26, 2014 7:56 pm
by DavidGH
OK, I think I now understand the situation.
I've implemented this in b26f743 and updated the
Cppcheck doc page. Please try it out, and read the doc, to make sure it's what you wanted.