Skip to content

Commit 0a92aff

Browse files
hamzasoodMaskRay
authored andcommitted
Replace uses of std::iterator with explicit using
This patch removes all uses of `std::iterator`, which was deprecated in C++17. While this isn't currently an issue while compiling LLVM, it's useful for those using LLVM as a library. For some reason there're a few places that were seemingly able to use `std` functions unqualified, which no longer works after this patch. I've updated those places, but I'm not really sure why it worked in the first place. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D67586
1 parent d737c47 commit 0a92aff

37 files changed

+448
-273
lines changed

clang/include/clang/AST/StmtIterator.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,17 @@ class StmtIteratorBase {
7474
};
7575

7676
template <typename DERIVED, typename REFERENCE>
77-
class StmtIteratorImpl : public StmtIteratorBase,
78-
public std::iterator<std::forward_iterator_tag,
79-
REFERENCE, ptrdiff_t,
80-
REFERENCE, REFERENCE> {
77+
class StmtIteratorImpl : public StmtIteratorBase {
8178
protected:
8279
StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
8380

8481
public:
82+
using iterator_category = std::forward_iterator_tag;
83+
using value_type = REFERENCE;
84+
using difference_type = std::ptrdiff_t;
85+
using pointer = REFERENCE;
86+
using reference = REFERENCE;
87+
8588
StmtIteratorImpl() = default;
8689
StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
8790
StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}

clang/include/clang/Rewrite/Core/RewriteRope.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ namespace clang {
8383
/// over bytes that are in a RopePieceBTree. This first iterates over bytes
8484
/// in a RopePiece, then iterates over RopePiece's in a RopePieceBTreeLeaf,
8585
/// then iterates over RopePieceBTreeLeaf's in a RopePieceBTree.
86-
class RopePieceBTreeIterator :
87-
public std::iterator<std::forward_iterator_tag, const char, ptrdiff_t> {
86+
class RopePieceBTreeIterator {
8887
/// CurNode - The current B+Tree node that we are inspecting.
8988
const void /*RopePieceBTreeLeaf*/ *CurNode = nullptr;
9089

@@ -96,6 +95,12 @@ namespace clang {
9695
unsigned CurChar = 0;
9796

9897
public:
98+
using iterator_category = std::forward_iterator_tag;
99+
using value_type = const char;
100+
using difference_type = std::ptrdiff_t;
101+
using pointer = value_type *;
102+
using reference = value_type &;
103+
99104
RopePieceBTreeIterator() = default;
100105
RopePieceBTreeIterator(const void /*RopePieceBTreeNode*/ *N);
101106

llvm/include/llvm/ADT/BreadthFirstIterator.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ template <class GraphT,
4444
class SetType =
4545
bf_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
4646
class GT = GraphTraits<GraphT>>
47-
class bf_iterator
48-
: public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
49-
public bf_iterator_storage<SetType> {
50-
using super = std::iterator<std::forward_iterator_tag, typename GT::NodeRef>;
47+
class bf_iterator : public bf_iterator_storage<SetType> {
48+
public:
49+
using iterator_category = std::forward_iterator_tag;
50+
using value_type = typename GT::NodeRef;
51+
using difference_type = std::ptrdiff_t;
52+
using pointer = value_type *;
53+
using reference = value_type &;
5154

55+
private:
5256
using NodeRef = typename GT::NodeRef;
5357
using ChildItTy = typename GT::ChildIteratorType;
5458

@@ -62,7 +66,6 @@ class bf_iterator
6266
// Current level.
6367
unsigned Level;
6468

65-
private:
6669
inline bf_iterator(NodeRef Node) {
6770
this->Visited.insert(Node);
6871
Level = 0;
@@ -107,8 +110,6 @@ class bf_iterator
107110
}
108111

109112
public:
110-
using pointer = typename super::pointer;
111-
112113
// Provide static begin and end methods as our public "constructors"
113114
static bf_iterator begin(const GraphT &G) {
114115
return bf_iterator(GT::getEntryNode(G));

llvm/include/llvm/ADT/CoalescingBitVector.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,17 @@ template <typename IndexT> class CoalescingBitVector {
231231

232232
bool operator!=(const ThisT &RHS) const { return !operator==(RHS); }
233233

234-
class const_iterator
235-
: public std::iterator<std::forward_iterator_tag, IndexT> {
234+
class const_iterator {
236235
friend class CoalescingBitVector;
237236

237+
public:
238+
using iterator_category = std::forward_iterator_tag;
239+
using value_type = IndexT;
240+
using difference_type = std::ptrdiff_t;
241+
using pointer = value_type *;
242+
using reference = value_type &;
243+
244+
private:
238245
// For performance reasons, make the offset at the end different than the
239246
// one used in \ref begin, to optimize the common `It == end()` pattern.
240247
static constexpr unsigned kIteratorAtTheEndOffset = ~0u;

llvm/include/llvm/ADT/DepthFirstIterator.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ template <class GraphT,
8282
class SetType =
8383
df_iterator_default_set<typename GraphTraits<GraphT>::NodeRef>,
8484
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
85-
class df_iterator
86-
: public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
87-
public df_iterator_storage<SetType, ExtStorage> {
88-
using super = std::iterator<std::forward_iterator_tag, typename GT::NodeRef>;
85+
class df_iterator : public df_iterator_storage<SetType, ExtStorage> {
86+
public:
87+
using iterator_category = std::forward_iterator_tag;
88+
using value_type = typename GT::NodeRef;
89+
using difference_type = std::ptrdiff_t;
90+
using pointer = value_type *;
91+
using reference = value_type &;
92+
93+
private:
8994
using NodeRef = typename GT::NodeRef;
9095
using ChildItTy = typename GT::ChildIteratorType;
9196

@@ -97,7 +102,6 @@ class df_iterator
97102
// VisitStack - Used to maintain the ordering. Top = current block
98103
std::vector<StackElement> VisitStack;
99104

100-
private:
101105
inline df_iterator(NodeRef Node) {
102106
this->Visited.insert(Node);
103107
VisitStack.push_back(StackElement(Node, None));
@@ -144,8 +148,6 @@ class df_iterator
144148
}
145149

146150
public:
147-
using pointer = typename super::pointer;
148-
149151
// Provide static begin and end methods as our public "constructors"
150152
static df_iterator begin(const GraphT &G) {
151153
return df_iterator(GT::getEntryNode(G));

llvm/include/llvm/ADT/EquivalenceClasses.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,18 @@ class EquivalenceClasses {
248248
return It != member_end() && It == findLeader(V2);
249249
}
250250

251-
class member_iterator : public std::iterator<std::forward_iterator_tag,
252-
const ElemTy, ptrdiff_t> {
251+
class member_iterator {
253252
friend class EquivalenceClasses;
254253

255-
using super = std::iterator<std::forward_iterator_tag,
256-
const ElemTy, ptrdiff_t>;
257-
258254
const ECValue *Node;
259255

260256
public:
261-
using size_type = size_t;
262-
using pointer = typename super::pointer;
263-
using reference = typename super::reference;
257+
using iterator_category = std::forward_iterator_tag;
258+
using value_type = const ElemTy;
259+
using size_type = std::size_t;
260+
using difference_type = std::ptrdiff_t;
261+
using pointer = value_type *;
262+
using reference = value_type &;
264263

265264
explicit member_iterator() = default;
266265
explicit member_iterator(const ECValue *N) : Node(N) {}

llvm/include/llvm/ADT/ImmutableSet.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,13 +651,16 @@ class ImutAVLFactory {
651651
// Immutable AVL-Tree Iterators.
652652
//===----------------------------------------------------------------------===//
653653

654-
template <typename ImutInfo>
655-
class ImutAVLTreeGenericIterator
656-
: public std::iterator<std::bidirectional_iterator_tag,
657-
ImutAVLTree<ImutInfo>> {
654+
template <typename ImutInfo> class ImutAVLTreeGenericIterator {
658655
SmallVector<uintptr_t,20> stack;
659656

660657
public:
658+
using iterator_category = std::bidirectional_iterator_tag;
659+
using value_type = ImutAVLTree<ImutInfo>;
660+
using difference_type = std::ptrdiff_t;
661+
using pointer = value_type *;
662+
using reference = value_type &;
663+
661664
enum VisitFlag { VisitedNone=0x0, VisitedLeft=0x1, VisitedRight=0x3,
662665
Flags=0x3 };
663666

@@ -762,15 +765,18 @@ class ImutAVLTreeGenericIterator
762765
}
763766
};
764767

765-
template <typename ImutInfo>
766-
class ImutAVLTreeInOrderIterator
767-
: public std::iterator<std::bidirectional_iterator_tag,
768-
ImutAVLTree<ImutInfo>> {
768+
template <typename ImutInfo> class ImutAVLTreeInOrderIterator {
769769
using InternalIteratorTy = ImutAVLTreeGenericIterator<ImutInfo>;
770770

771771
InternalIteratorTy InternalItr;
772772

773773
public:
774+
using iterator_category = std::bidirectional_iterator_tag;
775+
using value_type = ImutAVLTree<ImutInfo>;
776+
using difference_type = std::ptrdiff_t;
777+
using pointer = value_type *;
778+
using reference = value_type &;
779+
774780
using TreeTy = ImutAVLTree<ImutInfo>;
775781

776782
ImutAVLTreeInOrderIterator(const TreeTy* Root) : InternalItr(Root) {

llvm/include/llvm/ADT/IntervalMap.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@
6363
// };
6464
//
6565
// template <typename KeyT, typename ValT, unsigned N, typename Traits>
66-
// class IntervalMap::const_iterator :
67-
// public std::iterator<std::bidirectional_iterator_tag, ValT> {
66+
// class IntervalMap::const_iterator {
6867
// public:
68+
// using iterator_category = std::bidirectional_iterator_tag;
69+
// using value_type = ValT;
70+
// using difference_type = std::ptrdiff_t;
71+
// using pointer = value_type *;
72+
// using reference = value_type &;
73+
//
6974
// bool operator==(const const_iterator &) const;
7075
// bool operator!=(const const_iterator &) const;
7176
// bool valid() const;
@@ -1289,12 +1294,17 @@ clear() {
12891294
//===----------------------------------------------------------------------===//
12901295

12911296
template <typename KeyT, typename ValT, unsigned N, typename Traits>
1292-
class IntervalMap<KeyT, ValT, N, Traits>::const_iterator :
1293-
public std::iterator<std::bidirectional_iterator_tag, ValT> {
1294-
1295-
protected:
1297+
class IntervalMap<KeyT, ValT, N, Traits>::const_iterator {
12961298
friend class IntervalMap;
12971299

1300+
public:
1301+
using iterator_category = std::bidirectional_iterator_tag;
1302+
using value_type = ValT;
1303+
using difference_type = std::ptrdiff_t;
1304+
using pointer = value_type *;
1305+
using reference = value_type &;
1306+
1307+
protected:
12981308
// The map referred to.
12991309
IntervalMap *map = nullptr;
13001310

llvm/include/llvm/ADT/PostOrderIterator.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ class po_iterator_storage<SetType, true> {
9090
};
9191

9292
template <class GraphT,
93-
class SetType =
94-
SmallPtrSet<typename GraphTraits<GraphT>::NodeRef, 8>,
93+
class SetType = SmallPtrSet<typename GraphTraits<GraphT>::NodeRef, 8>,
9594
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
96-
class po_iterator
97-
: public std::iterator<std::forward_iterator_tag, typename GT::NodeRef>,
98-
public po_iterator_storage<SetType, ExtStorage> {
99-
using super = std::iterator<std::forward_iterator_tag, typename GT::NodeRef>;
95+
class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
96+
public:
97+
using iterator_category = std::forward_iterator_tag;
98+
using value_type = typename GT::NodeRef;
99+
using difference_type = std::ptrdiff_t;
100+
using pointer = value_type *;
101+
using reference = value_type &;
102+
103+
private:
100104
using NodeRef = typename GT::NodeRef;
101105
using ChildItTy = typename GT::ChildIteratorType;
102106

@@ -135,8 +139,6 @@ class po_iterator
135139
}
136140

137141
public:
138-
using pointer = typename super::pointer;
139-
140142
// Provide static "constructors"...
141143
static po_iterator begin(GraphT G) {
142144
return po_iterator(GT::getEntryNode(G));

llvm/include/llvm/ADT/SparseMultiSet.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,17 @@ class SparseMultiSet {
216216

217217
/// Our iterators are iterators over the collection of objects that share a
218218
/// key.
219-
template<typename SMSPtrTy>
220-
class iterator_base : public std::iterator<std::bidirectional_iterator_tag,
221-
ValueT> {
219+
template <typename SMSPtrTy> class iterator_base {
222220
friend class SparseMultiSet;
223221

222+
public:
223+
using iterator_category = std::bidirectional_iterator_tag;
224+
using value_type = ValueT;
225+
using difference_type = std::ptrdiff_t;
226+
using pointer = value_type *;
227+
using reference = value_type &;
228+
229+
private:
224230
SMSPtrTy SMS;
225231
unsigned Idx;
226232
unsigned SparseIdx;
@@ -247,12 +253,6 @@ class SparseMultiSet {
247253
void setNext(unsigned N) { SMS->Dense[Idx].Next = N; }
248254

249255
public:
250-
using super = std::iterator<std::bidirectional_iterator_tag, ValueT>;
251-
using value_type = typename super::value_type;
252-
using difference_type = typename super::difference_type;
253-
using pointer = typename super::pointer;
254-
using reference = typename super::reference;
255-
256256
reference operator*() const {
257257
assert(isKeyed() && SMS->sparseIndex(SMS->Dense[Idx].Data) == SparseIdx &&
258258
"Dereferencing iterator of invalid key or index");
@@ -411,7 +411,7 @@ class SparseMultiSet {
411411
RangePair equal_range(const KeyT &K) {
412412
iterator B = find(K);
413413
iterator E = iterator(this, SMSNode::INVALID, B.SparseIdx);
414-
return make_pair(B, E);
414+
return std::make_pair(B, E);
415415
}
416416

417417
/// Insert a new element at the tail of the subset list. Returns an iterator

llvm/include/llvm/ADT/iterator.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ namespace llvm {
6464
template <typename DerivedT, typename IteratorCategoryT, typename T,
6565
typename DifferenceTypeT = std::ptrdiff_t, typename PointerT = T *,
6666
typename ReferenceT = T &>
67-
class iterator_facade_base
68-
: public std::iterator<IteratorCategoryT, T, DifferenceTypeT, PointerT,
69-
ReferenceT> {
67+
class iterator_facade_base {
68+
public:
69+
using iterator_category = IteratorCategoryT;
70+
using value_type = T;
71+
using difference_type = DifferenceTypeT;
72+
using pointer = PointerT;
73+
using reference = ReferenceT;
74+
7075
protected:
7176
enum {
7277
IsRandomAccess = std::is_base_of<std::random_access_iterator_tag,

llvm/include/llvm/Analysis/AliasSetTracker.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,16 @@ class AliasSet : public ilist_node<AliasSet> {
232232
void dump() const;
233233

234234
/// Define an iterator for alias sets... this is just a forward iterator.
235-
class iterator : public std::iterator<std::forward_iterator_tag,
236-
PointerRec, ptrdiff_t> {
235+
class iterator {
237236
PointerRec *CurNode;
238237

239238
public:
239+
using iterator_category = std::forward_iterator_tag;
240+
using value_type = PointerRec;
241+
using difference_type = std::ptrdiff_t;
242+
using pointer = value_type *;
243+
using reference = value_type &;
244+
240245
explicit iterator(PointerRec *CN = nullptr) : CurNode(CN) {}
241246

242247
bool operator==(const iterator& x) const {

llvm/include/llvm/Analysis/MemorySSA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ class memoryaccess_def_iterator_base
11001100
return MP->getIncomingBlock(ArgNo);
11011101
}
11021102

1103-
typename BaseT::iterator::pointer operator*() const {
1103+
typename std::iterator_traits<BaseT>::pointer operator*() const {
11041104
assert(Access && "Tried to access past the end of our iterator");
11051105
// Go to the first argument for phis, and the defining access for everything
11061106
// else.
@@ -1196,7 +1196,7 @@ class upward_defs_iterator
11961196
return DefIterator == Other.DefIterator;
11971197
}
11981198

1199-
BaseT::iterator::reference operator*() const {
1199+
typename std::iterator_traits<BaseT>::reference operator*() const {
12001200
assert(DefIterator != OriginalAccess->defs_end() &&
12011201
"Tried to access past the end of our iterator");
12021202
return CurrentPair;

0 commit comments

Comments
 (0)