36 MatchFinder *Finder) {
38 auto DirectMemberVirtualFunctionPointer = unaryOperator(
39 allOf(hasOperatorName(
"&"),
40 hasUnaryOperand(declRefExpr(to(cxxMethodDecl(isVirtual()))))));
41 auto IndirectMemberPointer =
42 ignoringImpCasts(declRefExpr().bind(
"indirect_member_pointer"));
46 allOf(hasAnyOperatorName(
"==",
"!="),
48 hasType(memberPointerType(pointee(functionType())))),
49 anyOf(hasEitherOperand(DirectMemberVirtualFunctionPointer),
50 hasEitherOperand(IndirectMemberPointer)),
51 unless(hasEitherOperand(
52 castExpr(hasCastKind(CK_NullToMemberPointer))))))
53 .bind(
"binary_operator"),
58 const MatchFinder::MatchResult &Result) {
59 const auto *BO = Result.Nodes.getNodeAs<BinaryOperator>(
"binary_operator");
61 Result.Nodes.getNodeAs<DeclRefExpr>(
"indirect_member_pointer");
65 diag(BO->getOperatorLoc(), ErrorMsg);
69 llvm::SmallVector<SourceLocation, 12U> SameSignatureVirtualMethods{};
70 const auto *MPT = cast<MemberPointerType>(DRE->getType().getCanonicalType());
71 const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
75 constexpr bool StopVisit =
false;
77 auto VisitSameSignatureVirtualMethods =
78 [&](
const CXXRecordDecl *CurrentRecordDecl) ->
bool {
79 bool Ret = !StopVisit;
80 for (
const auto *MD : CurrentRecordDecl->methods()) {
81 if (MD->isVirtual() && MD->getType() == MPT->getPointeeType()) {
82 SameSignatureVirtualMethods.push_back(MD->getBeginLoc());
89 if (StopVisit != VisitSameSignatureVirtualMethods(RD)) {
90 RD->forallBases(VisitSameSignatureVirtualMethods);
93 if (!SameSignatureVirtualMethods.empty()) {
94 diag(BO->getOperatorLoc(), ErrorMsg);
95 for (
const auto Loc : SameSignatureVirtualMethods)
96 diag(Loc,
"potential member virtual function is declared here.",