From: Benjamin Kramer Date: Wed, 11 Feb 2015 19:09:16 +0000 (+0000) Subject: CXXInheritance: Modernize removal of hidden virtual base class decls. X-Git-Tag: llvmorg-3.7.0-rc1~12418 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ece036e5a8ea8b345410c674baa23c9bee32d720;p=platform%2Fupstream%2Fllvm.git CXXInheritance: Modernize removal of hidden virtual base class decls. NFC. llvm-svn: 228864 --- diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp index 3011e0c..800c8f83 100644 --- a/clang/lib/AST/CXXInheritance.cpp +++ b/clang/lib/AST/CXXInheritance.cpp @@ -318,48 +318,36 @@ bool CXXRecordDecl::lookupInBases(BaseMatchesCallback *BaseMatches, // // FIXME: This is an O(N^2) algorithm, but DPG doesn't see an easy // way to make it any faster. - for (CXXBasePaths::paths_iterator P = Paths.begin(), PEnd = Paths.end(); - P != PEnd; /* increment in loop */) { - bool Hidden = false; - - for (CXXBasePath::iterator PE = P->begin(), PEEnd = P->end(); - PE != PEEnd && !Hidden; ++PE) { - if (PE->Base->isVirtual()) { - CXXRecordDecl *VBase = nullptr; - if (const RecordType *Record = PE->Base->getType()->getAs()) - VBase = cast(Record->getDecl()); - if (!VBase) + Paths.Paths.remove_if([&Paths](const CXXBasePath &Path) { + for (const CXXBasePathElement &PE : Path) { + if (!PE.Base->isVirtual()) + continue; + + CXXRecordDecl *VBase = nullptr; + if (const RecordType *Record = PE.Base->getType()->getAs()) + VBase = cast(Record->getDecl()); + if (!VBase) + break; + + // The declaration(s) we found along this path were found in a + // subobject of a virtual base. Check whether this virtual + // base is a subobject of any other path; if so, then the + // declaration in this path are hidden by that patch. + for (const CXXBasePath &HidingP : Paths) { + CXXRecordDecl *HidingClass = nullptr; + if (const RecordType *Record = + HidingP.back().Base->getType()->getAs()) + HidingClass = cast(Record->getDecl()); + if (!HidingClass) break; - // The declaration(s) we found along this path were found in a - // subobject of a virtual base. Check whether this virtual - // base is a subobject of any other path; if so, then the - // declaration in this path are hidden by that patch. - for (CXXBasePaths::paths_iterator HidingP = Paths.begin(), - HidingPEnd = Paths.end(); - HidingP != HidingPEnd; - ++HidingP) { - CXXRecordDecl *HidingClass = nullptr; - if (const RecordType *Record - = HidingP->back().Base->getType()->getAs()) - HidingClass = cast(Record->getDecl()); - if (!HidingClass) - break; - - if (HidingClass->isVirtuallyDerivedFrom(VBase)) { - Hidden = true; - break; - } - } + if (HidingClass->isVirtuallyDerivedFrom(VBase)) + return true; } } + return false; + }); - if (Hidden) - P = Paths.Paths.erase(P); - else - ++P; - } - return true; } @@ -626,54 +614,32 @@ CXXRecordDecl::getFinalOverriders(CXXFinalOverriderMap &FinalOverriders) const { // Weed out any final overriders that come from virtual base class // subobjects that were hidden by other subobjects along any path. // This is the final-overrider variant of C++ [class.member.lookup]p10. - for (CXXFinalOverriderMap::iterator OM = FinalOverriders.begin(), - OMEnd = FinalOverriders.end(); - OM != OMEnd; - ++OM) { - for (OverridingMethods::iterator SO = OM->second.begin(), - SOEnd = OM->second.end(); - SO != SOEnd; - ++SO) { - SmallVectorImpl &Overriding = SO->second; + for (auto &OM : FinalOverriders) { + for (auto &SO : OM.second) { + SmallVectorImpl &Overriding = SO.second; if (Overriding.size() < 2) continue; - for (SmallVectorImpl::iterator - Pos = Overriding.begin(), PosEnd = Overriding.end(); - Pos != PosEnd; - /* increment in loop */) { - if (!Pos->InVirtualSubobject) { - ++Pos; - continue; - } + auto IsHidden = [&Overriding](const UniqueVirtualMethod &M) { + if (!M.InVirtualSubobject) + return false; // We have an overriding method in a virtual base class // subobject (or non-virtual base class subobject thereof); // determine whether there exists an other overriding method // in a base class subobject that hides the virtual base class // subobject. - bool Hidden = false; - for (SmallVectorImpl::iterator - OP = Overriding.begin(), OPEnd = Overriding.end(); - OP != OPEnd && !Hidden; - ++OP) { - if (Pos == OP) - continue; - - if (OP->Method->getParent()->isVirtuallyDerivedFrom( - const_cast(Pos->InVirtualSubobject))) - Hidden = true; - } - - if (Hidden) { - // The current overriding function is hidden by another - // overriding function; remove this one. - Pos = Overriding.erase(Pos); - PosEnd = Overriding.end(); - } else { - ++Pos; - } - } + for (const UniqueVirtualMethod &OP : Overriding) + if (&M != &OP && + OP.Method->getParent()->isVirtuallyDerivedFrom( + M.InVirtualSubobject)) + return true; + return false; + }; + + Overriding.erase( + std::remove_if(Overriding.begin(), Overriding.end(), IsHidden), + Overriding.end()); } } }