How can I tell Cppcheck to skip a header file
Asked Answered
R

2

5

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?

Radarscope answered 27/11, 2012 at 19:35 Comment(0)
F
3

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

Foresight answered 12/7, 2016 at 17:45 Comment(0)
W
12

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

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

Water answered 28/11, 2012 at 17:56 Comment(7)
I would love to write /*ccpcheck::startignore*/ ... /*ccpcheck::endignore*/Radarscope
I think that would be acceptable. I added a ticket (sourceforge.net/apps/trac/cppcheck/ticket/4377). I can't promise that we'll fix the ticket soon.. so if you have the time feel free to take a look at it.Indirection
well,... i am stuck otherwise :) How do i join the project?Radarscope
Found a way around it for now. I call cppcheck for each files individually and leave out those that have external code imported via headers.Radarscope
Any progress on this feature?Deposal
According to the manual (cppcheck.sourceforge.net/manual.pdf) page 7 states that the i option can be used to ignore files.Altissimo
Nevermind, I was mistaken, -i is only for source files.Altissimo
F
3

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

Foresight answered 12/7, 2016 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.