c++ - clang-tooling:如何检查一个字段是否是一个不完整的构造类型?
问题描述
我想编写一个匹配器,它排除包含不完整类型的类,例如:
std::unique_ptr<ForwardDeclared>
,但它没有被标识为一个,因为它是一个模板类型(我认为是这样)。有谁知道如何规避这个?
最小代码:
// ...
class MoveDefaultToDecl: public MatchFinder::MatchCallback {
// ...
public:
void run(const MatchFinder::MatchResult& r) override {
// ...
auto const* class_decl = r.Nodes.getNodeAs<CXXRecordDecl>("method-class");
auto iter = std::find_if(class_decl->field_begin(), class_decl->field_end(),
[](auto const& field) { return field->getType()->isIncompleteType(); });
if (iter != class_decl->field_end()) {
return;
}
// ...
}
// ...
}
test.h
#pragma once
#include <memory>
class H {
H();
~H() = delete;
};
class MyType;
class K {
K();
~K();
std::unique_ptr<MyType> ptr_;
};
test.cpp
#include "test.h"
class MyType {
// But not here:
MyType() = default;
// But not here:
~MyType() = default;
int i;
};
// CHECK: :[[@LINE+1]]:3: note: "xyz" binds here
H::H() = default;
// But not here
K::K() = default; // Actually binds here
// But not here
K::~K() = default; // Actually binds here
解决方案
推荐阅读
- excel - Excel 无法设置 ColumnWidth
- ruby-on-rails - Mongo::Error::OperationFailure ([8000:AtlasError]: noTimeout cursors are not allowed in this atlas tier
- javascript - 使用 JavaScript 的 HTML 表格的类似 Excel 的过滤器
- python - 没有错误,但仍然没有从麦克风获取任何输入。Flac 问题或者可能需要在 mac m1 中做一些不同的事情?
- unity3d - 在 Unity 中创建服务器,无需任何人作为主机
- eclipse - 无法从任何配置的存储库解析原型 org.apache.maven.archetypes:maven-archetype-quickstart:RELEASE
- javascript - 当我更改屏幕分辨率时,ExtJs 列值不断移动或不对齐
- docker - Docker 卷挂载没有 IP 地址的 Windows 共享文件夹
- laravel-livewire - 如何在模板中调用 livewire 方法?
- java - 通过类
改造不同网络服务的接口