Pass -D options to ccpcheck

Discussion about CodeLite development process and patches
Gibbon1
CodeLite Expert
Posts: 167
Joined: Fri Jul 22, 2011 5:32 am
Genuine User: Yes
IDE Question: C++
Contact:

Pass -D options to ccpcheck

Post 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
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Pass -D options to ccpcheck

Post 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
Gibbon1
CodeLite Expert
Posts: 167
Joined: Fri Jul 22, 2011 5:32 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Pass -D options to ccpcheck

Post 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.
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Pass -D options to ccpcheck

Post 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.
Gibbon1
CodeLite Expert
Posts: 167
Joined: Fri Jul 22, 2011 5:32 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Pass -D options to ccpcheck

Post 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
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Pass -D options to ccpcheck

Post by DavidGH »

OK, I'll see what I can do.

Thanks for testing it.
Gibbon1
CodeLite Expert
Posts: 167
Joined: Fri Jul 22, 2011 5:32 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Pass -D options to ccpcheck

Post 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.
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Pass -D options to ccpcheck

Post 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?
User avatar
Jarod42
CodeLite Expert
Posts: 240
Joined: Wed Sep 30, 2009 5:54 pm
Genuine User: Yes
IDE Question: C++
Location: France
Contact:

Re: Pass -D options to ccpcheck

Post 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.
DavidGH
CodeLite Plugin
Posts: 819
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: Pass -D options to ccpcheck

Post 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.
Post Reply