0
votes

I just learn clang tool about How to write RecursiveASTVisitor based ASTFrontendActions. I followed the example in the documentation and compile the example code, and there was always one error. I don't know why it have this error and how to solve it. I didn't find the solution of related problem. I don't know whether who meet the same problem and solved it.

/home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:44:31: error: conflicting return type specified for ‘virtual clang::ASTConsumer* FindNamedClassAction::CreateASTConsumer(clang::CompilerInstance&, llvm::StringRef)’ In file included from /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: subcommand failed.

Thanks!

3

3 Answers

0
votes

As of r215323, FrontendAction::CreateASTConsumer was changed to return a std::unique_ptr<clang::ASTConsumer> instead. I've updated the documentation on http://clang.llvm.org/docs/RAVFrontendAction.html to reflect that.

0
votes

when I change to std::unique_ptr. At the same time, I keep return new FindNamedClassConsumer(&Compiler.getASTContext()); not like you have updated the documentation "return new FindNamedClassConsumer;". Now When I compile FindClassDecls.cpp, there is still another error.

/home/sun/project/clang-llvm/llvm/tools/clang/tools/extra/find-class-decls/FindClassDecls.cpp:46:64: error: could not convert ‘((&(& Compiler)->clang::CompilerInstance::getASTContext()), (operator new(24ul), (((FindNamedClassConsumer*))->FindNamedClassConsumer::FindNamedClassConsumer(), ((FindNamedClassConsumer*)))))’ from ‘FindNamedClassConsumer*’ to ‘std::unique_ptr’.

Thank you very much!

0
votes

Oops. I've updated the documentation the rest of the way. It should have read:

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()));
  }
};