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