clang-tidy
v10.0.0似乎忽略了我的NOLINT
或NOLINTNEXTLINE
指令。使用这个简单的compile_commands.json
[
{
"directory": "/home/cmannett85/workspace/scratch/build",
"command": "/usr/lib/ccache/g++-10 -g -Werror -Wall -Wextra -std=c++2a -o main.cpp.o -c /home/cmannett85/workspace/scratch/main.cpp",
"file": "/home/cmannett85/workspace/scratch/main.cpp"
}
]
和这个琐碎的源文件:
#include <ranges>
#include <vector>
#include <iostream>
int main()
{
auto v = std::vector{0, 1, 2, 3, 4};
for (auto i : v | std::views::reverse) { // NOLINT
std::cout << i << std::endl;
}
return EXIT_SUCCESS;
}
生成以下clang-tidy
输出:
$ clang-tidy -p . --quiet ./main.cpp
2 warnings and 6 errors generated.
Error while processing /home/cmannett85/workspace/scratch/main.cpp.
/home/cmannett85/workspace/scratch/main.cpp:8:21: error: invalid operands to binary expression ('std::vector<int, std::allocator<int> >' and 'const __adaptor::_RangeAdaptorClosure<(lambda at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ranges:3280:9)>' (aka 'const std::ranges::views::__adaptor::_RangeAdaptorClosure<std::ranges::views::(lambda at /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/ranges:3280:9)>')) [clang-diagnostic-error]
for (auto i : v | std::views::reverse) { // NOLINT
...
现在我可以原谅这个虚假的错误,因为它太新了,可能缺乏对C++20范围的支持,但是为什么clang-tidy
忽略了我的NOLINT
指令?
发布于 2020-07-10 18:39:26
clang-tidy
程序有时会出现误报,或者以其他方式识别出有问题的区域,这些区域可能(给定您的平台)是已知的实现定义的行为,可能不一定符合标准。
您可以通过传入命令行定义(如-DCLANG_TIDY
)让clang-tidy
忽略这些部分,然后在代码中使用您希望clang-tidy
忽略的#ifndef CLANG_TIDY
... #endif
块。
这是一种实用的变通方法。
https://stackoverflow.com/questions/62838193
复制相似问题