void VirtualNearMissCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
- cxxMethodDecl(unless(anyOf(isOverride(), cxxConstructorDecl(),
- cxxDestructorDecl(), cxxConversionDecl(),
- isStatic(), isOverloadedOperator())))
+ cxxMethodDecl(
+ unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
+ cxxDestructorDecl(), cxxConversionDecl(), isStatic(),
+ isOverloadedOperator())))
.bind("method"),
this);
}
assert(DerivedRD);
for (const auto &BaseSpec : DerivedRD->bases()) {
- const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl();
- if (const auto *TST =
- dyn_cast<TemplateSpecializationType>(BaseSpec.getType())) {
- auto TN = TST->getTemplateName();
- BaseRD =
- dyn_cast<CXXRecordDecl>(TN.getAsTemplateDecl()->getTemplatedDecl());
- }
-
- if (BaseRD) {
+ if (const auto *BaseRD = BaseSpec.getType()->getAsCXXRecordDecl()) {
for (const auto *BaseMD : BaseRD->methods()) {
if (!isPossibleToBeOverridden(BaseMD))
continue;
auto Range = CharSourceRange::getTokenRange(
SourceRange(DerivedMD->getLocation()));
- diag(DerivedMD->getBeginLoc(),
- "method '%0' has a similar name and the same signature as "
- "virtual method '%1'; did you mean to override it?")
+ bool ApplyFix = !BaseMD->isTemplateInstantiation() &&
+ !DerivedMD->isTemplateInstantiation();
+ auto Diag =
+ diag(DerivedMD->getBeginLoc(),
+ "method '%0' has a similar name and the same signature as "
+ "virtual method '%1'; did you mean to override it?")
<< DerivedMD->getQualifiedNameAsString()
- << BaseMD->getQualifiedNameAsString()
- << FixItHint::CreateReplacement(Range, BaseMD->getName());
+ << BaseMD->getQualifiedNameAsString();
+ if (ApplyFix)
+ Diag << FixItHint::CreateReplacement(Range, BaseMD->getName());
}
}
}
struct TDerived : TBase<T> {
virtual void tfunk(T t);
// Should not apply fix for template.
- // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived::tfunk' has {{.*}} 'TBase::tfunc'
- // CHECK-FIXES: virtual void tfunc(T t);
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: method 'TDerived<double>::tfunk' has {{.*}} 'TBase<double>::tfunc'
+ // CHECK-MESSAGES: :[[@LINE-3]]:3: warning: method 'TDerived<int>::tfunk' has {{.*}} 'TBase<int>::tfunc'
+ // CHECK-FIXES: virtual void tfunk(T t);
};
TDerived<int> T1;