Clang 叮当作响的AST匹配器:“operator()”没有CXXMethodDel?

Clang 叮当作响的AST匹配器:“operator()”没有CXXMethodDel?,clang,clang-ast-matchers,Clang,Clang Ast Matchers,我在文件中有以下struct定义: template <class... EventArgs> struct banana { template <class... Args> void operator()(Args&&... args) const { _f(std::forward<Args>(args)...); } private: std::function<void(Even

我在文件中有以下
struct
定义:

template <class... EventArgs>
struct banana {
    template <class... Args>
    void operator()(Args&&... args) const {
        _f(std::forward<Args>(args)...);
    }

private:
    std::function<void(EventArgs...)> _f;
};
My
MatchFinder::MatchCallback
子类正在运行
CxRecordDecl
for事件,但是
methods()
返回的范围为空:

void ClassInfo::run(const MatchFinder::MatchResult& Result) {
    auto clas = Result.Nodes.getNodeAs<clang::CXXRecordDecl>("class");

    for (const auto& method : clas->methods()) {
        // Not getting run - methods() is empty?
    }
}
void ClassInfo::run(const MatchFinder::MatchResult&Result){
auto clas=Result.Nodes.getNodeAs(“类”);
对于(const auto&method:clas->methods()){
//无法获取run-methods()是否为空?
}
}
我缺少什么?

嗯,
clas->methods()
只在
结构的顶层返回
cxxmethoddel
s。 但是在您的
结构中,只有
函数TemplateDecl
。 所以,你可能想做这样的事情:

for (const auto &decl : clas->decls()) {
  if (auto *templ = dyn_cast<FunctionTemplateDecl>(&decl)) {
    // Use templ->getTemplatedDecl to get FunctionDecl.
  }
}
for(const auto&decl:clas->decls()){
if(自动*模板=动态投射(&decl)){
//使用templ->getTemplatedDecl获取函数decl。
}
}
注意。我没有实际测试或编译该代码,但希望您能从中了解到这一点

for (const auto &decl : clas->decls()) {
  if (auto *templ = dyn_cast<FunctionTemplateDecl>(&decl)) {
    // Use templ->getTemplatedDecl to get FunctionDecl.
  }
}