【发布时间】:2017-07-11 06:46:44
【问题描述】:
给定一个函数模板如:
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 被推断为引用类型的情况(表示传递了一个左值),但我不知道如何将functionDecl 预期的Matcher<FunctionDecl> 连接到Matcher<TemplateSpecializationType>从hasTemplateArgument返回。
我正在使用 Clang 3.8,以防万一(online docs 似乎是 5.0.0,http://releases.llvm.org/3.8.0/tools/clang/docs/LibASTMatchersReference.html 给出 404)。
【问题讨论】:
标签: c++ clang abstract-syntax-tree perfect-forwarding clang-ast-matchers