Skip to content

Commit 3ee58e1

Browse files
committed
[ADT] Use adl_being/adl_end in make_early_inc_range
This is to make sure that ADT helpers consistently use argument dependent lookup when dealing with input ranges. This was a part of #87936 but reverted due to buildbot failures. Also fix potential issue with double-move on the input range.
1 parent bd64f31 commit 3ee58e1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ iterator_range<early_inc_iterator_impl<detail::IterOfRange<RangeT>>>
657657
make_early_inc_range(RangeT &&Range) {
658658
using EarlyIncIteratorT =
659659
early_inc_iterator_impl<detail::IterOfRange<RangeT>>;
660-
return make_range(EarlyIncIteratorT(std::begin(std::forward<RangeT>(Range))),
661-
EarlyIncIteratorT(std::end(std::forward<RangeT>(Range))));
660+
return make_range(EarlyIncIteratorT(adl_begin(Range)),
661+
EarlyIncIteratorT(adl_end(Range)));
662662
}
663663

664664
// Forward declarations required by zip_shortest/zip_equal/zip_first/zip_longest

llvm/unittests/ADT/STLExtrasTest.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ TEST(STLExtrasTest, EarlyIncrementTest) {
767767
#endif
768768

769769
// Inserting shouldn't break anything. We should be able to keep dereferencing
770-
// the currrent iterator and increment. The increment to go to the "next"
770+
// the current iterator and increment. The increment to go to the "next"
771771
// iterator from before we inserted.
772772
L.insert(std::next(L.begin(), 2), -1);
773773
++I;
@@ -781,6 +781,14 @@ TEST(STLExtrasTest, EarlyIncrementTest) {
781781
EXPECT_EQ(EIR.end(), I);
782782
}
783783

784+
TEST(STLExtrasTest, EarlyIncADLTest) {
785+
// Make sure that we use the `begin`/`end` functions from `some_namespace`,
786+
// using ADL.
787+
some_namespace::some_struct S;
788+
S.data = {1, 2, 3};
789+
EXPECT_THAT(make_early_inc_range(S), ElementsAre(1, 2, 3));
790+
}
791+
784792
// A custom iterator that returns a pointer when dereferenced. This is used to
785793
// test make_early_inc_range with iterators that do not return a reference on
786794
// dereferencing.

0 commit comments

Comments
 (0)