Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell Cppcheck to skip a header file

Cppcheck scans all files in a project folder:

c:\projectfolder\main.c
c:\projectfolder\file.c
c:\projectfolder\file.h
c:\projectfolder\file_test.cc

c:\projectfolder\file_test.cc contains the following code

#include "c:/gtest/gtest.h"

extern "C"
{
    #include "TMyStruct.h"
}

TEST(Stack, Overflow)
{
    TMyStruct unterTest;
    EXPECT_EQ(1, TMyStruct_Init(&unterTest));
    EXPECT_GE(unterTest.variable, 9000);
}

File file_test.cc includes the gtest.h file

C:\gtest\gtest.h

All files in C:\gtest\ should not be tested.

I call

cppcheck.exe -ic:\gtest\ c:\projectfolder\ --enable=style --template="SomeError"

Errors are found and reported in c:\projectfolder\file_test.cc coming from the included gtest.h (detail: "too many #ifdef configurations").

How do I tell Cppcheck to not look at C:\gtest\gtest.h at all?

like image 728
Johannes Avatar asked Dec 11 '22 20:12

Johannes


2 Answers

I am a Cppcheck developer. I don't think you can skip a header file. Perhaps -i should work like that.

Feel free to create a ticket about this: http://sourceforge.net/apps/trac/cppcheck/

like image 161
Daniel Marjamäki Avatar answered Feb 11 '23 12:02

Daniel Marjamäki


My project structure looks like this:

├── build
├── lib
│   └── dep
│       └── dep.h
├── src
│   ├── code.c
│   └── code.h
└── tests
    └── code_test.c

To suppress warnings for lib includes, I did this:

cppcheck --enable=all --suppress='*:lib/*' -Isrc -Itests ./src ./tests 1>/dev/null

Maybe this should work on Windows:

cppcheck.exe --suppress='*:c:\gtest\*' c:\projectfolder\

My Cppcheck version is 1.74.

Reference:

Allow ignoring results from header files

like image 22
Hugo do Carmo Avatar answered Feb 11 '23 14:02

Hugo do Carmo