I recently started experimenting with the clang-tidy llvm tool. Now I am trying to suppress false warnings from third-party library code. For this I want to use command line options
-header-filter=<string> or -line-filter=<string>
but so far unsuccessfully. Therefore, for people with limited time, I asked the question here at the beginning and later I will explain what I have already tried.
Question
What parameter do I need to provide the clang-tidy tool to suppress a warning from a specific line and file?
If this is not possible
Which option works to suppress warnings from external header files?
What have i done so far
My original clang-tidy call is as follows
clang-tidy-3.8 -checks=-*,clang-analyzer-*,-clang-analyzer-alpha* -p Generated/LinuxMakeClangNoPCH Sources/CodeAssistant/ModuleListsFileManipulator_fixtures.cpp
and the first line of the warning I want to suppress looks like this:
.../gmock/gmock-spec-builders.h:1272:5: warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete] return function_mocker_->AddNewExpectation(
The gmock people told me that this is a false positive, so I want to suppress it. At first I tried using the -line-filter=<string> option. The documentation states:
-line-filter=<string> - List of files with line ranges to filter the warnings. Can be used together with -header-filter. The format of the list is a JSON array of objects: [ {"name":"file1.cpp","lines":[[1,3],[5,7]]}, {"name":"file2.h"} ]
I assumed that the warnings in these lines are filtered out. But the dock says if they are filtered or in. After some fiddeling arround, I created a .json file with the contents
[ {"name":"gmock-spec-builders.h","lines":[[1272,1272]]} ]
and changed the command line to
clang-tidy-3.8 -checks=-*,clang-analyzer-*,-clang-analyzer-alpha* -p Generated/LinuxMakeClangNoPCH -line-filter="$(< Sources/CodeAssistant/CodeAssistant_ClangTidySuppressions.json)" Sources/CodeAssistant/ModuleListsFileManipulator_fixtures.cpp
which writes the contents of the file to an argument. This suppresses the warning, but not only this warning, but all warnings from the ModuleListsFileManipulator_fixtures.cpp file. I tried more things, but I could not get it to work.
So, I tried the -header-filter=<string> parameter. Here, the documentation states that you need to provide a regular expression that matches all header files from which the diagnostics should be displayed. Well, I thought, let's use a regualar expression that matches everything in the same folder as the parsed .cpp file. I can live with this, although it can remove warnings that are due to misuse of external headers.
Here I was not sure whether the regular expression should match the full (absolute) file name or only part of the file name. I tried
-header-filter=.*\/CodeAssistant\/.*.h
which matches all absolute header file names in the CodeAssistant folder, but it did not suppress the warnings from the gmock-spec-builders.h file.
Therefore, I would like to suppress each warning individually, so that I can determine for everyone if this is a real problem or not, but if this is not possible, I could also live with suppressing warnings from all external headers.
Thank you for your time.