我正在尝试使用 clang 的 AST 匹配器来定位如下代码:
#include<memory>
namespace Demo {
class Widget {};
}
int main () {
auto w = std::make_unique<Demo::Widget>();
}
在 clang-query 中,我尝试了以下方法:
callExpr(callee(functionDecl(
// including only this arg gives matches
hasName("make_unique"),
// adding this second arg produces zero matches
hasTemplateArgument(0, refersToType(asString("Demo::Widget")))
)))
我也试过refersToType(...)
换成
refersToDeclaration(cxxRecordDecl(isSameOrDerivedFrom("Demo::Widget")))
这也给出了零匹配。我可以使用什么来针对std::make_unique
特定类型的模板化调用?