From: Aaron Ballman Date: Thu, 6 Mar 2014 23:45:36 +0000 (+0000) Subject: [C++11] Replacing iterators redecls_begin() and redecls_end() with iterator_range... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed65ea2738ab511212c76c4bbb61a215a2cd6af3;p=clang [C++11] Replacing iterators redecls_begin() and redecls_end() with iterator_range redecls(). Updating all of the usages of the iterators with range-based for loops, which allows the begin/end forms to be removed entirely. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@203179 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 520e487777..f73c3275a6 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -371,9 +371,8 @@ public: static NamespaceDecl *CreateDeserialized(ASTContext &C, unsigned ID); - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; @@ -779,9 +778,8 @@ protected: } public: - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; @@ -1569,9 +1567,8 @@ protected: } public: - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; @@ -2408,9 +2405,8 @@ protected: } public: - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; @@ -2593,9 +2589,8 @@ protected: void completeDefinition(); public: - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 23fb519b16..9e45740cd3 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -19,6 +19,7 @@ #include "clang/Basic/Linkage.h" #include "clang/Basic/Specifiers.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/iterator_range.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/PrettyStackTrace.h" @@ -770,12 +771,14 @@ public: } }; - /// \brief Returns iterator for all the redeclarations of the same decl. - /// It will iterate at least once (when this decl is the only one). - redecl_iterator redecls_begin() const { - return redecl_iterator(const_cast(this)); + typedef llvm::iterator_range redecl_range; + + /// \brief Returns an iterator range for all the redeclarations of the same + /// decl. It will iterate at least once (when this decl is the only one). + redecl_range redecls() const { + return redecl_range(redecl_iterator(const_cast(this)), + redecl_iterator()); } - redecl_iterator redecls_end() const { return redecl_iterator(); } /// \brief Retrieve the previous declaration that declares the same entity /// as this declaration, or NULL if there is no previous declaration. diff --git a/include/clang/AST/DeclCXX.h b/include/clang/AST/DeclCXX.h index 3def885499..a729b59bbd 100644 --- a/include/clang/AST/DeclCXX.h +++ b/include/clang/AST/DeclCXX.h @@ -2728,9 +2728,8 @@ public: static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID); - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 3947e35cbc..fc41639c94 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -1261,9 +1261,8 @@ public: bool lookupCategory, bool RHSIsQualifiedID = false); - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; @@ -1568,9 +1567,8 @@ public: return SourceRange(getAtStartLoc(), getLocation()); } - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 31a18d4c67..1823b847b9 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -710,9 +710,8 @@ public: getCommonPtr()->InstantiatedFromMember.setPointer(TD); } - typedef redeclarable_base::redecl_iterator redecl_iterator; - using redeclarable_base::redecls_begin; - using redeclarable_base::redecls_end; + typedef redeclarable_base::redecl_range redecl_range; + using redeclarable_base::redecls; using redeclarable_base::getPreviousDecl; using redeclarable_base::getMostRecentDecl; using redeclarable_base::isFirstDecl; diff --git a/include/clang/AST/Redeclarable.h b/include/clang/AST/Redeclarable.h index cfe5a90be0..76b6906214 100644 --- a/include/clang/AST/Redeclarable.h +++ b/include/clang/AST/Redeclarable.h @@ -161,13 +161,15 @@ public: } }; - /// \brief Returns iterator for all the redeclarations of the same decl. - /// It will iterate at least once (when this decl is the only one). - redecl_iterator redecls_begin() const { - return redecl_iterator(const_cast( - static_cast(this))); + typedef llvm::iterator_range redecl_range; + + /// \brief Returns an iterator range for all the redeclarations of the same + /// decl. It will iterate at least once (when this decl is the only one). + redecl_range redecls() const { + return redecl_range(redecl_iterator(const_cast( + static_cast(this))), + redecl_iterator()); } - redecl_iterator redecls_end() const { return redecl_iterator(); } friend class ASTDeclReader; friend class ASTDeclWriter; diff --git a/lib/ARCMigrate/TransGCAttrs.cpp b/lib/ARCMigrate/TransGCAttrs.cpp index d8be1ae746..29b849074e 100644 --- a/lib/ARCMigrate/TransGCAttrs.cpp +++ b/lib/ARCMigrate/TransGCAttrs.cpp @@ -164,8 +164,7 @@ public: if (!D) return false; - for (Decl::redecl_iterator - I = D->redecls_begin(), E = D->redecls_end(); I != E; ++I) + for (auto I : D->redecls()) if (!isInMainFile(I->getLocation())) return false; diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index b1f31c429e..d94fa4ba36 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -332,11 +332,9 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl( // Search for comments attached to declarations in the redeclaration chain. const RawComment *RC = NULL; const Decl *OriginalDeclForRC = NULL; - for (Decl::redecl_iterator I = D->redecls_begin(), - E = D->redecls_end(); - I != E; ++I) { + for (auto I : D->redecls()) { llvm::DenseMap::iterator Pos = - RedeclComments.find(*I); + RedeclComments.find(I); if (Pos != RedeclComments.end()) { const RawCommentAndCacheFlags &Raw = Pos->second; if (Raw.getKind() != RawCommentAndCacheFlags::NoCommentInDecl) { @@ -345,16 +343,16 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl( break; } } else { - RC = getRawCommentForDeclNoCache(*I); - OriginalDeclForRC = *I; + RC = getRawCommentForDeclNoCache(I); + OriginalDeclForRC = I; RawCommentAndCacheFlags Raw; if (RC) { Raw.setRaw(RC); Raw.setKind(RawCommentAndCacheFlags::FromDecl); } else Raw.setKind(RawCommentAndCacheFlags::NoCommentInDecl); - Raw.setOriginalDecl(*I); - RedeclComments[*I] = Raw; + Raw.setOriginalDecl(I); + RedeclComments[I] = Raw; if (RC) break; } @@ -372,10 +370,8 @@ const RawComment *ASTContext::getRawCommentForAnyRedecl( Raw.setKind(RawCommentAndCacheFlags::FromRedecl); Raw.setOriginalDecl(OriginalDeclForRC); - for (Decl::redecl_iterator I = D->redecls_begin(), - E = D->redecls_end(); - I != E; ++I) { - RawCommentAndCacheFlags &R = RedeclComments[*I]; + for (auto I : D->redecls()) { + RawCommentAndCacheFlags &R = RedeclComments[I]; if (R.getKind() == RawCommentAndCacheFlags::NoCommentInDecl) R = Raw; } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index db404ec5fe..6eaf140550 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1245,10 +1245,8 @@ public: // that all other computed linkages match, check that the one we just // computed also does. NamedDecl *Old = NULL; - for (NamedDecl::redecl_iterator I = D->redecls_begin(), - E = D->redecls_end(); - I != E; ++I) { - NamedDecl *T = cast(*I); + for (auto I : D->redecls()) { + NamedDecl *T = cast(I); if (T == D) continue; if (!T->isInvalidDecl() && T->hasCachedLinkage()) { @@ -1793,23 +1791,21 @@ VarDecl *VarDecl::getActingDefinition() { VarDecl *LastTentative = 0; VarDecl *First = getFirstDecl(); - for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end(); - I != E; ++I) { - Kind = (*I)->isThisDeclarationADefinition(); + for (auto I : First->redecls()) { + Kind = I->isThisDeclarationADefinition(); if (Kind == Definition) return 0; else if (Kind == TentativeDefinition) - LastTentative = *I; + LastTentative = I; } return LastTentative; } VarDecl *VarDecl::getDefinition(ASTContext &C) { VarDecl *First = getFirstDecl(); - for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end(); - I != E; ++I) { - if ((*I)->isThisDeclarationADefinition(C) == Definition) - return *I; + for (auto I : First->redecls()) { + if (I->isThisDeclarationADefinition(C) == Definition) + return I; } return 0; } @@ -1818,9 +1814,8 @@ VarDecl::DefinitionKind VarDecl::hasDefinition(ASTContext &C) const { DefinitionKind Kind = DeclarationOnly; const VarDecl *First = getFirstDecl(); - for (redecl_iterator I = First->redecls_begin(), E = First->redecls_end(); - I != E; ++I) { - Kind = std::max(Kind, (*I)->isThisDeclarationADefinition(C)); + for (auto I : First->redecls()) { + Kind = std::max(Kind, I->isThisDeclarationADefinition(C)); if (Kind == Definition) break; } @@ -1829,13 +1824,11 @@ VarDecl::DefinitionKind VarDecl::hasDefinition(ASTContext &C) const { } const Expr *VarDecl::getAnyInitializer(const VarDecl *&D) const { - redecl_iterator I = redecls_begin(), E = redecls_end(); - while (I != E && !I->getInit()) - ++I; - - if (I != E) { - D = *I; - return I->getInit(); + for (auto I : redecls()) { + if (auto Expr = I->getInit()) { + D = I; + return Expr; + } } return 0; } @@ -1860,10 +1853,9 @@ VarDecl *VarDecl::getOutOfLineDefinition() { if (!isStaticDataMember()) return 0; - for (VarDecl::redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); - RD != RDEnd; ++RD) { + for (auto RD : redecls()) { if (RD->getLexicalDeclContext()->isFileContext()) - return *RD; + return RD; } return 0; @@ -2190,9 +2182,9 @@ bool FunctionDecl::isVariadic() const { } bool FunctionDecl::hasBody(const FunctionDecl *&Definition) const { - for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) { + for (auto I : redecls()) { if (I->Body || I->IsLateTemplateParsed) { - Definition = *I; + Definition = I; return true; } } @@ -2215,10 +2207,10 @@ bool FunctionDecl::hasTrivialBody() const } bool FunctionDecl::isDefined(const FunctionDecl *&Definition) const { - for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) { + for (auto I : redecls()) { if (I->IsDeleted || I->IsDefaulted || I->Body || I->IsLateTemplateParsed || I->hasAttr()) { - Definition = I->IsDeleted ? I->getCanonicalDecl() : *I; + Definition = I->IsDeleted ? I->getCanonicalDecl() : I; return true; } } @@ -2680,9 +2672,7 @@ bool FunctionDecl::isInlineDefinitionExternallyVisible() const { // If any declaration is 'inline' but not 'extern', then this definition // is externally visible. - for (redecl_iterator Redecl = redecls_begin(), RedeclEnd = redecls_end(); - Redecl != RedeclEnd; - ++Redecl) { + for (auto Redecl : redecls()) { if (Redecl->isInlineSpecified() && Redecl->getStorageClass() != SC_Extern) return true; @@ -2699,10 +2689,8 @@ bool FunctionDecl::isInlineDefinitionExternallyVisible() const { // [...] If all of the file scope declarations for a function in a // translation unit include the inline function specifier without extern, // then the definition in that translation unit is an inline definition. - for (redecl_iterator Redecl = redecls_begin(), RedeclEnd = redecls_end(); - Redecl != RedeclEnd; - ++Redecl) { - if (RedeclForcesDefC99(*Redecl)) + for (auto Redecl : redecls()) { + if (RedeclForcesDefC99(Redecl)) return true; } @@ -3187,8 +3175,8 @@ void TagDecl::startDefinition() { if (CXXRecordDecl *D = dyn_cast(this)) { struct CXXRecordDecl::DefinitionData *Data = new (getASTContext()) struct CXXRecordDecl::DefinitionData(D); - for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) - cast(*I)->DefinitionData = Data; + for (auto I : redecls()) + cast(I)->DefinitionData = Data; } } @@ -3220,10 +3208,9 @@ TagDecl *TagDecl::getDefinition() const { if (const CXXRecordDecl *CXXRD = dyn_cast(this)) return CXXRD->getDefinition(); - for (redecl_iterator R = redecls_begin(), REnd = redecls_end(); - R != REnd; ++R) + for (auto R : redecls()) if (R->isCompleteDefinition()) - return *R; + return R; return 0; } diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index 2ca491194d..00692df46c 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -313,7 +313,7 @@ bool Decl::isReferenced() const { return true; // Check redeclarations. - for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) + for (auto I : redecls()) if (I->Referenced) return true; diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 94c4d5187a..b76fc5cf38 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -465,9 +465,8 @@ void ObjCInterfaceDecl::startDefinition() { allocateDefinitionData(); // Update all of the declarations with a pointer to the definition. - for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); - RD != RDEnd; ++RD) { - if (*RD != this) + for (auto RD : redecls()) { + if (RD != this) RD->Data = Data; } } @@ -1591,8 +1590,7 @@ void ObjCProtocolDecl::startDefinition() { allocateDefinitionData(); // Update all of the declarations with a pointer to the definition. - for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end(); - RD != RDEnd; ++RD) + for (auto RD : redecls()) RD->Data = this->Data; } diff --git a/lib/AST/ExprCXX.cpp b/lib/AST/ExprCXX.cpp index 516b60d89b..ee4992590a 100644 --- a/lib/AST/ExprCXX.cpp +++ b/lib/AST/ExprCXX.cpp @@ -108,10 +108,8 @@ UuidAttr *CXXUuidofExpr::GetUuidAttrOfType(QualType QT, return UuidForRD; } - for (CXXRecordDecl::redecl_iterator I = RD->redecls_begin(), - E = RD->redecls_end(); - I != E; ++I) - if (UuidAttr *Uuid = I->getAttr()) + for (auto I : RD->redecls()) + if (auto Uuid = I->getAttr()) return Uuid; return 0; diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index cebdbad4fc..6fb1172a89 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -1849,11 +1849,9 @@ TagType::TagType(TypeClass TC, const TagDecl *D, QualType can) decl(const_cast(D)) {} static TagDecl *getInterestingTagDecl(TagDecl *decl) { - for (TagDecl::redecl_iterator I = decl->redecls_begin(), - E = decl->redecls_end(); - I != E; ++I) { + for (auto I : decl->redecls()) { if (I->isCompleteDefinition() || I->isBeingDefined()) - return *I; + return I; } // If there's no definition (not even in progress), return what we have. return decl; diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 2ad750b46a..6fc06260b6 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2424,9 +2424,7 @@ llvm::DISubprogram CGDebugInfo::getFunctionDeclaration(const Decl *D) { return SP; } - for (FunctionDecl::redecl_iterator I = FD->redecls_begin(), - E = FD->redecls_end(); I != E; ++I) { - const FunctionDecl *NextFD = *I; + for (auto NextFD : FD->redecls()) { llvm::DenseMap::iterator MI = SPCache.find(NextFD->getCanonicalDecl()); if (MI != SPCache.end()) { diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 975ae6cb46..d35ab739e6 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -521,8 +521,7 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, // attribute to all function that are not marked AlwaysInline. if (const FunctionDecl *FD = dyn_cast_or_null(D)) { if (!CGM.getCodeGenOpts().NoInline) { - for (FunctionDecl::redecl_iterator RI = FD->redecls_begin(), - RE = FD->redecls_end(); RI != RE; ++RI) + for (auto RI : FD->redecls()) if (RI->isInlineSpecified()) { Fn->addFnAttr(llvm::Attribute::InlineHint); break; diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp index 2298f3ad68..705fb07319 100644 --- a/lib/Sema/IdentifierResolver.cpp +++ b/lib/Sema/IdentifierResolver.cpp @@ -273,10 +273,8 @@ static DeclMatchKind compareDeclarations(NamedDecl *Existing, NamedDecl *New) { // If the existing declaration is somewhere in the previous declaration // chain of the new declaration, then prefer the new declaration. - for (Decl::redecl_iterator RD = New->redecls_begin(), - RDEnd = New->redecls_end(); - RD != RDEnd; ++RD) { - if (*RD == Existing) + for (auto RD : New->redecls()) { + if (RD == Existing) return DMK_Replace; if (RD->isCanonicalDecl()) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index acf27e23c2..9840d1eca1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -5540,11 +5540,9 @@ void Sema::CheckShadow(Scope *S, VarDecl *D, const LookupResult& R) { if (shadowedVar->isExternC()) { // For shadowing external vars, make sure that we point to the global // declaration, not a locally scoped extern declaration. - for (VarDecl::redecl_iterator - I = shadowedVar->redecls_begin(), E = shadowedVar->redecls_end(); - I != E; ++I) + for (auto I : shadowedVar->redecls()) if (I->isFileVarDecl()) { - ShadowedDecl = *I; + ShadowedDecl = I; break; } } @@ -10330,8 +10328,7 @@ bool Sema::isAcceptableTagRedeclaration(const TagDecl *Previous, } bool previousMismatch = false; - for (TagDecl::redecl_iterator I(Previous->redecls_begin()), - E(Previous->redecls_end()); I != E; ++I) { + for (auto I : Previous->redecls()) { if (I->getTagKind() != NewTag) { if (!previousMismatch) { previousMismatch = true; diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 0e968f1f78..2d35d5cda7 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -12405,11 +12405,9 @@ bool Sema::DefineUsedVTables() { bool IsExplicitInstantiationDeclaration = Class->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDeclaration; - for (TagDecl::redecl_iterator R = Class->redecls_begin(), - REnd = Class->redecls_end(); - R != REnd; ++R) { + for (auto R : Class->redecls()) { TemplateSpecializationKind TSK - = cast(*R)->getTemplateSpecializationKind(); + = cast(R)->getTemplateSpecializationKind(); if (TSK == TSK_ExplicitInstantiationDeclaration) IsExplicitInstantiationDeclaration = true; else if (TSK == TSK_ExplicitInstantiationDefinition) { diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 38d1724c9c..2566db30a0 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -168,9 +168,7 @@ void Sema::NoteDeletedFunction(FunctionDecl *Decl) { /// \brief Determine whether a FunctionDecl was ever declared with an /// explicit storage class. static bool hasAnyExplicitStorageClass(const FunctionDecl *D) { - for (FunctionDecl::redecl_iterator I = D->redecls_begin(), - E = D->redecls_end(); - I != E; ++I) { + for (auto I : D->redecls()) { if (I->getStorageClass() != SC_None) return true; } @@ -11409,10 +11407,9 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func) { } } else { // Walk redefinitions, as some of them may be instantiable. - for (FunctionDecl::redecl_iterator i(Func->redecls_begin()), - e(Func->redecls_end()); i != e; ++i) { + for (auto i : Func->redecls()) { if (!i->isUsed(false) && i->isImplicitlyInstantiable()) - MarkFunctionReferenced(Loc, *i); + MarkFunctionReferenced(Loc, i); } } diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index dfd078f5de..059bc1cae7 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -1269,9 +1269,8 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) { static NamedDecl *findAcceptableDecl(Sema &SemaRef, NamedDecl *D) { assert(!LookupResult::isVisible(SemaRef, D) && "not in slow case"); - for (Decl::redecl_iterator RD = D->redecls_begin(), RDEnd = D->redecls_end(); - RD != RDEnd; ++RD) { - if (NamedDecl *ND = dyn_cast(*RD)) { + for (auto RD : D->redecls()) { + if (auto ND = dyn_cast(RD)) { if (LookupResult::isVisible(SemaRef, ND)) return ND; } diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 9bfdc5f95e..fe62ab466e 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1450,10 +1450,8 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, } // Check for redefinitions due to other instantiations of this or // a similar friend function. - else for (FunctionDecl::redecl_iterator R = Function->redecls_begin(), - REnd = Function->redecls_end(); - R != REnd; ++R) { - if (*R == Function) + else for (auto R : Function->redecls()) { + if (R == Function) continue; // If some prior declaration of this function has been used, we need diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index cc218a2807..0afe262396 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -7676,16 +7676,14 @@ void ASTReader::finishPendingActions() { llvm::SmallVector Candidates; for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); !Found && I != E; ++I) { - for (Decl::redecl_iterator RI = (*I)->redecls_begin(), - RE = (*I)->redecls_end(); - RI != RE; ++RI) { - if ((*RI)->getLexicalDeclContext() == CanonDef) { + for (auto RI : (*I)->redecls()) { + if (RI->getLexicalDeclContext() == CanonDef) { // This declaration is present in the canonical definition. If it's // in the same redecl chain, it's the one we're looking for. - if ((*RI)->getCanonicalDecl() == DCanon) + if (RI->getCanonicalDecl() == DCanon) Found = true; else - Candidates.push_back(cast(*RI)); + Candidates.push_back(cast(RI)); break; } } @@ -7726,44 +7724,35 @@ void ASTReader::finishPendingActions() { const_cast(TagT)->decl = TD; } - if (CXXRecordDecl *RD = dyn_cast(*D)) { - for (CXXRecordDecl::redecl_iterator R = RD->redecls_begin(), - REnd = RD->redecls_end(); - R != REnd; ++R) - cast(*R)->DefinitionData = RD->DefinitionData; + if (auto RD = dyn_cast(*D)) { + for (auto R : RD->redecls()) + cast(R)->DefinitionData = RD->DefinitionData; } continue; } - if (ObjCInterfaceDecl *ID = dyn_cast(*D)) { + if (auto ID = dyn_cast(*D)) { // Make sure that the ObjCInterfaceType points at the definition. const_cast(cast(ID->TypeForDecl)) ->Decl = ID; - for (ObjCInterfaceDecl::redecl_iterator R = ID->redecls_begin(), - REnd = ID->redecls_end(); - R != REnd; ++R) + for (auto R : ID->redecls()) R->Data = ID->Data; continue; } - if (ObjCProtocolDecl *PD = dyn_cast(*D)) { - for (ObjCProtocolDecl::redecl_iterator R = PD->redecls_begin(), - REnd = PD->redecls_end(); - R != REnd; ++R) + if (auto PD = dyn_cast(*D)) { + for (auto R : PD->redecls()) R->Data = PD->Data; continue; } - RedeclarableTemplateDecl *RTD - = cast(*D)->getCanonicalDecl(); - for (RedeclarableTemplateDecl::redecl_iterator R = RTD->redecls_begin(), - REnd = RTD->redecls_end(); - R != REnd; ++R) + auto RTD = cast(*D)->getCanonicalDecl(); + for (auto R : RTD->redecls()) R->Common = RTD->Common; } PendingDefinitions.clear();