@@ -216,10 +216,9 @@ bool VirtualNearMissCheck::isOverriddenByDerivedClass(
216
216
217
217
void VirtualNearMissCheck::registerMatchers (MatchFinder *Finder) {
218
218
Finder->addMatcher (
219
- cxxMethodDecl (
220
- unless (anyOf (isOverride (), isImplicit (), cxxConstructorDecl (),
221
- cxxDestructorDecl (), cxxConversionDecl (), isStatic (),
222
- isOverloadedOperator ())))
219
+ cxxMethodDecl (unless (anyOf (isOverride (), cxxConstructorDecl (),
220
+ cxxDestructorDecl (), cxxConversionDecl (),
221
+ isStatic (), isOverloadedOperator ())))
223
222
.bind (" method" ),
224
223
this );
225
224
}
@@ -234,7 +233,15 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) {
234
233
assert (DerivedRD);
235
234
236
235
for (const auto &BaseSpec : DerivedRD->bases ()) {
237
- if (const auto *BaseRD = BaseSpec.getType ()->getAsCXXRecordDecl ()) {
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) {
238
245
for (const auto *BaseMD : BaseRD->methods ()) {
239
246
if (!isPossibleToBeOverridden (BaseMD))
240
247
continue ;
@@ -250,16 +257,12 @@ void VirtualNearMissCheck::check(const MatchFinder::MatchResult &Result) {
250
257
auto Range = CharSourceRange::getTokenRange (
251
258
SourceRange (DerivedMD->getLocation ()));
252
259
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?" )
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?" )
259
263
<< DerivedMD->getQualifiedNameAsString ()
260
- << BaseMD->getQualifiedNameAsString ();
261
- if (ApplyFix)
262
- Diag << FixItHint::CreateReplacement (Range, BaseMD->getName ());
264
+ << BaseMD->getQualifiedNameAsString ()
265
+ << FixItHint::CreateReplacement (Range, BaseMD->getName ());
263
266
}
264
267
}
265
268
}
0 commit comments