2014-10-20 32 views
0

我刚刚学习关于How to write RecursiveASTVisitor based ASTFrontendActions的clang工具。 我遵循文档中的示例并编译示例代码,并且总是有一个错误。我不知道为什么它有这个错误以及如何解决它。我没有找到相关问题的解决方案。我不知道是否遇到同样的问题并解决问题。编译Clang工具时出错递归ASTVisitor:错误:冲突返回类型CreateASTConsumer

/home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:44:31:error:冲突返回类型指定为'虚拟铿锵: :ASTConsumer * FindNamedClassAction :: CreateASTConsumer(clang :: CompilerInstance &,llvm :: StringRef)' 从/ home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class- decls/FindClassDecls.cpp:4:0: /home/sun/project/clang-llvm/llvm/tools/clang/include/clang/Frontend/FrontendAction.h:64:40:error:overriding'virtual std :: unique_ptr clang :: FrontendAction :: CreateASTConsumer(clang :: CompilerInstance &,llvm :: StringRef)' ninja:build stopped:子命令失败。

谢谢!

回答

0

糟糕。我已经更新了文档的其余部分。它应该是这样的:

class FindNamedClassAction : public clang::ASTFrontendAction { 
public: 
    virtual std::unique_ptr<clang::ASTConsumer> CreateASTConsumer(
    clang::CompilerInstance &Compiler, llvm::StringRef InFile) { 
    return std::unique_ptr<clang::ASTConsumer>(
     new FindNamedClassConsumer(&Compiler.getASTContext())); 
    } 
}; 
0

r215323开始,FrontendAction::CreateASTConsumer改为返回一个std :: unique_ptr < clang :: ASTConsumer >。我已经更新了http://clang.llvm.org/docs/RAVFrontendAction.html的文档以反映这一点。

+0

嗨尼克,根据你的答案,我改变了代码,仍然存在一个错误,不能转换'((&(&Compiler) - > clang :: CompilerInstance :: (FindNamedClassConsumer *)) - > FindNamedClassConsumer :: FindNamedClassConsumer(),((FindNamedClassConsumer *)))))'从'FindNamedClassConsumer *'到'std :: unique_ptr' 。 – sun 2014-10-21 15:58:49

0

当我更改为std :: unique_ptr。与此同时,我保持返回新的FindNamedClassConsumer(& Compiler.getASTContext());不像你已经更新了文档“return new FindNamedClassConsumer;”。现在当我编译FindClassDecls.cpp时,还有一个错误。

/home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:46:64:错误:无法转换“((&(&编译器) - > clang :: CompilerInstance :: getASTContext()),(operator new(24ul),(((FindNamedClassConsumer *)) - > FindNamedClassConsumer :: FindNamedClassConsumer(),((FindNamedClassConsumer *)))))'from' FindNamedClassConsumer *'到'std :: unique_ptr'。

非常感谢!