我使用以下方法在Ubuntu上安装了clang-tidy:
/root/Index.html => <a href="members/biographies.html#John_Lewis">
/root/members/biographies.html => <a href="../Index.html">
我在一个简单的C ++ 17文件上运行它,并收到警告和错误:
sudo apt install clang-tidy
如何根据c ++ 17标准告诉clang-tidy检查此文件?
注意:要构建程序,我运行:
/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>();
答案 0 :(得分:1)
Depending on your compiler / clang-tidy version, the default C++ standard version used to compile source files may vary. clang's default std version is gnu++-98
(or gnu++-14
starting with clang 6.0), and typically clang-tidy has the same defaults as clang.
I'm guessing that -std=c++17
(or -std=c++1z
) isn't specified in the C++ compiler flags, used for compiling ptr.cpp
, so clang-tidy falls back to the default -std=gnu++98
, and therefore gives warnings for C++11 code.
For asking clang-tidy to handle C++17, you should specify the -std
flag as suggested by @n.m., as parameter to the -extra-arg
option, for example:
clang-tidy -p . ptr.cpp -extra-arg=-std=c++17
Edit:
Since clang++-5.0
is used for compiling ptr.cpp
, it may be a good idea to use the matching clang-tidy version, 5.0 (on Ubuntu 16.04, the default clang-tidy version installed through apt is 3.8), that is:
clang-tidy-5.0 -p . ptr.cpp -extra-arg=-std=c++17
If not already installed, you could grab it from:
https://www.ubuntuupdates.org/package/xorg-edgers/xenial/main/base/clang-tidy-5.0