summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/misc/UseOverride.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/UseOverride.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/misc/UseOverride.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/UseOverride.cpp b/clang-tools-extra/clang-tidy/misc/UseOverride.cpp
index 04a920b32df..9c3b5b63209 100644
--- a/clang-tools-extra/clang-tidy/misc/UseOverride.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseOverride.cpp
@@ -57,6 +57,9 @@ static StringRef GetText(const Token &Tok, const SourceManager &Sources) {
}
void UseOverride::check(const MatchFinder::MatchResult &Result) {
+ if (!Result.Context->getLangOpts().CPlusPlus11)
+ return;
+
const FunctionDecl *Method = Result.Nodes.getStmtAs<FunctionDecl>("method");
const SourceManager &Sources = *Result.SourceManager;
@@ -78,11 +81,26 @@ void UseOverride::check(const MatchFinder::MatchResult &Result) {
if (!OnlyVirtualSpecified && KeywordCount == 1)
return; // Nothing to do.
- DiagnosticBuilder Diag = diag(
- Method->getLocation(),
- OnlyVirtualSpecified
- ? "Prefer using 'override' or (rarely) 'final' instead of 'virtual'"
- : "Annotate this function with 'override' or (rarely) 'final'");
+ std::string Message;
+
+ if (OnlyVirtualSpecified) {
+ Message =
+ "prefer using 'override' or (rarely) 'final' instead of 'virtual'";
+ } else if (KeywordCount == 0) {
+ Message = "annotate this function with 'override' or (rarely) 'final'";
+ } else {
+ StringRef Redundant =
+ HasVirtual ? (HasOverride && HasFinal ? "'virtual' and 'override' are"
+ : "'virtual' is")
+ : "'override' is";
+ StringRef Correct = HasFinal ? "'final'" : "'override'";
+
+ Message =
+ (llvm::Twine(Redundant) +
+ " redundant since the function is already declared " + Correct).str();
+ }
+
+ DiagnosticBuilder Diag = diag(Method->getLocation(), Message);
CharSourceRange FileRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Method->getSourceRange()), Sources,
@@ -146,7 +164,7 @@ void UseOverride::check(const MatchFinder::MatchResult &Result) {
CharSourceRange::getTokenRange(OverrideLoc, OverrideLoc));
}
- if (Method->isVirtualAsWritten()) {
+ if (HasVirtual) {
for (Token Tok : Tokens) {
if (Tok.is(tok::kw_virtual)) {
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
OpenPOWER on IntegriCloud