2014-10-20 33 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'。

非常感謝!