Skip to content

Commit 5b45106

Browse files
committed
[ADT] Pass DerivedT from pointe{e,r}_iterator to iterator_adaptor_base
These were passing the wrong type into iterator_adaptor_base if T was anything but the default. llvm-svn: 335698
1 parent 73dbe86 commit 5b45106

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/include/llvm/ADT/iterator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ template <typename WrappedIteratorT,
288288
decltype(**std::declval<WrappedIteratorT>())>::type>
289289
struct pointee_iterator
290290
: iterator_adaptor_base<
291-
pointee_iterator<WrappedIteratorT>, WrappedIteratorT,
291+
pointee_iterator<WrappedIteratorT, T>, WrappedIteratorT,
292292
typename std::iterator_traits<WrappedIteratorT>::iterator_category,
293293
T> {
294294
pointee_iterator() = default;
@@ -311,7 +311,7 @@ make_pointee_range(RangeT &&Range) {
311311
template <typename WrappedIteratorT,
312312
typename T = decltype(&*std::declval<WrappedIteratorT>())>
313313
class pointer_iterator
314-
: public iterator_adaptor_base<pointer_iterator<WrappedIteratorT>,
314+
: public iterator_adaptor_base<pointer_iterator<WrappedIteratorT, T>,
315315
WrappedIteratorT, T> {
316316
mutable T Ptr;
317317

llvm/unittests/ADT/IteratorTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ TEST(PointeeIteratorTest, Range) {
128128
EXPECT_EQ(A[I++], II);
129129
}
130130

131+
TEST(PointeeIteratorTest, PointeeType) {
132+
struct S {
133+
int X;
134+
bool operator==(const S &RHS) const { return X == RHS.X; };
135+
};
136+
S A[] = {S{0}, S{1}};
137+
SmallVector<S *, 2> V{&A[0], &A[1]};
138+
139+
pointee_iterator<SmallVectorImpl<S *>::const_iterator, const S> I = V.begin();
140+
for (int j = 0; j < 2; ++j, ++I) {
141+
EXPECT_EQ(*V[j], *I);
142+
}
143+
}
144+
131145
TEST(FilterIteratorTest, Lambda) {
132146
auto IsOdd = [](int N) { return N % 2 == 1; };
133147
int A[] = {0, 1, 2, 3, 4, 5, 6};

0 commit comments

Comments
 (0)