使用 compile_commands.json 时 Cppcheck 内联抑制
Cppcheck inline suppression when using compile_commands.json
我正在尝试了解 cppcheck,因此我将它集成到我的示例项目的 travis 构建中。多亏了 cppcheck,我解决了很多问题,但是我想通过内联抑制忽略一些误报。
a.cpp
struct A {
int i;
};
// cppcheck-suppress unusedFunction
A operator+(const A &a1, const A &a2) {
return A{a1.i + a2.i};
}
int main() {
return 0;
}
compile_commands.json
[
{
"directory": "/path/to/source",
"command": "/usr/bin/clang++-9 -std=gnu++17 -o a.o -c a.cpp",
"file": "a.cpp"
}
]
当我 运行 cppcheck(版本 1.82)作为 cppcheck --enable=all --inline-suppr a.cpp
时就可以了。但是当我 运行 它与像 cppcheck --enable=all --inline-suppr --project=compile_commands.json
这样的 compile_commands.json 文件一起使用时,我得到了以下结果:
Checking a.cpp ...
[a.cpp:6]: (style) The function 'operator+' is never used.
cppcheck 在上述情况下表现不同的原因是否有任何记录?如果不是,这可能是一个错误?
我认为这是 1.82 版中的一个错误,因为在较新的版本中它运行良好。
我正在尝试了解 cppcheck,因此我将它集成到我的示例项目的 travis 构建中。多亏了 cppcheck,我解决了很多问题,但是我想通过内联抑制忽略一些误报。
a.cpp
struct A {
int i;
};
// cppcheck-suppress unusedFunction
A operator+(const A &a1, const A &a2) {
return A{a1.i + a2.i};
}
int main() {
return 0;
}
compile_commands.json
[
{
"directory": "/path/to/source",
"command": "/usr/bin/clang++-9 -std=gnu++17 -o a.o -c a.cpp",
"file": "a.cpp"
}
]
当我 运行 cppcheck(版本 1.82)作为 cppcheck --enable=all --inline-suppr a.cpp
时就可以了。但是当我 运行 它与像 cppcheck --enable=all --inline-suppr --project=compile_commands.json
这样的 compile_commands.json 文件一起使用时,我得到了以下结果:
Checking a.cpp ...
[a.cpp:6]: (style) The function 'operator+' is never used.
cppcheck 在上述情况下表现不同的原因是否有任何记录?如果不是,这可能是一个错误?
我认为这是 1.82 版中的一个错误,因为在较新的版本中它运行良好。