Menu

Check with and without specific preprocessor symbols

matttbe
2017-05-30
2017-05-30
  • matttbe

    matttbe - 2017-05-30

    Hello,

    First, thank you for developing and maintaining this great open-source tool!

    I maybe missed that in the documentation but is there a way to analyse the code with and without some specific preprocessor symbols?

    I know that I can use -D and -U and if I don't use any, cppcheck will try different configurations.
    I can still force cppcheck to look at different configurations by using --force or --max-configs options. But if I include some headers from /usr/include, I don't want to use these options as it will look at "generic" preprocessor symbols. Is there a way to select these preprocessor symbols?

    Here is an example:

    #ifdef B
        w = B;
    #else
    #error
    #endif
    
    #ifdef A
        int x = y(w);
    #else
        int x = z(w);
    #endif
    
        x++;
    

    I would like to always use the path where B is defined (-DB) but still analyse the code when A is defined and not defined, e.g. not to report that y() and z() and not used. Is it possible to do that with one command? Or do I have to add ifdef around y() and z() functions and run cppcheck twice on all my project, once with -DB -DA and the other time with -DB -UA?

    Note that I quickly tried with -DA and -UA at the same time but then I think I had a situation where A is defined and not defined at the same time! Leading in this example at the situation where x is not defined at all. I quickly tried that with cppcheck 1.67 (on Debian Jessie).

    Thanks!
    Matt

     
  • Daniel Marjamäki

    hmm that code is not handled well by Cppcheck we'll need to look at that.

    I created one ticket to improve Preprocessor::getConfigs():
    http://trac.cppcheck.net/ticket/8092

     
  • matttbe

    matttbe - 2017-06-02

    Hi Daniel,

    Thank you for your reply (sorry for the delay, I didn't get any notification).

    Thank you for the ticket!

    Cheers,
    Matt

     

Log in to post a comment.