diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index db751b227586..c6bc7411f4fc 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -745,6 +745,9 @@ public: /// An iterator over friend declarations. All of these are defined /// in DeclFriend.h. class friend_iterator; + typedef llvm::iterator_range friend_range; + + friend_range friends() const; friend_iterator friend_begin() const; friend_iterator friend_end() const; void pushFriendDecl(FriendDecl *FD); diff --git a/clang/include/clang/AST/DeclFriend.h b/clang/include/clang/AST/DeclFriend.h index 5d4633e0668c..bb852d0629a8 100644 --- a/clang/include/clang/AST/DeclFriend.h +++ b/clang/include/clang/AST/DeclFriend.h @@ -227,6 +227,10 @@ inline CXXRecordDecl::friend_iterator CXXRecordDecl::friend_end() const { return friend_iterator(0); } +inline CXXRecordDecl::friend_range CXXRecordDecl::friends() const { + return friend_range(friend_begin(), friend_end()); +} + inline void CXXRecordDecl::pushFriendDecl(FriendDecl *FD) { assert(!FD->NextFriend && "friend already has next friend?"); FD->NextFriend = data().FirstFriend; diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp index 541b7f927597..f7806d251612 100644 --- a/clang/lib/Sema/SemaAccess.cpp +++ b/clang/lib/Sema/SemaAccess.cpp @@ -571,10 +571,7 @@ static AccessResult GetFriendKind(Sema &S, AccessResult OnFailure = AR_inaccessible; // Okay, check friends. - for (CXXRecordDecl::friend_iterator I = Class->friend_begin(), - E = Class->friend_end(); I != E; ++I) { - FriendDecl *Friend = *I; - + for (auto *Friend : Class->friends()) { switch (MatchesFriend(S, EC, Friend)) { case AR_accessible: return AR_accessible;