Recover TypeDecl* from QualType

It’s possible to recover the TypeDecl* from a QualType (or it’s underlying Type*)?

Victor

There isn't a generic method, but you can do it for specific types,
e.g. RecordType has a getDecl() method.

-Eli

Thanks Eli, so It’s just a matter of dyn_cast the Type* to RecordType*?

Another question, what’s the best way to detect is a Type has atemplate parameters?

Victor

Thanks Eli, so It's just a matter of dyn_cast the Type* to RecordType*?

Yes... except that you generally want to use the getAs() method of
Type rather than dyn_cast because getAs automatically looks through
sugar like typedefs.

Another question, what's the best way to detect is a Type has atemplate
parameters?

Depends on what exactly you mean by "has template parameters"... but
CXXRecordDecl::getDescribedClassTemplate might be helpful.

-Eli

> Thanks Eli, so It's just a matter of dyn_cast the Type* to RecordType*?

Yes... except that you generally want to use the getAs() method of
Type rather than dyn_cast because getAs automatically looks through
sugar like typedefs.

> Another question, what's the best way to detect is a Type has atemplate
> parameters?

Depends on what exactly you mean by "has template parameters"... but
CXXRecordDecl::getDescribedClassTemplate might be helpful.

Calling getDescribedClassTemplate on a CXXRecordDecl* for a
std::shared_ptr<X> returns null, and getNumTemplateParameterLists is
returning zero too. The compilation is fine, tough, so it's not a missing
include.

getDescribedClassTemplate is for the class within a template
declaration. To find the template for a class template specialization,
you can dyn_cast the CXXRecordDecl to ClassTemplateSpecializationDecl
and call getSpecializedTemplate.