<div class="gmail_quote">On Thu Aug 28 2014 at 12:02:11 PM Alexander Kornienko <<a href="mailto:alexfh@google.com">alexfh@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
================<br>
Comment at: include/clang/ASTMatchers/<u></u>ASTMatchers.h:2970-2982<br>
@@ -2969,1 +2969,15 @@<br>
<br>
+/// \brief Matches declarations or statements that are contained in a function<br>
+/// or class template instantiation.<br>
+///<br>
+/// Given<br>
+/// \code<br>
+///   template<typename T> void A(T t) { T i; }<br>
+///   A(0);<br>
+///   A(0U);<br>
+/// \endcode<br>
+/// stmt(<u></u>isInTemplateInstantiation())<br>
+///   matches 'int i;' and 'unsigned i;'.<br>
+///<br>
+/// Usable as: Matcher<Decl>, Matcher<Stmt><br>
+AST_POLYMORPHIC_MATCHER(<u></u>isInTemplateInstantiation,<br>
----------------<br>
klimek wrote:<br>
> Perhaps add comment that this will not match if the node itself is a template instantiation (so functionDecl(<u></u>isInTemplateInstantiation()) will not match anything here).<br>
><br>
> I'd also add a comment about node sharing; for example, given<br>
> int j;<br>
> template<typename T> void A(T t) { T i; j += 42; int x; }<br>
>   stmt(unless(<u></u>isInTemplateInstnatiation()))<br>
> will not match j += 42 (because the template independent node is shared between the definition and the instantiations), but will match 'T i;' (with the dependent type), because the dependent nodes cannot be shared.<br>

> Funnily enough 'int x' *will* match (as will any further statement referencing x); I have no idea why the node cannot be shared, which is why node sharing always makes me feel cautious.<br>
><br>
> Of course:<br>
>   stmt(<u></u>isInTemplateInstnatiation())<br>
> will match all.<br>
><br>
> Perhaps add comment that this will not match if the node itself is a template instantiation<br>
<br>
Maybe add a separate version for decl, which will handle this? Something along the lines of:<br>
<br>
    auto IsInstantiation = decl(anyOf(recordDecl(<u></u>isTemplateInstantiation()),<br>
                                      functionDecl(<u></u>isTemplateInstantiation())));<br>
    auto InnerMatcher = decl(anyOf(isInstantiation, hasAncestor(isInstantiation));<br></blockquote><div><br></div><div>That's what I have used before, too.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
<a href="http://reviews.llvm.org/D5085" target="_blank">http://reviews.llvm.org/D5085</a><br>
<br>
<br>
</blockquote></div>