From 963b4b8a19fd56191a04828fbb5f682595866ad4 Mon Sep 17 00:00:00 2001 From: Zinovy Nis Date: Fri, 13 Apr 2018 07:46:27 +0000 Subject: [PATCH] [clang-tidy] [bugprone-parent-virtual-call] Minor cosmetic changes. NFC llvm-svn: 329994 --- .../bugprone/ParentVirtualCallCheck.cpp | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp index a64564c048a0..7daf742dadac 100755 --- a/clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/ParentVirtualCallCheck.cpp @@ -11,6 +11,7 @@ #include "clang/AST/ASTContext.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Tooling/FixIt.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include #include @@ -27,13 +28,12 @@ static bool isParentOf(const CXXRecordDecl &Parent, const CXXRecordDecl &ThisClass) { if (Parent.getCanonicalDecl() == ThisClass.getCanonicalDecl()) return true; - for (const CXXBaseSpecifier &Base : ThisClass.bases()) { - auto *BaseDecl = Base.getType()->getAsCXXRecordDecl(); - assert(BaseDecl); - if (Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl()) - return true; - } - return false; + return ThisClass.bases_end() != + llvm::find_if(ThisClass.bases(), [=](const CXXBaseSpecifier &Base) { + auto *BaseDecl = Base.getType()->getAsCXXRecordDecl(); + assert(BaseDecl); + return Parent.getCanonicalDecl() == BaseDecl->getCanonicalDecl(); + }); } static BasesVector getParentsByGrandParent(const CXXRecordDecl &GrandParent, @@ -76,9 +76,9 @@ static std::string getExprAsString(const clang::Expr &E, clang::ASTContext &AC) { std::string Text = tooling::fixit::getText(E, AC).str(); Text.erase( - std::remove_if( - Text.begin(), Text.end(), - [](char c) { return std::isspace(static_cast(c)); }), + llvm::remove_if( + Text, + [](char C) { return std::isspace(static_cast(C)); }), Text.end()); return Text; } @@ -92,16 +92,11 @@ void ParentVirtualCallCheck::registerMatchers(MatchFinder *Finder) { hasSourceExpression(cxxThisExpr(hasType( type(anything()).bind("thisType"))))))) .bind("member")), - callee(cxxMethodDecl(isVirtual()))) - .bind("call"), + callee(cxxMethodDecl(isVirtual()))), this); } void ParentVirtualCallCheck::check(const MatchFinder::MatchResult &Result) { - const auto *MatchedDecl = Result.Nodes.getNodeAs("call"); - (void)MatchedDecl; - assert(MatchedDecl); - const auto *Member = Result.Nodes.getNodeAs("member"); assert(Member);