From: Craig Topper Date: Sat, 15 Mar 2014 07:47:46 +0000 (+0000) Subject: [C++11] Add 'override' keyword to virtual methods that override their base class. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=04fc58fb9e62b27655658b4ef793b3d5748d7dac;p=clang [C++11] Add 'override' keyword to virtual methods that override their base class. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204002 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/arcmt-test/arcmt-test.cpp b/tools/arcmt-test/arcmt-test.cpp index 518d06f2ad..28331c279b 100644 --- a/tools/arcmt-test/arcmt-test.cpp +++ b/tools/arcmt-test/arcmt-test.cpp @@ -83,17 +83,17 @@ public: PrintTransforms(raw_ostream &OS) : Ctx(0), OS(OS) { } - virtual void start(ASTContext &ctx) { Ctx = &ctx; } - virtual void finish() { Ctx = 0; } + void start(ASTContext &ctx) override { Ctx = &ctx; } + void finish() override { Ctx = 0; } - virtual void insert(SourceLocation loc, StringRef text) { + void insert(SourceLocation loc, StringRef text) override { assert(Ctx); OS << "Insert: "; printSourceLocation(loc, *Ctx, OS); OS << " \"" << text << "\"\n"; } - virtual void remove(CharSourceRange range) { + void remove(CharSourceRange range) override { assert(Ctx); OS << "Remove: "; printSourceRange(range, *Ctx, OS); diff --git a/tools/clang-check/ClangCheck.cpp b/tools/clang-check/ClangCheck.cpp index 011cd3fad8..4fc970c0d1 100644 --- a/tools/clang-check/ClangCheck.cpp +++ b/tools/clang-check/ClangCheck.cpp @@ -96,7 +96,7 @@ public: FixWhatYouCan = ::FixWhatYouCan; } - std::string RewriteFilename(const std::string& filename, int &fd) { + std::string RewriteFilename(const std::string& filename, int &fd) override { assert(llvm::sys::path::is_absolute(filename) && "clang-fixit expects absolute paths only."); @@ -123,15 +123,15 @@ public: : clang::FixItRewriter(Diags, SourceMgr, LangOpts, FixItOpts) { } - virtual bool IncludeInDiagnosticCounts() const { return false; } + bool IncludeInDiagnosticCounts() const override { return false; } }; /// \brief Subclasses \c clang::FixItAction so that we can install the custom /// \c FixItRewriter. class FixItAction : public clang::FixItAction { public: - virtual bool BeginSourceFileAction(clang::CompilerInstance& CI, - StringRef Filename) { + bool BeginSourceFileAction(clang::CompilerInstance& CI, + StringRef Filename) override { FixItOpts.reset(new FixItOptions); Rewriter.reset(new FixItRewriter(CI.getDiagnostics(), CI.getSourceManager(), CI.getLangOpts(), FixItOpts.get())); diff --git a/tools/diagtool/DiagTool.h b/tools/diagtool/DiagTool.h index 93d531babb..b1e69f38c3 100644 --- a/tools/diagtool/DiagTool.h +++ b/tools/diagtool/DiagTool.h @@ -62,7 +62,7 @@ class CLSNAME : public diagtool::DiagTool {\ public:\ CLSNAME() : DiagTool(NAME, DESC) {}\ virtual ~CLSNAME() {}\ - virtual int run(unsigned argc, char *argv[], llvm::raw_ostream &out);\ + int run(unsigned argc, char *argv[], llvm::raw_ostream &out) override;\ };\ diagtool::RegisterDiagTool Register##CLSNAME;\ } diff --git a/tools/libclang/CIndexCodeCompletion.cpp b/tools/libclang/CIndexCodeCompletion.cpp index e13e3e18a2..591294599d 100644 --- a/tools/libclang/CIndexCodeCompletion.cpp +++ b/tools/libclang/CIndexCodeCompletion.cpp @@ -537,11 +537,11 @@ namespace { AllocatedResults(Results), CCTUInfo(Results.CodeCompletionAllocator), TU(TranslationUnit) { } ~CaptureCompletionResults() { Finish(); } - - virtual void ProcessCodeCompleteResults(Sema &S, - CodeCompletionContext Context, - CodeCompletionResult *Results, - unsigned NumResults) { + + void ProcessCodeCompleteResults(Sema &S, + CodeCompletionContext Context, + CodeCompletionResult *Results, + unsigned NumResults) override { StoredResults.reserve(StoredResults.size() + NumResults); for (unsigned I = 0; I != NumResults; ++I) { CodeCompletionString *StoredCompletion @@ -614,10 +614,10 @@ namespace { AllocatedResults.ContainerIsIncomplete = 1; } } - - virtual void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, - OverloadCandidate *Candidates, - unsigned NumCandidates) { + + void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg, + OverloadCandidate *Candidates, + unsigned NumCandidates) override { StoredResults.reserve(StoredResults.size() + NumCandidates); for (unsigned I = 0; I != NumCandidates; ++I) { CodeCompletionString *StoredCompletion @@ -630,13 +630,13 @@ namespace { StoredResults.push_back(R); } } - - virtual CodeCompletionAllocator &getAllocator() { + + CodeCompletionAllocator &getAllocator() override { return *AllocatedResults.CodeCompletionAllocator; } - virtual CodeCompletionTUInfo &getCodeCompletionTUInfo() { return CCTUInfo; } - + CodeCompletionTUInfo &getCodeCompletionTUInfo() override { return CCTUInfo;} + private: void Finish() { AllocatedResults.Results = new CXCompletionResult [StoredResults.size()]; diff --git a/tools/libclang/CIndexDiagnostic.cpp b/tools/libclang/CIndexDiagnostic.cpp index a5440b4dfb..cf9dc6f240 100644 --- a/tools/libclang/CIndexDiagnostic.cpp +++ b/tools/libclang/CIndexDiagnostic.cpp @@ -51,32 +51,35 @@ public: Message(Msg), Loc(L) {} virtual ~CXDiagnosticCustomNoteImpl() {} - - CXDiagnosticSeverity getSeverity() const { + + CXDiagnosticSeverity getSeverity() const override { return CXDiagnostic_Note; } - - CXSourceLocation getLocation() const { + + CXSourceLocation getLocation() const override { return Loc; } - - CXString getSpelling() const { + + CXString getSpelling() const override { return cxstring::createRef(Message.c_str()); } - - CXString getDiagnosticOption(CXString *Disable) const { + + CXString getDiagnosticOption(CXString *Disable) const override { if (Disable) *Disable = cxstring::createEmpty(); return cxstring::createEmpty(); } - - unsigned getCategory() const { return 0; } - CXString getCategoryText() const { return cxstring::createEmpty(); } - unsigned getNumRanges() const { return 0; } - CXSourceRange getRange(unsigned Range) const { return clang_getNullRange(); } - unsigned getNumFixIts() const { return 0; } - CXString getFixIt(unsigned FixIt, CXSourceRange *ReplacementRange) const { + unsigned getCategory() const override { return 0; } + CXString getCategoryText() const override { return cxstring::createEmpty(); } + + unsigned getNumRanges() const override { return 0; } + CXSourceRange getRange(unsigned Range) const override { + return clang_getNullRange(); + } + unsigned getNumFixIts() const override { return 0; } + CXString getFixIt(unsigned FixIt, + CXSourceRange *ReplacementRange) const override { if (ReplacementRange) *ReplacementRange = clang_getNullRange(); return cxstring::createEmpty(); @@ -93,9 +96,9 @@ public: virtual ~CXDiagnosticRenderer() {} - virtual void beginDiagnostic(DiagOrStoredDiag D, - DiagnosticsEngine::Level Level) { - + void beginDiagnostic(DiagOrStoredDiag D, + DiagnosticsEngine::Level Level) override { + const StoredDiagnostic *SD = D.dyn_cast(); if (!SD) return; @@ -109,13 +112,13 @@ public: if (Level != DiagnosticsEngine::Note) CurrentSet = &CD->getChildDiagnostics(); } - - virtual void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - StringRef Message, - ArrayRef Ranges, - const SourceManager *SM, - DiagOrStoredDiag D) { + + void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, + StringRef Message, + ArrayRef Ranges, + const SourceManager *SM, + DiagOrStoredDiag D) override { if (!D.isNull()) return; @@ -127,20 +130,20 @@ public: CXDiagnosticImpl *CD = new CXDiagnosticCustomNoteImpl(Message, L); CurrentSet->appendDiagnostic(CD); } - - virtual void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, - DiagnosticsEngine::Level Level, - ArrayRef Ranges, - const SourceManager &SM) {} - - virtual void emitCodeContext(SourceLocation Loc, - DiagnosticsEngine::Level Level, - SmallVectorImpl& Ranges, - ArrayRef Hints, - const SourceManager &SM) {} - - virtual void emitNote(SourceLocation Loc, StringRef Message, - const SourceManager *SM) { + + void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc, + DiagnosticsEngine::Level Level, + ArrayRef Ranges, + const SourceManager &SM) override {} + + void emitCodeContext(SourceLocation Loc, + DiagnosticsEngine::Level Level, + SmallVectorImpl& Ranges, + ArrayRef Hints, + const SourceManager &SM) override {} + + void emitNote(SourceLocation Loc, StringRef Message, + const SourceManager *SM) override { CXSourceLocation L; if (SM) L = translateSourceLocation(*SM, LangOpts, Loc); diff --git a/tools/libclang/CIndexDiagnostic.h b/tools/libclang/CIndexDiagnostic.h index b1c3978e0a..31ae902eac 100644 --- a/tools/libclang/CIndexDiagnostic.h +++ b/tools/libclang/CIndexDiagnostic.h @@ -121,35 +121,35 @@ struct CXStoredDiagnostic : public CXDiagnosticImpl { virtual ~CXStoredDiagnostic() {} /// \brief Return the severity of the diagnostic. - virtual CXDiagnosticSeverity getSeverity() const; - + CXDiagnosticSeverity getSeverity() const override; + /// \brief Return the location of the diagnostic. - virtual CXSourceLocation getLocation() const; + CXSourceLocation getLocation() const override; /// \brief Return the spelling of the diagnostic. - virtual CXString getSpelling() const; + CXString getSpelling() const override; /// \brief Return the text for the diagnostic option. - virtual CXString getDiagnosticOption(CXString *Disable) const; - + CXString getDiagnosticOption(CXString *Disable) const override; + /// \brief Return the category of the diagnostic. - virtual unsigned getCategory() const; - + unsigned getCategory() const override; + /// \brief Return the category string of the diagnostic. - virtual CXString getCategoryText() const; + CXString getCategoryText() const override; /// \brief Return the number of source ranges for the diagnostic. - virtual unsigned getNumRanges() const; - + unsigned getNumRanges() const override; + /// \brief Return the source ranges for the diagnostic. - virtual CXSourceRange getRange(unsigned Range) const; + CXSourceRange getRange(unsigned Range) const override; /// \brief Return the number of FixIts. - virtual unsigned getNumFixIts() const; + unsigned getNumFixIts() const override; /// \brief Return the FixIt information (source range and inserted text). - virtual CXString getFixIt(unsigned FixIt, - CXSourceRange *ReplacementRange) const; + CXString getFixIt(unsigned FixIt, + CXSourceRange *ReplacementRange) const override; static bool classof(const CXDiagnosticImpl *D) { return D->getKind() == StoredDiagnosticKind; diff --git a/tools/libclang/CXLoadedDiagnostic.h b/tools/libclang/CXLoadedDiagnostic.h index d4b11d530f..c281f9be3e 100644 --- a/tools/libclang/CXLoadedDiagnostic.h +++ b/tools/libclang/CXLoadedDiagnostic.h @@ -29,36 +29,36 @@ public: virtual ~CXLoadedDiagnostic(); /// \brief Return the severity of the diagnostic. - virtual CXDiagnosticSeverity getSeverity() const; - + CXDiagnosticSeverity getSeverity() const override; + /// \brief Return the location of the diagnostic. - virtual CXSourceLocation getLocation() const; - + CXSourceLocation getLocation() const override; + /// \brief Return the spelling of the diagnostic. - virtual CXString getSpelling() const; - + CXString getSpelling() const override; + /// \brief Return the text for the diagnostic option. - virtual CXString getDiagnosticOption(CXString *Disable) const; - + CXString getDiagnosticOption(CXString *Disable) const override; + /// \brief Return the category of the diagnostic. - virtual unsigned getCategory() const; - + unsigned getCategory() const override; + /// \brief Return the category string of the diagnostic. - virtual CXString getCategoryText() const; - + CXString getCategoryText() const override; + /// \brief Return the number of source ranges for the diagnostic. - virtual unsigned getNumRanges() const; - + unsigned getNumRanges() const override; + /// \brief Return the source ranges for the diagnostic. - virtual CXSourceRange getRange(unsigned Range) const; - + CXSourceRange getRange(unsigned Range) const override; + /// \brief Return the number of FixIts. - virtual unsigned getNumFixIts() const; - + unsigned getNumFixIts() const override; + /// \brief Return the FixIt information (source range and inserted text). - virtual CXString getFixIt(unsigned FixIt, - CXSourceRange *ReplacementRange) const; - + CXString getFixIt(unsigned FixIt, + CXSourceRange *ReplacementRange) const override; + static bool classof(const CXDiagnosticImpl *D) { return D->getKind() == LoadedDiagnosticKind; } diff --git a/tools/libclang/Indexing.cpp b/tools/libclang/Indexing.cpp index 24c1362217..55e6e79873 100644 --- a/tools/libclang/Indexing.cpp +++ b/tools/libclang/Indexing.cpp @@ -253,8 +253,8 @@ public: IndexPPCallbacks(Preprocessor &PP, IndexingContext &indexCtx) : PP(PP), IndexCtx(indexCtx), IsMainFileEntered(false) { } - virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason, - SrcMgr::CharacteristicKind FileType, FileID PrevFID) { + void FileChanged(SourceLocation Loc, FileChangeReason Reason, + SrcMgr::CharacteristicKind FileType, FileID PrevFID) override { if (IsMainFileEntered) return; @@ -267,15 +267,11 @@ public: } } - virtual void InclusionDirective(SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - const FileEntry *File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported) { + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, + StringRef FileName, bool IsAngled, + CharSourceRange FilenameRange, const FileEntry *File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported) override { bool isImport = (IncludeTok.is(tok::identifier) && IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import); IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled, @@ -283,25 +279,21 @@ public: } /// MacroDefined - This hook is called whenever a macro definition is seen. - virtual void MacroDefined(const Token &Id, const MacroDirective *MD) { - } + void MacroDefined(const Token &Id, const MacroDirective *MD) override {} /// MacroUndefined - This hook is called whenever a macro #undef is seen. /// MI is released immediately following this callback. - virtual void MacroUndefined(const Token &MacroNameTok, - const MacroDirective *MD) { - } + void MacroUndefined(const Token &MacroNameTok, + const MacroDirective *MD) override {} /// MacroExpands - This is called by when a macro invocation is found. - virtual void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, - SourceRange Range, const MacroArgs *Args) { - } + void MacroExpands(const Token &MacroNameTok, const MacroDirective *MD, + SourceRange Range, const MacroArgs *Args) override {} /// SourceRangeSkipped - This hook is called when a source range is skipped. /// \param Range The SourceRange that was skipped. The range begins at the /// #if/#else directive and ends after the #endif/#else directive. - virtual void SourceRangeSkipped(SourceRange Range) { - } + void SourceRangeSkipped(SourceRange Range) override {} }; //===----------------------------------------------------------------------===// @@ -318,24 +310,24 @@ public: // ASTConsumer Implementation - virtual void Initialize(ASTContext &Context) { + void Initialize(ASTContext &Context) override { IndexCtx.setASTContext(Context); IndexCtx.startedTranslationUnit(); } - virtual void HandleTranslationUnit(ASTContext &Ctx) { + void HandleTranslationUnit(ASTContext &Ctx) override { if (SKCtrl) SKCtrl->finished(); } - virtual bool HandleTopLevelDecl(DeclGroupRef DG) { + bool HandleTopLevelDecl(DeclGroupRef DG) override { IndexCtx.indexDeclGroupRef(DG); return !IndexCtx.shouldAbort(); } /// \brief Handle the specified top-level declaration that occurred inside /// and ObjC container. - virtual void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) { + void HandleTopLevelDeclInObjCContainer(DeclGroupRef D) override { // They will be handled after the interface is seen first. IndexCtx.addTUDeclInObjCContainer(D); } @@ -343,9 +335,9 @@ public: /// \brief This is called by the AST reader when deserializing things. /// The default implementation forwards to HandleTopLevelDecl but we don't /// care about them when indexing, so have an empty definition. - virtual void HandleInterestingDecl(DeclGroupRef D) {} + void HandleInterestingDecl(DeclGroupRef D) override {} - virtual void HandleTagDeclDefinition(TagDecl *D) { + void HandleTagDeclDefinition(TagDecl *D) override { if (!IndexCtx.shouldIndexImplicitTemplateInsts()) return; @@ -353,14 +345,14 @@ public: IndexCtx.indexDecl(D); } - virtual void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) { + void HandleCXXImplicitFunctionInstantiation(FunctionDecl *D) override { if (!IndexCtx.shouldIndexImplicitTemplateInsts()) return; IndexCtx.indexDecl(D); } - virtual bool shouldSkipFunctionBody(Decl *D) { + bool shouldSkipFunctionBody(Decl *D) override { if (!SKCtrl) { // Always skip bodies. return true; @@ -395,8 +387,8 @@ class CaptureDiagnosticConsumer : public DiagnosticConsumer { SmallVector Errors; public: - virtual void HandleDiagnostic(DiagnosticsEngine::Level level, - const Diagnostic &Info) { + void HandleDiagnostic(DiagnosticsEngine::Level level, + const Diagnostic &Info) override { if (level >= DiagnosticsEngine::Error) Errors.push_back(StoredDiagnostic(level, Info)); } @@ -422,8 +414,8 @@ public: : IndexCtx(clientData, indexCallbacks, indexOptions, cxTU), CXTU(cxTU), SKData(skData) { } - virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, - StringRef InFile) { + ASTConsumer *CreateASTConsumer(CompilerInstance &CI, + StringRef InFile) override { PreprocessorOptions &PPOpts = CI.getPreprocessorOpts(); if (!PPOpts.ImplicitPCHInclude.empty()) { @@ -446,17 +438,17 @@ public: return new IndexingConsumer(IndexCtx, SKCtrl.get()); } - virtual void EndSourceFileAction() { + void EndSourceFileAction() override { indexDiagnostics(CXTU, IndexCtx); } - virtual TranslationUnitKind getTranslationUnitKind() { + TranslationUnitKind getTranslationUnitKind() override { if (IndexCtx.shouldIndexImplicitTemplateInsts()) return TU_Complete; else return TU_Prefix; } - virtual bool hasCodeCompletionSupport() const { return false; } + bool hasCodeCompletionSupport() const override { return false; } }; //===----------------------------------------------------------------------===//