Menu

Regression when using --project= option: Include file: ... not found. (

2023-07-07
2023-07-08
  • Dominique Pelle

    Dominique Pelle - 2023-07-07

    Hi. I see a regression in cppcheck introduced between those 2 commits:

    7fd4118d606b64dcb1c324d37248210a27094347  Mar 04 2023 -> FAIL <--- regression
    50eb0641b9f1b0db4321a01713fbeed4a54ed304  Mar 04 2023 -> OK
    

    I analyze my project with cppecheck using using the compilation database (i.e. compile_commands.json file) in order to find compilation options (#defines, include path...) like this:

    $ cd cppcheck
    $ ./cppcheck --inconclusive --enable=all --project=...path_to_my_project.../compile_commands.json
    

    This worked find but got broken on March 4 2023 (and is still broken as of today 2023/07/07) since this commit:

    commit 7fd4118d606b64dcb1c324d37248210a27094347 (HEAD)
    Author: Oliver Stöneberg <firewave@users.noreply.github.com>
    Date:   Sat Mar 4 09:02:35 2023 +0100
    
        Fix #10039 (integrate `--check-config` include findings with normal analysis) / also fixes #11283 (#3229)
    

    Since this commit, I get a bunch of errors like this:

    /.../foo.cpp.cpp:14:0: information: Include file: <cassert> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    
    ^
    /.../foo.cpp:15:0: information: Include file: <cstring> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]
    

    cppcheck cannot find any includes (std includes and projects includes). Going back to the older version of cppcheck 50eb0641b9f1b0db4321a01713fbeed4a54ed304 everything works fine.

    I'm surprised this is not fixed after several months. Surely I most not be the only one using cppcheck with a compilation database compile_commands.json.

     
  • CHR

    CHR - 2023-07-07

    Why do you think that the missingIncludeSystem warnings are incorrect? You should be able to suppress them if you wish.

     
  • Dominique Pelle

    Dominique Pelle - 2023-07-07

    CHR wrote:

    Why do you think that the missingIncludeSystem warnings are incorrect?
    You should be able to suppress them if you wish.

    cppcheck should be able to find all includes (system and application specific includes),
    since the compilation database should give all the include paths.

    As I wrote, I it reports this not only for system includes but also for includes
    from my application. The same compile_command.json works fine with plenty of other tools such as clang-format, clang-tidy, clangd, include-what-you-use.

     
  • CHR

    CHR - 2023-07-07

    The commit that you identified merely enabled missingInclude* under more circumstances, so things were likely broken before.
    Can you share any details about your compile_commands.json?

     
  • Daniel Marjamäki

    I think it's reasonable for a user to assume that there won't be missing include warnings when the compile database is used.

    However the include paths for <cassert> etc are not usually provided on the command line and therefore it's not provided in the compile database. The compiler looks in various system paths such as /usr/include by default. You can compile a minimal helloworld program with gcc like this:

    gcc -o helloworld main.cpp
    

    There is no need to provide the path for <iostream> on the command line.

    Cppcheck does not look in /usr/include by default. And we do that by intention.

    I think you should NOT provide the include path for cassert and other standard headers. I recommend that you just ignore and suppress the warnings about the standard headers.

     

    Last edit: Daniel Marjamäki 2023-07-08

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.