<div dir="ltr">Thank you for the explanation, Jusufadis! I am just trying to see if I can match a class template reference in a template declaration without going into `<span style="color:rgb(33,33,33)">ClassTemplateSpecializationDec</span><span style="color:rgb(33,33,33)">l</span>` so that I don't need to worry about parameter substitution. But looks like I have to deal with the substitutions.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Feb 8, 2017 at 9:31 PM Jusufadis Bakamovic <<a href="mailto:jbakam@gmail.com">jbakam@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Hi Eric,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">`A<T>` in `class Temp` definition is a dependent name (see <a href="http://eel.is/c++draft/temp.dep" class="gmail_msg" target="_blank">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 class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I had a very similar question few days ago (<a href="http://lists.llvm.org/pipermail/cfe-dev/2017-January/052376.html" class="gmail_msg" target="_blank">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 class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Cheers,</div><div class="gmail_msg">Adi</div></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg"></div></div><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg">On 8 February 2017 at 18:55, Eric Liu via cfe-dev <span dir="ltr" class="gmail_msg"><<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br class="gmail_msg"></div></div><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div dir="ltr" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">Hi all,<div class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><br class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"></div><div class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">I am trying to match type references of `class A` in the following code:</div><div class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><pre class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"> template <typename T>
 class A {};
</pre><pre class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"> template <typename T>
 class Temp {
   A<int> a;
   A<T> at;
 };</pre><pre class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">with matcher:</div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">    typeLoc(loc(qualType(hasDeclaration(cxxRecordDecl(hasName("A"))))))</div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><br class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"></div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_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_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><br class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"></div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">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).</div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><br class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"></div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_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_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><pre class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><div class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg" style="font-family:sans-serif;white-space:normal"><pre class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><br class="m_8750814177513889688m_2845122542868735971inbox-inbox-Apple-interchange-newline gmail_msg">|-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_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">'A<T>'</b>
| `-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 <b class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_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_8750814177513889688m_2845122542868735971gmail_msg gmail_msg"><br class="gmail_msg"></pre></div></pre></div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">Regards,</div><div style="font-family:sans-serif;white-space:normal" class="m_8750814177513889688m_2845122542868735971gmail_msg gmail_msg">Eric</div></pre></div></div></div>
<br class="gmail_msg"></blockquote></div></div><div class="gmail_extra gmail_msg"><div class="gmail_quote gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div>
</blockquote></div>