@@ -216,9 +216,10 @@ bool VirtualNearMissCheck::isOverriddenByDerivedClass(
216
216
217
217
void VirtualNearMissCheck::registerMatchers (MatchFinder *Finder) {
218
218
Finder->addMatcher (
219
- cxxMethodDecl (unless (anyOf (isOverride (), cxxConstructorDecl (),
220
- cxxDestructorDecl (), cxxConversionDecl (),
221
- isStatic (), isOverloadedOperator ())))
219
+ cxxMethodDecl (
220
+ unless (anyOf (isOverride (), isImplicit (), cxxConstructorDecl (),
221
+ cxxDestructorDecl (), cxxConversionDecl (), isStatic (),
222
+ isOverloadedOperator ())))
222
223
.bind (" method" ),
223
224
this );
224
225
}
@@ -233,15 +234,7 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) {
233
234
assert (DerivedRD);
234
235
235
236
for (const auto &BaseSpec : DerivedRD->bases ()) {
236
- const auto *BaseRD = BaseSpec.getType ()->getAsCXXRecordDecl ();
237
- if (const auto *TST =
238
- dyn_cast<TemplateSpecializationType>(BaseSpec.getType ())) {
239
- auto TN = TST->getTemplateName ();
240
- BaseRD =
241
- dyn_cast<CXXRecordDecl>(TN.getAsTemplateDecl ()->getTemplatedDecl ());
242
- }
243
-
244
- if (BaseRD) {
237
+ if (const auto *BaseRD = BaseSpec.getType ()->getAsCXXRecordDecl ()) {
245
238
for (const auto *BaseMD : BaseRD->methods ()) {
246
239
if (!isPossibleToBeOverridden (BaseMD))
247
240
continue ;
@@ -257,12 +250,16 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) {
257
250
auto Range = CharSourceRange::getTokenRange (
258
251
SourceRange (DerivedMD->getLocation ()));
259
252
260
- diag (DerivedMD->getBeginLoc (),
261
- " method '%0' has a similar name and the same signature as "
262
- " virtual method '%1'; did you mean to override it?" )
253
+ bool ApplyFix = !BaseMD->isTemplateInstantiation () &&
254
+ !DerivedMD->isTemplateInstantiation ();
255
+ auto Diag =
256
+ diag (DerivedMD->getBeginLoc (),
257
+ " method '%0' has a similar name and the same signature as "
258
+ " virtual method '%1'; did you mean to override it?" )
263
259
<< DerivedMD->getQualifiedNameAsString ()
264
- << BaseMD->getQualifiedNameAsString ()
265
- << FixItHint::CreateReplacement (Range, BaseMD->getName ());
260
+ << BaseMD->getQualifiedNameAsString ();
261
+ if (ApplyFix)
262
+ Diag << FixItHint::CreateReplacement (Range, BaseMD->getName ());
266
263
}
267
264
}
268
265
}
0 commit comments