<div dir="ltr">Hi Eric,<div><br></div><div>`A<T>` in `class Temp` definition is a dependent name (see <a href="http://eel.is/c++draft/temp.dep">http://eel.is/c++draft/temp.dep</a>) whereas in `class Temp` specialization it is not (it is instantiated as `A<int>`). In case of dependent names, clang will not offer you any additional details about the construct because semantics of such a construct may differ from one instantiation to another.</div><div><br></div><div>I had a very similar question few days ago (<a href="http://lists.llvm.org/pipermail/cfe-dev/2017-January/052376.html">http://lists.llvm.org/pipermail/cfe-dev/2017-January/052376.html</a>). Although I am not using AST matcher, but rather libclang directly, I did end up implementing heuristic method for extracting the details that I needed and which seems to be quite applicable in my target use-case. I am not sure about your use-case and how flexible AST matcher is but you might want to try to jump to the declaration of dependent-name node and then walk through it to get more details which you need.</div><div><br></div><div>Cheers,</div><div>Adi</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 8 February 2017 at 18:55, Eric Liu via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr" class="m_2845122542868735971gmail_msg">Hi all,<div class="m_2845122542868735971gmail_msg"><br class="m_2845122542868735971gmail_msg"></div><div class="m_2845122542868735971gmail_msg">I am trying to match type references of `class A` in the following code:</div><div class="m_2845122542868735971gmail_msg"><pre class="m_2845122542868735971gmail_msg"> template <typename T>
class A {};
</pre><pre class="m_2845122542868735971gmail_msg"> template <typename T>
class Temp {
A<int> a;
A<T> at;
};</pre><pre class="m_2845122542868735971gmail_msg"><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg">with matcher:</div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg"> typeLoc(loc(qualType(<wbr>hasDeclaration(cxxRecordDecl(<wbr>hasName("A"))))))</div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg"><br class="m_2845122542868735971gmail_msg"></div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg">However, only `A<int>` matches, and `A<T>` only matches after I added an instantiation of the template (e.g. `Temp<int> t;`).</div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg"><br class="m_2845122542868735971gmail_msg"></div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg">I also dumped the AST, and it seems that `A<T>` is only associated with the `class A` in `<wbr>ClassTemplateSpecializationDec<wbr>l` of `Temp` but not `ClassTemplateDecl` (highlighted below).</div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg"><br class="m_2845122542868735971gmail_msg"></div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg">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!</div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg"><pre class="m_2845122542868735971gmail_msg"><div class="m_2845122542868735971gmail_msg" style="font-family:sans-serif;white-space:normal"><pre class="m_2845122542868735971gmail_msg"><br class="m_2845122542868735971inbox-inbox-Apple-interchange-newline">|-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 <b class="m_2845122542868735971gmail_msg">'A<T>'</b>
| `-<wbr>ClassTemplateSpecializationDec<wbr>l 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 <b class="m_2845122542868735971gmail_msg">'A<int>':'class A<int>'</b>
| |-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> &&'</pre><pre class="m_2845122542868735971gmail_msg"><br></pre></div></pre></div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg">Regards,</div><div style="font-family:sans-serif;white-space:normal" class="m_2845122542868735971gmail_msg">Eric</div></pre></div></div></div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>