c++ - clang-tidy 10 忽略了我的 NOLINT 命令
问题描述
clang-tidy
v10.0.0 似乎忽略了我的NOLINT
orNOLINTNEXTLINE
指示。使用这个微不足道的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
指令?
解决方案
该clang-tidy
程序有时会出现误报,或者以其他方式识别可能(给定您的平台)可能是已知的实现定义的行为的问题区域,这些行为可能不一定符合标准。
您可以clang-tidy
通过传入命令行定义来忽略这些部分,例如-DCLANG_TIDY
, 然后在您想要忽略的代码中使用#ifndef CLANG_TIDY
...块。#endif
clang-tidy
这是一个务实的解决方法。
推荐阅读
- powershell - Powershell Write-Error Write-Warning 自定义格式
- scala - scala中的List[Row]到RDD[CassandrRow]转换
- php - 如何将 PHP 父对象转换/转换为子对象?
- javascript - 使用 javascript 或 jquery 获取数组中的复选框状态
- node.js - 节点无法连接到流浪盒
- ios - 获取结构中嵌套对象的路径
- ssis - 如何为每一行创建一个字段并在每个转换级别中附加一些文本
- r - 根据开始/结束列每月“拆分”数据帧
- java - 当缺少两个重要变量时,如何将对象作为参数提供给对象?
- testing - 共享步骤的 TFS 测试中的不同参数