title: Clang AST Matchers: How to find calls to a perfectly forwarding function called with rvalues?
body: <p>Given a function template such as:</p>
  
  <pre><code>template &lt;typename T&gt; void function(T &amp;&amp;t) { /*...*/ }
  </code></pre>
  
  <p>how do I find calls to the function that pass rvalues:</p>
  
  <pre><code>function(1); // MATCH
  int i;
  function(i); // SKIP
  int foo();
  function(foo()); // MATCH
  ...
  </code></pre>
  
  <p>You get the idea.</p>
  
  <p>I was thinking about something like:</p>
  
  <pre><code>callExpr(callee(functionDecl(
                      hasName("function"),
                      unless(hasTemplateArgument(0,
                          refersToType(references(anything()))))))
  </code></pre>
  
  <p>to filter out the case where <code>T</code> is deduced as a reference type (indicating an lvalue was passed), but I don't see how I can connect the <code>Matcher&lt;FunctionDecl&gt;</code> expected by <code>functionDecl</code> to the <code>Matcher&lt;TemplateSpecializationType&gt;</code> returned from <code>hasTemplateArgument</code>.</p>
  
  <p>I'm using Clang 3.8, in case it matters (the <a href="http://clang.llvm.org/docs/LibASTMatchersReference.html" rel="nofollow noreferrer">online docs</a> seem to be at 5.0.0, and <a href="http://releases.llvm.org/3.8.0/tools/clang/docs/LibASTMatchersReference.html" rel="nofollow noreferrer">http://releases.llvm.org/3.8.0/tools/clang/docs/LibASTMatchersReference.html</a> gives a 404).</p>