c++clanglibclanglibtooling

Definition data of ClassTemplateSpecializationDecl is null


I recieve a class alt::VectorLayout<int, 4> for example, as a ClassTemplateSpecializationDecl and I'm trying to process the field and methods of the class, but it fails on an assertion where the definition data is null. I have the presumption that the template specialization is a forward declaration so it's not instantiated, but I couldn't figure out how to instantiate, even when all the template parameters are provided.

Is it possible to recieve the ClassTemplateSpecializationDecl with a non-null definition data or somehow instantiate it to fill in the definition data?


Solution

  • I could solve the issue with Sema::RequireCompleteType.
    I found that there would be no way to retrieve the Sema purely from a ClangTool instance. Instead of processing the source files with ClangTool, I made a CompilerInstance where the instance of the Sema was retrievable and ran a FrontendAction on the CompilerInstance.

    CompilerInstance impl: https://github.com/7Hazard/altv-capi/blob/master/src/main.cpp#L111
    Sema::RequireCompleteType usage: https://github.com/7Hazard/altv-capi/blob/master/src/templateClass.cpp#L46