给定一个函数模板,例如:
template <typename T> void function(T &&t) { /*...*/ }
如何找到对传递右值的函数的调用:
function(1); // MATCH
int i;
function(i); // SKIP
int foo();
function(foo()); // MATCH
...
你明白了。
我在想类似的事情:
callExpr(callee(functionDecl(
hasName("function"),
unless(hasTemplateArgument(0,
refersToType(references(anything()))))))
过滤掉T
被推断为引用类型的情况(表示传递了一个左值),但我不知道如何将Matcher<FunctionDecl>
预期的 by连接functionDecl
到Matcher<TemplateSpecializationType>
返回的 from hasTemplateArgument
。
我正在使用 Clang 3.8,以防万一(在线文档似乎是 5.0.0,并且http://releases.llvm.org/3.8.0/tools/clang/docs/LibASTMatchersReference.html给出了 404 )。