clang-tooling: How to check if a field is an incomplete type on construction?

I want to write a matcher, which excludes classes containing incomplete types like:
std::unique_ptr<ForwardDeclared>, but it is not identified as one, because it is a template type (I think so). Does anyone know how to circumvent this?

Minimal code:

// ...
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

Source: Windows Questions C++

LEAVE A COMMENT