diff options
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp | 14 | ||||
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.h | 9 |
2 files changed, 15 insertions, 8 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp index ddec9d91b97..043540666d3 100644 --- a/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.cpp @@ -249,11 +249,19 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) { if (EditDistance > 0 && EditDistance <= EditDistanceThreshold) { if (checkOverrideWithoutName(Context, BaseMD, DerivedMD)) { // A "virtual near miss" is found. - diag(DerivedMD->getLocStart(), - "method '%0' has a similar name and the same signature as " - "virtual method '%1'; did you mean to override it?") + auto Range = CharSourceRange::getTokenRange( + SourceRange(DerivedMD->getLocation())); + + bool ApplyFix = !BaseMD->isTemplateInstantiation() && + !DerivedMD->isTemplateInstantiation(); + auto Diag = + diag(DerivedMD->getLocStart(), + "method '%0' has a similar name and the same signature as " + "virtual method '%1'; did you mean to override it?") << DerivedMD->getQualifiedNameAsString() << BaseMD->getQualifiedNameAsString(); + if (ApplyFix) + Diag << FixItHint::CreateReplacement(Range, BaseMD->getName()); } } } diff --git a/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.h b/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.h index f4dad0f9af9..4e108f22ce3 100644 --- a/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.h +++ b/clang-tools-extra/clang-tidy/misc/VirtualNearMissCheck.h @@ -12,7 +12,6 @@ #include "../ClangTidy.h" #include <map> -#include <string> namespace clang { namespace tidy { @@ -46,12 +45,12 @@ private: bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD, const CXXRecordDecl *DerivedRD); - /// key: the unique ID of a method; - /// value: whether the method is possible to be overridden. + /// Key: the unique ID of a method. + /// Value: whether the method is possible to be overridden. std::map<const CXXMethodDecl *, bool> PossibleMap; - /// key: <unique ID of base method, name of derived class> - /// value: whether the base method is overridden by some method in the derived + /// Key: <unique ID of base method, name of derived class> + /// Value: whether the base method is overridden by some method in the derived /// class. std::map<std::pair<const CXXMethodDecl *, const CXXRecordDecl *>, bool> OverriddenMap; |