diff options
author | Alexander Kornienko <alexfh@google.com> | 2016-04-04 14:31:36 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2016-04-04 14:31:36 +0000 |
commit | 09464e63d842e1e0e6be300b6bb59bc9c1e7ecdf (patch) | |
tree | 0e3a899d441530e52facc1841ca4986dd53c504d /clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp | |
parent | 193b99c53c9d6a3fb221cf2dcebc5fb7b76d0fd3 (diff) | |
download | bcm5719-llvm-09464e63d842e1e0e6be300b6bb59bc9c1e7ecdf.tar.gz bcm5719-llvm-09464e63d842e1e0e6be300b6bb59bc9c1e7ecdf.zip |
[clang-tidy] fix a couple of modernize-use-override bugs
Fix for __declspec attributes and const=0 without space
This patch is to address 2 problems I found with Clang-tidy:modernize-use-override.
1: missing spaces on pure function decls.
Orig:
void pure() const=0
Problem:
void pure() constoverride =0
Fixed:
void pure() const override =0
2: This is ms-extension specific, but possibly applies to other attribute types. The override is placed before the attribute which doesn’t work well with declspec as this attribute can be inherited or placed before the method identifier.
Orig:
class __declspec(dllexport) X : public Y
{
void p();
};
Problem:
class override __declspec(dllexport) class X : public Y
{
void p();
};
Fixed:
class __declspec(dllexport) class X : public Y
{
void p() override;
};
Patch by Robert Bolter!
Differential Revision: http://reviews.llvm.org/D18396
llvm-svn: 265298
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp index a335748301c..81fa73f95c5 100644 --- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp @@ -95,9 +95,9 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { : "'override' is"; StringRef Correct = HasFinal ? "'final'" : "'override'"; - Message = - (llvm::Twine(Redundant) + - " redundant since the function is already declared " + Correct).str(); + Message = (llvm::Twine(Redundant) + + " redundant since the function is already declared " + Correct) + .str(); } DiagnosticBuilder Diag = diag(Method->getLocation(), Message); @@ -118,9 +118,11 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { if (!HasFinal && !HasOverride) { SourceLocation InsertLoc; StringRef ReplacementText = "override "; + SourceLocation MethodLoc = Method->getLocation(); for (Token T : Tokens) { - if (T.is(tok::kw___attribute)) { + if (T.is(tok::kw___attribute) && + !Sources.isBeforeInTranslationUnit(T.getLocation(), MethodLoc)) { InsertLoc = T.getLocation(); break; } @@ -128,11 +130,12 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { if (Method->hasAttrs()) { for (const clang::Attr *A : Method->getAttrs()) { - if (!A->isImplicit()) { + if (!A->isImplicit() && !A->isInherited()) { SourceLocation Loc = Sources.getExpansionLoc(A->getRange().getBegin()); - if (!InsertLoc.isValid() || - Sources.isBeforeInTranslationUnit(Loc, InsertLoc)) + if ((!InsertLoc.isValid() || + Sources.isBeforeInTranslationUnit(Loc, InsertLoc)) && + !Sources.isBeforeInTranslationUnit(Loc, MethodLoc)) InsertLoc = Loc; } } @@ -163,6 +166,9 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) { Tokens.back().is(tok::kw_delete)) && GetText(Tokens[Tokens.size() - 2], Sources) == "=") { InsertLoc = Tokens[Tokens.size() - 2].getLocation(); + // Check if we need to insert a space. + if ((Tokens[Tokens.size() - 2].getFlags() & Token::LeadingSpace) == 0) + ReplacementText = " override "; } else if (GetText(Tokens.back(), Sources) == "ABSTRACT") { InsertLoc = Tokens.back().getLocation(); } |