[cfe-dev] TypeLoc of a template class type in an uninstantiated template has incomplete type?

Eric Liu via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 8 09:55:23 PST 2017


Hi all,

I am trying to match type references of `class A` in the following code:

 template <typename T>
 class A {};

 template <typename T>
 class Temp {
   A<int> a;
   A<T> at;
 };

with matcher:
    typeLoc(loc(qualType(hasDeclaration(cxxRecordDecl(hasName("A"))))))

However, only `A<int>` matches, and `A<T>` only matches after I added
an instantiation of the template (e.g. `Temp<int> t;`).

I also dumped the AST, and it seems that `A<T>` is only associated
with the `class A` in `ClassTemplateSpecializationDecl` of `Temp` but
not `ClassTemplateDecl` (highlighted below).

Is this expected? If so, could someone explain why TypeLoc `A<T>` in
`ClassTemplateDecl` should not be associated with the actual class A?
Thanks a lot!


|-ClassTemplateDecl 0x7f991815b5d8 <line:4:1, line:8:1> line:5:7 Temp
| |-TemplateTypeParmDecl 0x7f991815b4c0 <line:4:11, col:20> col:20
referenced typename T
| |-CXXRecordDecl 0x7f991815b540 <line:5:1, line:8:1> line:5:7 class
Temp definition
| | |-CXXRecordDecl 0x7f991815b848 <col:1, col:7> col:7 implicit class Temp
| | |-FieldDecl 0x7f991815bbc0 <line:6:3, col:10> col:10 a
'A<int>':'class A<int>'
| | `-FieldDecl 0x7f991815bcc8 <line:7:3, col:8> col:8 at *'A<T>'*
| `-ClassTemplateSpecializationDecl 0x7f991815bd48 <line:4:1,
line:8:1> line:5:7 class Temp definition
|   |-TemplateArgument type 'int'
|   |-CXXRecordDecl 0x7f991818c000 prev 0x7f991815bd48 <col:1, col:7>
col:7 implicit class Temp
|   |-FieldDecl 0x7f991818c098 <line:6:3, col:10> col:10 a
'A<int>':'class A<int>'
|   |-FieldDecl 0x7f991818c198 <line:7:3, col:8> col:8 at
*'A<int>':'class A<int>'*
|   |-CXXConstructorDecl 0x7f991818c220 <line:5:7> col:7 implicit used
constexpr Temp 'void (void) noexcept' inline default trivial
|   | |-CXXCtorInitializer Field 0x7f991818c098 'a' 'A<int>':'class A<int>'
|   | | `-CXXConstructExpr 0x7f991818cc68 <col:7> 'A<int>':'class
A<int>' 'void (void) noexcept'
|   | |-CXXCtorInitializer Field 0x7f991818c198 'at' 'A<int>':'class A<int>'
|   | | `-CXXConstructExpr 0x7f991818ccc0 <col:7> 'A<int>':'class
A<int>' 'void (void) noexcept'
|   | `-CompoundStmt 0x7f991818cd28 <col:7>
|   |-CXXConstructorDecl 0x7f991818c8c8 <col:7> col:7 implicit
constexpr Temp 'void (const class Temp<int> &)' inline default trivial
noexcept-unevaluated 0x7f991818c8c8
|   | `-ParmVarDecl 0x7f991818c9f0 <col:7> col:7 'const class Temp<int> &'
|   `-CXXConstructorDecl 0x7f991818ca88 <col:7> col:7 implicit
constexpr Temp 'void (class Temp<int> &&)' inline default trivial
noexcept-unevaluated 0x7f991818ca88
|     `-ParmVarDecl 0x7f991818cbb0 <col:7> col:7 'class Temp<int> &&'


Regards,
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170208/be459f56/attachment.html>


More information about the cfe-dev mailing list