diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2014-03-13 15:41:46 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2014-03-13 15:41:46 +0000 |
commit | 574705ed7f80c59da543ad26d4a5fcd962b5c27d (patch) | |
tree | a2037e4203693828cbfd1f19000dc4199ff6204d /clang/lib/Sema | |
parent | 48803e5ca9c07109c5de8b379c24f15d21b8c244 (diff) | |
download | bcm5719-llvm-574705ed7f80c59da543ad26d4a5fcd962b5c27d.tar.gz bcm5719-llvm-574705ed7f80c59da543ad26d4a5fcd962b5c27d.zip |
[C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with iterator_range bases(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203803
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaAccess.cpp | 14 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 188 | ||||
-rw-r--r-- | clang/lib/Sema/SemaExprMember.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateDeduction.cpp | 8 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiate.cpp | 44 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 9 |
10 files changed, 123 insertions, 179 deletions
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 60c3e726e61..541b7f92759 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -288,12 +288,10 @@ static AccessResult IsDerivedFromInclusive(const CXXRecordDecl *Derived, if (Derived->isDependentContext() && !Derived->hasDefinition()) return AR_dependent; - for (CXXRecordDecl::base_class_const_iterator - I = Derived->bases_begin(), E = Derived->bases_end(); I != E; ++I) { - + for (const auto &I : Derived->bases()) { const CXXRecordDecl *RD; - QualType T = I->getType(); + QualType T = I.getType(); if (const RecordType *RT = T->getAs<RecordType>()) { RD = cast<CXXRecordDecl>(RT->getDecl()); } else if (const InjectedClassNameType *IT @@ -646,18 +644,16 @@ struct ProtectedFriendContext { EverDependent = true; // Recurse into the base classes. - for (CXXRecordDecl::base_class_const_iterator - I = Cur->bases_begin(), E = Cur->bases_end(); I != E; ++I) { - + for (const auto &I : Cur->bases()) { // If this is private inheritance, then a public member of the // base will not have any access in classes derived from Cur. unsigned BasePrivateDepth = PrivateDepth; - if (I->getAccessSpecifier() == AS_private) + if (I.getAccessSpecifier() == AS_private) BasePrivateDepth = CurPath.size() - 1; const CXXRecordDecl *RD; - QualType T = I->getType(); + QualType T = I.getType(); if (const RecordType *RT = T->getAs<RecordType>()) { RD = cast<CXXRecordDecl>(RT->getDecl()); } else if (const InjectedClassNameType *IT diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index f981592bd33..bdb203782f9 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -4243,21 +4243,19 @@ void Sema::CodeCompleteConstructorInitializer( Results.getCodeCompletionTUInfo()); bool SawLastInitializer = Initializers.empty(); CXXRecordDecl *ClassDecl = Constructor->getParent(); - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - BaseEnd = ClassDecl->bases_end(); - Base != BaseEnd; ++Base) { - if (!InitializedBases.insert(Context.getCanonicalType(Base->getType()))) { + for (const auto &Base : ClassDecl->bases()) { + if (!InitializedBases.insert(Context.getCanonicalType(Base.getType()))) { SawLastInitializer = !Initializers.empty() && Initializers.back()->isBaseInitializer() && - Context.hasSameUnqualifiedType(Base->getType(), + Context.hasSameUnqualifiedType(Base.getType(), QualType(Initializers.back()->getBaseClass(), 0)); continue; } Builder.AddTypedTextChunk( Results.getAllocator().CopyString( - Base->getType().getAsString(Policy))); + Base.getType().getAsString(Policy))); Builder.AddChunk(CodeCompletionString::CK_LeftParen); Builder.AddPlaceholderChunk("args"); Builder.AddChunk(CodeCompletionString::CK_RightParen); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index ec062852789..258914343cb 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -386,9 +386,8 @@ bool Sema::isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S) { const Type *Ty = SS->getScopeRep()->getAsType(); CXXRecordDecl *RD = cast<CXXRecordDecl>(CurContext); - for (CXXRecordDecl::base_class_const_iterator Base = RD->bases_begin(), - BaseEnd = RD->bases_end(); Base != BaseEnd; ++Base) - if (Context.hasSameUnqualifiedType(QualType(Ty, 1), Base->getType())) + for (const auto &Base : RD->bases()) + if (Context.hasSameUnqualifiedType(QualType(Ty, 1), Base.getType())) return true; return S->isFunctionPrototypeScope(); } diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index c75bac5e8c6..cc5397be908 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -1271,10 +1271,8 @@ static bool findCircularInheritance(const CXXRecordDecl *Class, Class = Class->getCanonicalDecl(); while (true) { - for (CXXRecordDecl::base_class_const_iterator I = Current->bases_begin(), - E = Current->bases_end(); - I != E; ++I) { - CXXRecordDecl *Base = I->getType()->getAsCXXRecordDecl(); + for (const auto &I : Current->bases()) { + CXXRecordDecl *Base = I.getType()->getAsCXXRecordDecl(); if (!Base) continue; @@ -2413,13 +2411,11 @@ static bool FindBaseInitializer(Sema &SemaRef, const CXXBaseSpecifier *&VirtualBaseSpec) { // First, check for a direct base class. DirectBaseSpec = 0; - for (CXXRecordDecl::base_class_const_iterator Base - = ClassDecl->bases_begin(); - Base != ClassDecl->bases_end(); ++Base) { - if (SemaRef.Context.hasSameUnqualifiedType(BaseType, Base->getType())) { + for (const auto &Base : ClassDecl->bases()) { + if (SemaRef.Context.hasSameUnqualifiedType(BaseType, Base.getType())) { // We found a direct base of this type. That's what we're // initializing. - DirectBaseSpec = &*Base; + DirectBaseSpec = &Base; break; } } @@ -3575,10 +3571,9 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors, // Keep track of the direct virtual bases. llvm::SmallPtrSet<CXXBaseSpecifier *, 16> DirectVBases; - for (CXXRecordDecl::base_class_iterator I = ClassDecl->bases_begin(), - E = ClassDecl->bases_end(); I != E; ++I) { - if (I->isVirtual()) - DirectVBases.insert(I); + for (auto &I : ClassDecl->bases()) { + if (I.isVirtual()) + DirectVBases.insert(&I); } // Push virtual bases before others. @@ -3619,19 +3614,18 @@ bool Sema::SetCtorInitializers(CXXConstructorDecl *Constructor, bool AnyErrors, } // Non-virtual bases. - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - E = ClassDecl->bases_end(); Base != E; ++Base) { + for (auto &Base : ClassDecl->bases()) { // Virtuals are in the virtual base list and already constructed. - if (Base->isVirtual()) + if (Base.isVirtual()) continue; if (CXXCtorInitializer *Value - = Info.AllBaseFields.lookup(Base->getType()->getAs<RecordType>())) { + = Info.AllBaseFields.lookup(Base.getType()->getAs<RecordType>())) { Info.AllToInit.push_back(Value); } else if (!AnyErrors) { CXXCtorInitializer *CXXBaseInit; if (BuildImplicitBaseInitializer(*this, Constructor, Info.IIK, - Base, /*IsInheritedVirtualBase=*/false, + &Base, /*IsInheritedVirtualBase=*/false, CXXBaseInit)) { HadError = true; continue; @@ -3758,11 +3752,10 @@ static void DiagnoseBaseOrMemInitializerOrder( IdealInitKeys.push_back(GetKeyForBase(SemaRef.Context, VBase->getType())); // 2. Non-virtual bases. - for (CXXRecordDecl::base_class_const_iterator Base = ClassDecl->bases_begin(), - E = ClassDecl->bases_end(); Base != E; ++Base) { - if (Base->isVirtual()) + for (const auto &Base : ClassDecl->bases()) { + if (Base.isVirtual()) continue; - IdealInitKeys.push_back(GetKeyForBase(SemaRef.Context, Base->getType())); + IdealInitKeys.push_back(GetKeyForBase(SemaRef.Context, Base.getType())); } // 3. Direct fields. @@ -4003,13 +3996,12 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location, llvm::SmallPtrSet<const RecordType *, 8> DirectVirtualBases; // Bases. - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - E = ClassDecl->bases_end(); Base != E; ++Base) { + for (const auto &Base : ClassDecl->bases()) { // Bases are always records in a well-formed non-dependent class. - const RecordType *RT = Base->getType()->getAs<RecordType>(); + const RecordType *RT = Base.getType()->getAs<RecordType>(); // Remember direct virtual bases. - if (Base->isVirtual()) + if (Base.isVirtual()) DirectVirtualBases.insert(RT); CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(RT->getDecl()); @@ -4023,10 +4015,10 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location, assert(Dtor && "No dtor found for BaseClassDecl!"); // FIXME: caret should be on the start of the class name - CheckDestructorAccess(Base->getLocStart(), Dtor, + CheckDestructorAccess(Base.getLocStart(), Dtor, PDiag(diag::err_access_dtor_base) - << Base->getType() - << Base->getSourceRange(), + << Base.getType() + << Base.getSourceRange(), Context.getTypeDeclType(ClassDecl)); MarkFunctionReferenced(Location, Dtor); @@ -4633,10 +4625,8 @@ static bool defaultedSpecialMemberIsConstexpr(Sema &S, CXXRecordDecl *ClassDecl, // sub-objects shall be a constexpr constructor; // -- the assignment operator selected to copy/move each direct base // class is a constexpr function, and - for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(), - BEnd = ClassDecl->bases_end(); - B != BEnd; ++B) { - const RecordType *BaseType = B->getType()->getAs<RecordType>(); + for (const auto &B : ClassDecl->bases()) { + const RecordType *BaseType = B.getType()->getAs<RecordType>(); if (!BaseType) continue; CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseType->getDecl()); @@ -5357,10 +5347,9 @@ bool Sema::ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, SpecialMemberDeletionInfo SMI(*this, MD, CSM, Diagnose); - for (CXXRecordDecl::base_class_iterator BI = RD->bases_begin(), - BE = RD->bases_end(); BI != BE; ++BI) - if (!BI->isVirtual() && - SMI.shouldDeleteForBase(BI)) + for (auto &BI : RD->bases()) + if (!BI.isVirtual() && + SMI.shouldDeleteForBase(&BI)) return true; // Per DR1611, do not consider virtual bases of constructors of abstract @@ -5726,9 +5715,8 @@ bool Sema::SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, // A [default constructor or destructor] is trivial if // -- all the direct base classes have trivial [default constructors or // destructors] - for (CXXRecordDecl::base_class_iterator BI = RD->bases_begin(), - BE = RD->bases_end(); BI != BE; ++BI) - if (!checkTrivialSubobjectCall(*this, BI->getLocStart(), BI->getType(), + for (const auto &BI : RD->bases()) + if (!checkTrivialSubobjectCall(*this, BI.getLocStart(), BI.getType(), ConstArg, CSM, TSK_BaseClass, Diagnose)) return false; @@ -8002,19 +7990,17 @@ Sema::ComputeDefaultedDefaultCtorExceptionSpec(SourceLocation Loc, return ExceptSpec; // Direct base-class constructors. - for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(), - BEnd = ClassDecl->bases_end(); - B != BEnd; ++B) { - if (B->isVirtual()) // Handled below. + for (const auto &B : ClassDecl->bases()) { + if (B.isVirtual()) // Handled below. continue; - if (const RecordType *BaseType = B->getType()->getAs<RecordType>()) { + if (const RecordType *BaseType = B.getType()->getAs<RecordType>()) { CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseType->getDecl()); CXXConstructorDecl *Constructor = LookupDefaultConstructor(BaseClassDecl); // If this is a deleted function, add it anyway. This might be conformant // with the standard. This might not. I'm not sure. It might not matter. if (Constructor) - ExceptSpec.CalledDecl(B->getLocStart(), Constructor); + ExceptSpec.CalledDecl(B.getLocStart(), Constructor); } } @@ -8089,19 +8075,17 @@ Sema::ComputeInheritingCtorExceptionSpec(CXXConstructorDecl *CD) { ExceptSpec.CalledDecl(CD->getLocStart(), InheritedCD); // Direct base-class constructors. - for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(), - BEnd = ClassDecl->bases_end(); - B != BEnd; ++B) { - if (B->isVirtual()) // Handled below. + for (const auto &B : ClassDecl->bases()) { + if (B.isVirtual()) // Handled below. continue; - if (const RecordType *BaseType = B->getType()->getAs<RecordType>()) { + if (const RecordType *BaseType = B.getType()->getAs<RecordType>()) { CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseType->getDecl()); if (BaseClassDecl == InheritedDecl) continue; CXXConstructorDecl *Constructor = LookupDefaultConstructor(BaseClassDecl); if (Constructor) - ExceptSpec.CalledDecl(B->getLocStart(), Constructor); + ExceptSpec.CalledDecl(B.getLocStart(), Constructor); } } @@ -8550,11 +8534,9 @@ void Sema::DeclareInheritingConstructors(CXXRecordDecl *ClassDecl) { // Find base classes from which we might inherit constructors. SmallVector<CXXRecordDecl*, 4> InheritedBases; - for (CXXRecordDecl::base_class_iterator BaseIt = ClassDecl->bases_begin(), - BaseE = ClassDecl->bases_end(); - BaseIt != BaseE; ++BaseIt) - if (BaseIt->getInheritConstructors()) - InheritedBases.push_back(BaseIt->getType()->getAsCXXRecordDecl()); + for (const auto &BaseIt : ClassDecl->bases()) + if (BaseIt.getInheritConstructors()) + InheritedBases.push_back(BaseIt.getType()->getAsCXXRecordDecl()); // Go no further if we're not inheriting any constructors. if (InheritedBases.empty()) @@ -8607,14 +8589,12 @@ Sema::ComputeDefaultedDtorExceptionSpec(CXXMethodDecl *MD) { return ExceptSpec; // Direct base-class destructors. - for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(), - BEnd = ClassDecl->bases_end(); - B != BEnd; ++B) { - if (B->isVirtual()) // Handled below. + for (const auto &B : ClassDecl->bases()) { + if (B.isVirtual()) // Handled below. continue; - if (const RecordType *BaseType = B->getType()->getAs<RecordType>()) - ExceptSpec.CalledDecl(B->getLocStart(), + if (const RecordType *BaseType = B.getType()->getAs<RecordType>()) + ExceptSpec.CalledDecl(B.getLocStart(), LookupDestructor(cast<CXXRecordDecl>(BaseType->getDecl()))); } @@ -9213,17 +9193,15 @@ Sema::ComputeDefaultedCopyAssignmentExceptionSpec(CXXMethodDecl *MD) { // Based on a similar decision made for constness in C++0x, we're erring on // the side of assuming such calls to be made regardless of whether they // actually happen. - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - BaseEnd = ClassDecl->bases_end(); - Base != BaseEnd; ++Base) { - if (Base->isVirtual()) + for (const auto &Base : ClassDecl->bases()) { + if (Base.isVirtual()) continue; CXXRecordDecl *BaseClassDecl - = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); + = cast<CXXRecordDecl>(Base.getType()->getAs<RecordType>()->getDecl()); if (CXXMethodDecl *CopyAssign = LookupCopyingAssignment(BaseClassDecl, ArgQuals, false, 0)) - ExceptSpec.CalledDecl(Base->getLocStart(), CopyAssign); + ExceptSpec.CalledDecl(Base.getLocStart(), CopyAssign); } for (CXXRecordDecl::base_class_iterator Base = ClassDecl->vbases_begin(), @@ -9429,18 +9407,17 @@ void Sema::DefineImplicitCopyAssignment(SourceLocation CurrentLocation, // Assign base classes. bool Invalid = false; - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - E = ClassDecl->bases_end(); Base != E; ++Base) { + for (auto &Base : ClassDecl->bases()) { // Form the assignment: // static_cast<Base*>(this)->Base::operator=(static_cast<Base&>(other)); - QualType BaseType = Base->getType().getUnqualifiedType(); + QualType BaseType = Base.getType().getUnqualifiedType(); if (!BaseType->isRecordType()) { Invalid = true; continue; } CXXCastPath BasePath; - BasePath.push_back(Base); + BasePath.push_back(&Base); // Construct the "from" expression, which is an implicit cast to the // appropriately-qualified base type. @@ -9598,17 +9575,15 @@ Sema::ComputeDefaultedMoveAssignmentExceptionSpec(CXXMethodDecl *MD) { // actually happen. // Note that a move constructor is not implicitly declared when there are // virtual bases, but it can still be user-declared and explicitly defaulted. - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - BaseEnd = ClassDecl->bases_end(); - Base != BaseEnd; ++Base) { - if (Base->isVirtual()) + for (const auto &Base : ClassDecl->bases()) { + if (Base.isVirtual()) continue; CXXRecordDecl *BaseClassDecl - = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); + = cast<CXXRecordDecl>(Base.getType()->getAs<RecordType>()->getDecl()); if (CXXMethodDecl *MoveAssign = LookupMovingAssignment(BaseClassDecl, 0, false, 0)) - ExceptSpec.CalledDecl(Base->getLocStart(), MoveAssign); + ExceptSpec.CalledDecl(Base.getLocStart(), MoveAssign); } for (CXXRecordDecl::base_class_iterator Base = ClassDecl->vbases_begin(), @@ -9719,10 +9694,8 @@ static void checkMoveAssignmentForRepeatedMove(Sema &S, CXXRecordDecl *Class, typedef llvm::DenseMap<CXXRecordDecl*, CXXBaseSpecifier*> VBaseMap; VBaseMap VBases; - for (CXXRecordDecl::base_class_iterator BI = Class->bases_begin(), - BE = Class->bases_end(); - BI != BE; ++BI) { - Worklist.push_back(&*BI); + for (auto &BI : Class->bases()) { + Worklist.push_back(&BI); while (!Worklist.empty()) { CXXBaseSpecifier *BaseSpec = Worklist.pop_back_val(); CXXRecordDecl *Base = BaseSpec->getType()->getAsCXXRecordDecl(); @@ -9754,19 +9727,19 @@ static void checkMoveAssignmentForRepeatedMove(Sema &S, CXXRecordDecl *Class, // only happens in one base, we'll diagnose it when synthesizing // that base class's move assignment operator.) CXXBaseSpecifier *&Existing = - VBases.insert(std::make_pair(Base->getCanonicalDecl(), BI)) + VBases.insert(std::make_pair(Base->getCanonicalDecl(), &BI)) .first->second; - if (Existing && Existing != BI) { + if (Existing && Existing != &BI) { S.Diag(CurrentLocation, diag::warn_vbase_moved_multiple_times) << Class << Base; S.Diag(Existing->getLocStart(), diag::note_vbase_moved_here) << (Base->getCanonicalDecl() == Existing->getType()->getAsCXXRecordDecl()->getCanonicalDecl()) << Base << Existing->getType() << Existing->getSourceRange(); - S.Diag(BI->getLocStart(), diag::note_vbase_moved_here) + S.Diag(BI.getLocStart(), diag::note_vbase_moved_here) << (Base->getCanonicalDecl() == - BI->getType()->getAsCXXRecordDecl()->getCanonicalDecl()) - << Base << BI->getType() << BaseSpec->getSourceRange(); + BI.getType()->getAsCXXRecordDecl()->getCanonicalDecl()) + << Base << BI.getType() << BaseSpec->getSourceRange(); // Only diagnose each vbase once. Existing = 0; @@ -9779,10 +9752,8 @@ static void checkMoveAssignmentForRepeatedMove(Sema &S, CXXRecordDecl *Class, continue; // We're going to move the base classes of Base. Add them to the list. - for (CXXRecordDecl::base_class_iterator BI = Base->bases_begin(), - BE = Base->bases_end(); - BI != BE; ++BI) - Worklist.push_back(&*BI); + for (auto &BI : Base->bases()) + Worklist.push_back(&BI); } } } @@ -9844,8 +9815,7 @@ void Sema::DefineImplicitMoveAssignment(SourceLocation CurrentLocation, // Assign base classes. bool Invalid = false; - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - E = ClassDecl->bases_end(); Base != E; ++Base) { + for (auto &Base : ClassDecl->bases()) { // C++11 [class.copy]p28: // It is unspecified whether subobjects representing virtual base classes // are assigned more than once by the implicitly-defined copy assignment @@ -9856,14 +9826,14 @@ void Sema::DefineImplicitMoveAssignment(SourceLocation CurrentLocation, // Form the assignment: // static_cast<Base*>(this)->Base::operator=(static_cast<Base&&>(other)); - QualType BaseType = Base->getType().getUnqualifiedType(); + QualType BaseType = Base.getType().getUnqualifiedType(); if (!BaseType->isRecordType()) { Invalid = true; continue; } CXXCastPath BasePath; - BasePath.push_back(Base); + BasePath.push_back(&Base); // Construct the "from" expression, which is an implicit cast to the // appropriately-qualified base type. @@ -10020,19 +9990,16 @@ Sema::ComputeDefaultedCopyCtorExceptionSpec(CXXMethodDecl *MD) { // C++ [except.spec]p14: // An implicitly declared special member function (Clause 12) shall have an // exception-specification. [...] - for (CXXRecordDecl::base_class_iterator Base = ClassDecl->bases_begin(), - BaseEnd = ClassDecl->bases_end(); - Base != BaseEnd; - ++Base) { + for (const auto &Base : ClassDecl->bases()) { // Virtual bases are handled below. - if (Base->isVirtual()) + if (Base.isVirtual()) continue; CXXRecordDecl *BaseClassDecl - = cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl()); + = cast<CXXRecordDecl>(Base.getType()->getAs<RecordType>()->getDecl()); if (CXXConstructorDecl *CopyConstructor = LookupCopyingConstructor(BaseClassDecl, Quals)) - ExceptSpec.CalledDecl(Base->getLocStart(), CopyConstructor); + ExceptSpec.CalledDecl(Base.getLocStart(), CopyConstructor); } for (CXXRecordDecl::base_class_iterator Base = ClassDecl->vbases_begin(), BaseEnd = ClassDecl->vbases_end(); @@ -10177,20 +10144,18 @@ Sema::ComputeDefaultedMoveCtorExceptionSpec(CXXMethodDecl *MD) { return ExceptSpec; // Direct base-class constructors. - for (CXXRecordDecl::base_class_iterator B = ClassDecl->bases_begin(), - BEnd = ClassDecl->bases_end(); - B != BEnd; ++B) { - if (B->isVirtual()) // Handled below. + for (const auto &B : ClassDecl->bases()) { + if (B.isVirtual()) // Handled below. continue; - if (const RecordType *BaseType = B->getType()->getAs<RecordType>()) { + if (const RecordType *BaseType = B.getType()->getAs<RecordType>()) { CXXRecordDecl *BaseClassDecl = cast<CXXRecordDecl>(BaseType->getDecl()); CXXConstructorDecl *Constructor = LookupMovingConstructor(BaseClassDecl, 0); // If this is a deleted function, add it anyway. This might be conformant // with the standard. This might not. I'm not sure. It might not matter. if (Constructor) - ExceptSpec.CalledDecl(B->getLocStart(), Constructor); + ExceptSpec.CalledDecl(B.getLocStart(), Constructor); } } @@ -12436,10 +12401,9 @@ void Sema::MarkVirtualMembersReferenced(SourceLocation Loc, if (RD->getNumVBases() == 0) return; - for (CXXRecordDecl::base_class_const_iterator i = RD->bases_begin(), - e = RD->bases_end(); i != e; ++i) { + for (const auto &I : RD->bases()) { const CXXRecordDecl *Base = - cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); + cast<CXXRecordDecl>(I.getType()->getAs<RecordType>()->getDecl()); if (Base->getNumVBases() == 0) continue; MarkVirtualMembersReferenced(Loc, Base); diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 7d2426be87d..9c6877e0e1b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -559,11 +559,9 @@ class RecordMemberExprValidatorCCC : public CorrectionCandidateCallback { if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Record)) { // Accept candidates that occur in any of the current class' base classes. - for (CXXRecordDecl::base_class_const_iterator BS = RD->bases_begin(), - BSEnd = RD->bases_end(); - BS != BSEnd; ++BS) { + for (const auto &BS : RD->bases()) { if (const RecordType *BSTy = dyn_cast_or_null<RecordType>( - BS->getType().getTypePtrOrNull())) { + BS.getType().getTypePtrOrNull())) { if (BSTy->getDecl()->containsDecl(ND)) return true; } diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index b8f5583f25f..382901667ed 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6263,10 +6263,8 @@ static bool DiagnoseUninitializedReference(Sema &S, SourceLocation Loc, } } - for (CXXRecordDecl::base_class_iterator BI = RD->bases_begin(), - BE = RD->bases_end(); - BI != BE; ++BI) { - if (DiagnoseUninitializedReference(S, BI->getLocStart(), BI->getType())) { + for (const auto &BI : RD->bases()) { + if (DiagnoseUninitializedReference(S, BI.getLocStart(), BI.getType())) { S.Diag(Loc, diag::note_value_initialization_here) << RD; return true; } diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 2ace8c2769c..0e31606aaf6 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -2069,10 +2069,8 @@ addAssociatedClassesAndNamespaces(AssociatedLookup &Result, Class = Bases.pop_back_val(); // Visit the base classes. - for (CXXRecordDecl::base_class_iterator Base = Class->bases_begin(), - BaseEnd = Class->bases_end(); - Base != BaseEnd; ++Base) { - const RecordType *BaseType = Base->getType()->getAs<RecordType>(); + for (const auto &Base : Class->bases()) { + const RecordType *BaseType = Base.getType()->getAs<RecordType>(); // In dependent contexts, we do ADL twice, and the first time around, // the base type might be a dependent TemplateSpecializationType, or a // TemplateTypeParmType. If that happens, simply ignore it. @@ -3094,10 +3092,8 @@ static void LookupVisibleDecls(DeclContext *Ctx, LookupResult &Result, if (!Record->hasDefinition()) return; - for (CXXRecordDecl::base_class_iterator B = Record->bases_begin(), - BEnd = Record->bases_end(); - B != BEnd; ++B) { - QualType BaseType = B->getType(); + for (const auto &B : Record->bases()) { + QualType BaseType = B.getType(); // Don't look into dependent bases, because name lookup can't look // there anyway. diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index ef325b04edf..8a0589a747f 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -1472,12 +1472,10 @@ DeduceTemplateArgumentsByTypeMatch(Sema &S, // Visit base classes CXXRecordDecl *Next = cast<CXXRecordDecl>(NextT->getDecl()); - for (CXXRecordDecl::base_class_iterator Base = Next->bases_begin(), - BaseEnd = Next->bases_end(); - Base != BaseEnd; ++Base) { - assert(Base->getType()->isRecordType() && + for (const auto &Base : Next->bases()) { + assert(Base.getType()->isRecordType() && "Base class that isn't a record?"); - ToVisit.push_back(Base->getType()->getAs<RecordType>()); + ToVisit.push_back(Base.getType()->getAs<RecordType>()); } } diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 7faaecefa88..7b3fc77eb05 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1818,31 +1818,29 @@ Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, const MultiLevelTemplateArgumentList &TemplateArgs) { bool Invalid = false; SmallVector<CXXBaseSpecifier*, 4> InstantiatedBases; - for (ClassTemplateSpecializationDecl::base_class_iterator - Base = Pattern->bases_begin(), BaseEnd = Pattern->bases_end(); - Base != BaseEnd; ++Base) { - if (!Base->getType()->isDependentType()) { - if (const CXXRecordDecl *RD = Base->getType()->getAsCXXRecordDecl()) { + for (const auto Base : Pattern->bases()) { + if (!Base.getType()->isDependentType()) { + if (const CXXRecordDecl *RD = Base.getType()->getAsCXXRecordDecl()) { if (RD->isInvalidDecl()) Instantiation->setInvalidDecl(); } - InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(*Base)); + InstantiatedBases.push_back(new (Context) CXXBaseSpecifier(Base)); continue; } SourceLocation EllipsisLoc; TypeSourceInfo *BaseTypeLoc; - if (Base->isPackExpansion()) { + if (Base.isPackExpansion()) { // This is a pack expansion. See whether we should expand it now, or // wait until later. SmallVector<UnexpandedParameterPack, 2> Unexpanded; - collectUnexpandedParameterPacks(Base->getTypeSourceInfo()->getTypeLoc(), + collectUnexpandedParameterPacks(Base.getTypeSourceInfo()->getTypeLoc(), Unexpanded); bool ShouldExpand = false; bool RetainExpansion = false; Optional<unsigned> NumExpansions; - if (CheckParameterPacksForExpansion(Base->getEllipsisLoc(), - Base->getSourceRange(), + if (CheckParameterPacksForExpansion(Base.getEllipsisLoc(), + Base.getSourceRange(), Unexpanded, TemplateArgs, ShouldExpand, RetainExpansion, @@ -1856,9 +1854,9 @@ Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, for (unsigned I = 0; I != *NumExpansions; ++I) { Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, I); - TypeSourceInfo *BaseTypeLoc = SubstType(Base->getTypeSourceInfo(), + TypeSourceInfo *BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), TemplateArgs, - Base->getSourceRange().getBegin(), + Base.getSourceRange().getBegin(), DeclarationName()); if (!BaseTypeLoc) { Invalid = true; @@ -1867,9 +1865,9 @@ Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, if (CXXBaseSpecifier *InstantiatedBase = CheckBaseSpecifier(Instantiation, - Base->getSourceRange(), - Base->isVirtual(), - Base->getAccessSpecifierAsWritten(), + Base.getSourceRange(), + Base.isVirtual(), + Base.getAccessSpecifierAsWritten(), BaseTypeLoc, SourceLocation())) InstantiatedBases.push_back(InstantiatedBase); @@ -1881,16 +1879,16 @@ Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, } // The resulting base specifier will (still) be a pack expansion. - EllipsisLoc = Base->getEllipsisLoc(); + EllipsisLoc = Base.getEllipsisLoc(); Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(*this, -1); - BaseTypeLoc = SubstType(Base->getTypeSourceInfo(), + BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), TemplateArgs, - Base->getSourceRange().getBegin(), + Base.getSourceRange().getBegin(), DeclarationName()); } else { - BaseTypeLoc = SubstType(Base->getTypeSourceInfo(), + BaseTypeLoc = SubstType(Base.getTypeSourceInfo(), TemplateArgs, - Base->getSourceRange().getBegin(), + Base.getSourceRange().getBegin(), DeclarationName()); } @@ -1901,9 +1899,9 @@ Sema::SubstBaseSpecifiers(CXXRecordDecl *Instantiation, if (CXXBaseSpecifier *InstantiatedBase = CheckBaseSpecifier(Instantiation, - Base->getSourceRange(), - Base->isVirtual(), - Base->getAccessSpecifierAsWritten(), + Base.getSourceRange(), + Base.isVirtual(), + Base.getAccessSpecifierAsWritten(), BaseTypeLoc, EllipsisLoc)) InstantiatedBases.push_back(InstantiatedBase); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 1dadde8da01..f91778f8286 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -5327,12 +5327,11 @@ bool Sema::RequireLiteralType(SourceLocation Loc, QualType T, !RD->hasTrivialDefaultConstructor()) { Diag(RD->getLocation(), diag::note_non_literal_no_constexpr_ctors) << RD; } else if (RD->hasNonLiteralTypeFieldsOrBases()) { - for (CXXRecordDecl::base_class_const_iterator I = RD->bases_begin(), - E = RD->bases_end(); I != E; ++I) { - if (!I->getType()->isLiteralType(Context)) { - Diag(I->getLocStart(), + for (const auto &I : RD->bases()) { + if (!I.getType()->isLiteralType(Context)) { + Diag(I.getLocStart(), diag::note_non_literal_base_class) - << RD << I->getType() << I->getSourceRange(); + << RD << I.getType() << I.getSourceRange(); return true; } } |