Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ clang tidy 10忽略了我的NOLINT命令_C++_Clang Tidy - Fatal编程技术网

C++ clang tidy 10忽略了我的NOLINT命令

C++ clang tidy 10忽略了我的NOLINT命令,c++,clang-tidy,C++,Clang Tidy,clangtidyv10.0.0似乎忽略了我的NOLINT或NOLINTNEXTLINE说明。使用这个简单的编译\u命令.json: [ { "directory": "/home/cmannett85/workspace/scratch/build", "command": "/usr/lib/ccache/g++-10 -g -Werror -Wall -Wextra -std=c++2a -o main.cpp.

clangtidy
v10.0.0似乎忽略了我的
NOLINT
NOLINTNEXTLINE
说明。使用这个简单的
编译\u命令.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;
}

现在我可以原谅这个错误,因为C++20范围的支持可能是缺乏的,因为它太新了,但是为什么
clangtidy
忽略了我的
NOLINT
指令?

clangtidy
程序有时会出现误报,或者以其他方式确定可能存在问题的领域(给定您的平台)是已知的实现定义的行为,可能不一定符合标准

您可以通过传入命令行定义,例如
-DCLANG\u-tidy
,让
clang-tidy
忽略这些部分,然后使用
\ifndef clang\u-tidy
#endif
代码中要忽略的块


这是一个务实的解决办法。

NOLINT
抑制叮当声警告。它不会抑制错误。@Eljay-Ugh。现在我重新阅读了文档,它只明确地说了警告。有没有办法对错误进行等效处理?
clangtidy-DCLANG\u tidy-p--安静./main.cpp
然后
#如果声音叮当#整洁
<代码>#endif在代码中。@Eljay谢谢,它很笨重但可以理解。回答你的意见,我会接受的。
$ 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
        ...