我正在使用clang-tidy作为开发中的“线性”工具。我开始将第3方软件集成到我的代码中,并在使用它们包含头文件时使用:
-I/path/to/include
Run Code Online (Sandbox Code Playgroud)
产生了大量错误,我什#include至还没有标题。
error: too many errors emitted, stopping now [clang-diagnostic-error]
...
/path/to/include/wchar.h:81:1: error: unknown type name 'wint_t' [clang-diagnostic-error]
wint_t fgetwc(FILE *__stream);
^
/path/to/include/wchar.h:81:15: error: unknown type name 'FILE' [clang-diagnostic-error]
wint_t fgetwc(FILE *__stream);
^
...
Run Code Online (Sandbox Code Playgroud)
我使用以下命令编译程序:
/usr/bin/clang-tidy-4.0 /path/to/main.cpp -checks=-*,cppcoreguidelines* -- -lang-c++ -I/path/to/include -std=gnu++11 -Wall -Werror -O0 -g -D<define variables>
Run Code Online (Sandbox Code Playgroud)
似乎这些“ lang诊”错误不会停止编译,因为它会继续编译并运行良好。是否有一个标志可以关闭/抑制该错误?我不想看到它,因为我没有写这些头文件。
如果我摆脱了争论,-I/path/to/include一切都会顺利进行,没有错误。
自从ccache在我们的CI服务器上使用以来,我们发现在构建时间方面的瓶颈现在是我们的静态分析过程clang-tidy,以及其他工具。有人知道有一种clang-tidy类似于ccache普通编译器的加速方法吗?
我是 NDK 的新手。刚刚升级到Android Studio 3.5.2,在Ubuntu 16.04上安装了LLDB 3.1.4508709,NDK(并排)21.0.6113669,CMake 3.6.4111459(顺便说一句,界面很糟糕)。
从模板创建了一个新的 Native C++ 项目。
每次打开cpp文件,窗口顶部都会出现一条粉红色的消息:
无法执行 Clang-Tidy:无法为 JavaBean 创建属性=诊断=com.jetbrains.cidr.lang.daemon.clang.tidy.ClangTidyYamlLoader...
消息太长,无法适应窗口。它仅在 Ubuntu 上发生,在 Mac 上,相同的 IDE 版本工作正常。其他一切似乎都正常 - 在模拟器上构建、运行/调试。只是这个消息很烦人。有任何想法吗?
我有项目将 Clang-tidy 配置设置如下
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=google-*,cppcoreguidelines-*;")
Run Code Online (Sandbox Code Playgroud)
但是,我注意到它正在检查甚至不在当前存储库中的所有文件,例如
/opt/ros/melodic/include/ros/console.h
Run Code Online (Sandbox Code Playgroud)
以及子模块的所有 .h/.hpp 文件...
我试图添加一个正则表达式来过滤目标 .h 文件,但无法让它工作......我已经为单个 .hpp 文件提供了绝对路径,但它仍在评估/opt/ros/melodic/include文件......
我可以举一个关于标题过滤器的例子吗??
如果 hpp 在过滤器中,我假设 clang-tidy 将检查相应的 cpp 文件。我对么?
我正在努力为我的项目运行 clang-tidy 。我正在尝试为我的项目运行 clang-tidy 以将数据发送到 Codacy。我这样做是这样的:
clang-tidy $PWD -header-filter=.*,-checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* | ./codacy-clang-tidy-1.1.1 | \
curl -XPOST -L -H "project-token: $CODACY_PROJECT_TOKEN" \
-H "Content-type: application/json" -d @- \
"https://api.codacy.com/2.0/commit/$TRAVIS_COMMIT/issuesRemoteResults"
curl -XPOST -L -H "project-token: $CODACY_PROJECT_TOKEN" \
-H "Content-type: application/json" \
"https://api.codacy.com/2.0/commit/$TRAVIS_COMMIT/resultsFinal"
Run Code Online (Sandbox Code Playgroud)
但报错找不到编译数据:
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/home/travis/build/mVento3/Duckvil/build"
No compilation database found in /home/travis/build/mVento3/Duckvil or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while …Run Code Online (Sandbox Code Playgroud) 我有一个获取“Config”结构的函数,目前它只是一个包含数组的结构
class ShmConfig {
public:
std::int64_t shellShmSize[ShellId_Count];
};
Run Code Online (Sandbox Code Playgroud)
我将它传递给函数中的另一个函数std::move,因为我希望复制它的所有代码位置都不知道它可以被有效地复制这一事实。
m_allocator.setup(std::move(config));
Run Code Online (Sandbox Code Playgroud)
如果以后移动它可以更有效(也许因为我添加了一个std::string),它会自动变得更有效率。但clang-tidy建议反对
std::moveconfig普通可复制类型“ ”的变量“ShmConfig”无效;消除std::move()
我不明白为什么这是可取的。用 包裹起来有什么缺点吗move?是否只有在定期运行 clang-tidy 时才应遵循这些建议,以便std::move在添加数据成员时能够发现稍后有意义的情况?
我使用以下命令在 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) 我刚从clang-tidy得到以下警告:
overloaded "operator++" returns a non-constant object
instead of a constant object type
Run Code Online (Sandbox Code Playgroud)
https://clang.llvm.org/extra/clang-tidy/checks/cert-dcl21-cpp.html
不幸的是,他们提供的链接不起作用,https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId = 88046682没有简单的方法来找到这个规则(看似DCL规则开始从50).
但无论我在标准中看到什么(对于ex 16.5.7增量和减量[over.inc]),我都没有找到postfix operator ++应该返回const的引用:
struct X {
X operator++(int); // postfix a++
};
Run Code Online (Sandbox Code Playgroud)
问题:只是铿锵过度保护,错误或为什么我要声明后缀的返回类型为const?
我正在运行 clang-tidy 8.0 并且收到警告:
constructor does not initialize these fields:
在模板化类上使用委托构造函数时。我想知道这是否是我应该压制的误报,或者我的代码是否确实是错误的。
有问题的示例代码是这样的:
template<typename T>
class A
{
public:
explicit A(const std::size_t size) :
data_(nullptr),
data_size_(size)
{
// ...
}
explicit A(const std::vector<T>& b) :
A(b.size())
{
// ...
}
private:
T* data_;
std::size_t data_size_;
};
Run Code Online (Sandbox Code Playgroud)
在此代码上运行 clang-tidy 时:
clang-tidy-8 --checks=* test.cpp
我得到,除其他外:
warning: constructor does not initialize these fields: data_ [cppcoreguidelines-pro-type-member-init]
explicit A(const std::vector<T>& b) : A(b.size()) {}
Run Code Online (Sandbox Code Playgroud)
但是,如果我从类中删除模板并使其成为普通类,则不会出现此类错误。
在模板化类上使用委托构造函数时,我是否遗漏了什么,或者这是 clang-tidy 中的错误?
谢谢!
我希望将所有 for 循环与在其主体中声明的向量相匹配(稍后可能会扩展到 while 循环和 do-while 循环):
\n#include <vector>\n\nint main() {\n for (int i = 0; i < 10; i++) {\n std::vector<int> foo;\n }\n\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n我从这个程序中得到的 AST 是
\n`-FunctionDecl 0x55c1d33c8bc8 <main.cpp:3:1, line:9:1> line:3:5 main \'int ()\'\n `-CompoundStmt 0x55c1d3402a48 <col:12, line:9:1>\n |-ForStmt 0x55c1d34029e0 <line:4:3, line:6:3>\n | |-DeclStmt 0x55c1d33c8d40 <line:4:8, col:17>\n | | `-VarDecl 0x55c1d33c8cb8 <col:8, col:16> col:12 used i \'int\' cinit\n | | `-IntegerLiteral 0x55c1d33c8d20 <col:16> \'int\' 0\n | |-<<<NULL>>>\n | |-BinaryOperator 0x55c1d33c8db0 <col:19, col:23> \'bool\' \'<\'\n …Run Code Online (Sandbox Code Playgroud) clang-tidy ×10
c++ ×9
clang ×2
cmake ×2
android-ndk ×1
c ×1
c++11 ×1
c++17 ×1
ccache ×1
codacy ×1
header-files ×1
linter ×1
ubuntu-16.04 ×1