I've just started running cppcheck to see if it helps show any issues with my project. I'd like it not to tell me about any issues in some files - headers under some folders and local files matching certain patterns.
I am using Visual Studio, and the project is using Qt 3.
I am finding that the results I am seeing are telling me that there are issues with the Qt header files. While that may well be entirely correct I'm not sure it's particularly helpful to know about. I'm not going to change these headers, or the Qt source, and they are really old so the the vendor won't either.
Ok, I thought, lets just ask cppcheck to ignore anything in that folder. I think it still needs to read the qt include folders so it gets the symbols set-up, but I don't want it to do any analysis there, I noticed that there is a place to enter files or folders to be ignored, but that doesn't seem to be doing what I'd like.
Also, part of the Qt build process automatically generates some extra cpp files which I want to ignore. In this case the file-names match a pattern (All start with moc_, so matching "^moc_.+.cpp$"). I would also like to suppress any issues in these, as their contents are entirely created by Qt tools which I can't change.
Can anyone advise whether I can configure cppcheck to ignore files in the way I'm describing here?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Basically I feel that you should get better results if you use --library=qt instead of including the qt headers. However Qt3 is pretty old. And maybe our qt.cfg will not work very well for various reasons. But one issue related to that is https://trac.cppcheck.net/ticket/13236 to handle SLOT better.
If you want that the qt headers are included in the analysis anyway but don't want to see Cppcheck warnings in those you should use suppressions. You can for instance specify that all warnings in filename /usr/include/*should be suppressed.
I normally don't analyse the moc output files at all. But if you do that you can for instance suppress all warnings in */moc_*.cpp
How exactly you suppress depends on if you specify the suppressions in the GUI project file, on the command line, or in a suppressions file. The manual specifies the format you can use.
Last edit: Daniel Marjamäki 2025-01-16
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
-i <dir or file> Give a source file or source file directory to exclude
from the check. This applies only to source files so
header files included by source files are not matched.
Directory name is matched to all parts of the path.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've just started running cppcheck to see if it helps show any issues with my project. I'd like it not to tell me about any issues in some files - headers under some folders and local files matching certain patterns.
I am using Visual Studio, and the project is using Qt 3.
I am finding that the results I am seeing are telling me that there are issues with the Qt header files. While that may well be entirely correct I'm not sure it's particularly helpful to know about. I'm not going to change these headers, or the Qt source, and they are really old so the the vendor won't either.
Ok, I thought, lets just ask cppcheck to ignore anything in that folder. I think it still needs to read the qt include folders so it gets the symbols set-up, but I don't want it to do any analysis there, I noticed that there is a place to enter files or folders to be ignored, but that doesn't seem to be doing what I'd like.
Also, part of the Qt build process automatically generates some extra cpp files which I want to ignore. In this case the file-names match a pattern (All start with moc_, so matching "^moc_.+.cpp$"). I would also like to suppress any issues in these, as their contents are entirely created by Qt tools which I can't change.
Can anyone advise whether I can configure cppcheck to ignore files in the way I'm describing here?
Basically I feel that you should get better results if you use
--library=qt
instead of including the qt headers. However Qt3 is pretty old. And maybe our qt.cfg will not work very well for various reasons. But one issue related to that is https://trac.cppcheck.net/ticket/13236 to handle SLOT better.If you want that the qt headers are included in the analysis anyway but don't want to see Cppcheck warnings in those you should use suppressions. You can for instance specify that all warnings in filename
/usr/include/*
should be suppressed.I normally don't analyse the moc output files at all. But if you do that you can for instance suppress all warnings in
*/moc_*.cpp
How exactly you suppress depends on if you specify the suppressions in the GUI project file, on the command line, or in a suppressions file. The manual specifies the format you can use.
Last edit: Daniel Marjamäki 2025-01-16
There's also