Ere*_*evi 8 c++ c++17 clang-tidy
我使用以下命令在 Ubuntu 上安装了 clang-tidy:
sudo apt install clang-tidy
Run Code Online (Sandbox Code Playgroud)
我在一个简单的 C++ 17 文件上运行它,并收到警告和错误:
/home/erelsgl/Dropbox/ariel/CPLUSPLUS/intro/01-single-file/ptr.cpp:17:3: warning: 'auto' type specifier is a C++11 extension [clang-diagnostic-c++11-extensions]
auto i = make_unique<int>();
^
/home/erelsgl/Dropbox/ariel/CPLUSPLUS/intro/01-single-file/ptr.cpp:17:12: error: use of undeclared identifier 'make_unique' [clang-diagnostic-error]
auto i = make_unique<int>();
Run Code Online (Sandbox Code Playgroud)
我如何告诉 clang-tidy 根据 c++17 标准检查这个文件?
注意:要构建程序,我运行:
clang++-5.0 --std=c++17 ptr.cpp
Run Code Online (Sandbox Code Playgroud)
val*_*ano 15
根据您的编译器/ clang-tidy 版本,用于编译源文件的默认 C++ 标准版本可能会有所不同。clang 的默认标准版本是gnu++-98(或gnu++-14从 clang 6.0 开始),并且通常 clang-tidy 具有与 clang 相同的默认值。
我猜测-std=c++17(或-std=c++1z) 未在 C++ 编译器标志中指定,用于编译ptr.cpp,因此 clang-tidy 回退到默认值-std=gnu++98,因此对 C++11 代码发出警告。
要让 clang-tidy 处理 C++17,您应该指定-std@nm 建议的标志作为-extra-arg选项的参数,例如:
clang-tidy -p . ptr.cpp -extra-arg=-std=c++17
编辑:
由于clang++-5.0用于编译ptr.cpp,因此最好使用匹配的 clang-tidy 版本 5.0(在 Ubuntu 16.04 上,通过 apt 安装的默认 clang-tidy 版本为 3.8),即:
clang-tidy-5.0 -p . ptr.cpp -extra-arg=-std=c++17
如果尚未安装,您可以从以下位置获取:https :
//www.ubuntuupdates.org/package/xorg-edgers/xenial/main/base/clang-tidy-5.0
| 归档时间: |
|
| 查看次数: |
8307 次 |
| 最近记录: |