[cfe-dev] Recover TypeDecl* from QualType

Richard Smith richard at metafoo.co.uk
Sun Jul 7 16:16:02 PDT 2013


On Sun, Jul 7, 2013 at 2:42 PM, Victor Vicente de Carvalho
<victor.v.carvalho at gmail.com> wrote:
> 2013/7/7 Eli Friedman <eli.friedman at gmail.com>
>>
>> On Sun, Jul 7, 2013 at 10:14 AM, Victor Vicente de Carvalho
>> <victor.v.carvalho at gmail.com> wrote:
>> > 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.



More information about the cfe-dev mailing list