Menu

Warnings on disabled code

2020-03-08
2020-03-09
  • Dennis Mierke

    Dennis Mierke - 2020-03-08

    Hello,
    I get unmatched suppression warnings by cppcheck 1.90 on inline suppressions in disabled code.
    For example:

    #if FOO
    
    void foo()
    {
        static constexpr bool enabled = true;
    
        // cppcheck-suppress knownConditionTrueFalse
        if(enabled) std::cout << "Hello World"  << std::endl;
    }
    
    #endif // FOO
    

    With enabled code:

    $ cppcheck --enable=all --inline-suppr -DFOO=1 foo.cpp 
    Checking foo.cpp ...
    Checking foo.cpp: FOO_ENABLED=1...
    

    That was to be expected.
    But if I disable the code, I get this warning:

    $ cppcheck --enable=all --inline-suppr -DFOO=0 foo.cpp
    Checking foo.cpp ...
    Checking foo.cpp: FOO_ENABLED=0...
    test.cpp:8:0: information: Unmatched suppression: knownConditionTrueFalse [unmatchedSuppression]
        if(enabled) std::cout << "Hello World"  << std::endl;
    ^
    

    Is this behaviour intended?

     

    Last edit: Dennis Mierke 2020-03-08
  • Daniel Marjamäki

    It is not intended. There is a ticket: https://trac.cppcheck.net/ticket/5704

    It's not very straightforward to fix this unfortunately. The suppressions are extracted from the "raw tokens" as far as I remember and that contains all code, even code that is defined out. Well maybe we can add a pass after preprocessing that removes inline suppressions that don't "have code".

    If you have time to look at this.. feel free to submit a PR at github.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.