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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)