Typedef templates

Hello everyone,

I’m new to clang and this is my first post, so please forgive me for what may be a basic question.

I have a template like this:

template <class T, class U, class V>
class MyTemplate {
public:
T var1 ;
U var2 ;
V var3 ;
} ;

And I have a typedef like this:

typedef MyTemplate< double , int , short > MyTemplateTypedef ;

What I’m trying to find is somewhere that stores the template with the arguments substituted in. I have seen some of the template instantiating routines in Sema, but cannot figure out how to use them. Am I on the right track here?

Thanks in advance,

Alex

I forgot to mention that I have gotten as far as writing a RecursiveASTVisitor and have found the TemplateSpecilizationType node where I can get both the original template and the argument list. I just don’t know how to put them together.

Thanks,

Alex

To quote from the TemplateSpecializationType docs:

  A non-dependent template specialization type is always "sugar", typically for a RecordType.

You can use getAs<RecordType>() to check whether it's a record type (it will be unless the template is a C++11 template alias), and then pull the RecordDecl out of that. It will be a ClassTemplateSpecializationDecl (again, unless the template is a C++11 template alias that happens to resolve to a non-templated class).

Note that just writing a typedef of a template specialization type does not require (or even allow) instantiation of the template, so the ClassTemplateSpecializationDecl will not necessarily have a definition, and even if the class does, its member functions may not.

John.