Index: clang-tidy/misc/VirtualNearMissCheck.cpp =================================================================== --- clang-tidy/misc/VirtualNearMissCheck.cpp +++ clang-tidy/misc/VirtualNearMissCheck.cpp @@ -52,16 +52,10 @@ const CXXRecordDecl *BRD, *DRD; // Both types must be pointers or references to classes. - if (const auto *DerivedPT = DerivedReturnTy->getAs()) { - if (const auto *BasePT = BaseReturnTy->getAs()) { - DTy = DerivedPT->getPointeeType(); - BTy = BasePT->getPointeeType(); - } - } else if (const auto *DerivedRT = DerivedReturnTy->getAs()) { - if (const auto *BaseRT = BaseReturnTy->getAs()) { - DTy = DerivedRT->getPointeeType(); - BTy = BaseRT->getPointeeType(); - } + if ((BaseReturnTy->isPointerType() && DerivedReturnTy->isPointerType()) || + (BaseReturnTy->isReferenceType() && DerivedReturnTy->isReferenceType())) { + DTy = DerivedReturnTy->getPointeeType(); + BTy = BaseReturnTy->getPointeeType(); } // The return types aren't either both pointers or references to a class type. @@ -116,6 +110,13 @@ return true; } +/// \returns decayed type for arrays and functions. +static QualType getDecayedType(QualType Type) { + if (const auto *Decayed = Type->getAs()) + return Decayed->getDecayedType(); + return Type; +} + /// \returns true if the param types are the same. static bool checkParamTypes(const CXXMethodDecl *BaseMD, const CXXMethodDecl *DerivedMD) { @@ -125,8 +126,8 @@ return false; for (unsigned I = 0; I < NumParamA; I++) { - if (BaseMD->getParamDecl(I)->getType() != - DerivedMD->getParamDecl(I)->getType()) + if (getDecayedType(BaseMD->getParamDecl(I)->getType()) != + getDecayedType(DerivedMD->getParamDecl(I)->getType())) return false; } return true; @@ -143,9 +144,6 @@ if (BaseMD->isStatic() != DerivedMD->isStatic()) return false; - if (BaseMD->getAccess() != DerivedMD->getAccess()) - return false; - if (BaseMD->getType() == DerivedMD->getType()) return true; Index: test/clang-tidy/misc-virtual-near-miss.cpp =================================================================== --- test/clang-tidy/misc-virtual-near-miss.cpp +++ test/clang-tidy/misc-virtual-near-miss.cpp @@ -36,6 +36,7 @@ static void method(); virtual int method(int argc, const char **argv); virtual int method(int argc) const; + virtual int decay(const char *str); }; class Child : private Father, private Mother { @@ -60,6 +61,10 @@ virtual Derived &&generat(); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::generat' has {{.*}} 'Father::generate' + int decaz(const char str[]); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::decaz' has {{.*}} 'Mother::decay' + private: - void funk(); // Should not warn: access qualifers don't match. + void funk(); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: method 'Child::funk' has {{.*}} 'Father::func' };