Skip to content

Commit dad0a4e

Browse files
authored
[ADT] Use adl_being/adl_end in make_early_inc_range (#130518)
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 8132c4f commit dad0a4e

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
@@ -656,8 +656,8 @@ iterator_range<early_inc_iterator_impl<detail::IterOfRange<RangeT>>>
656656
make_early_inc_range(RangeT &&Range) {
657657
using EarlyIncIteratorT =
658658
early_inc_iterator_impl<detail::IterOfRange<RangeT>>;
659-
return make_range(EarlyIncIteratorT(std::begin(std::forward<RangeT>(Range))),
660-
EarlyIncIteratorT(std::end(std::forward<RangeT>(Range))));
659+
return make_range(EarlyIncIteratorT(adl_begin(Range)),
660+
EarlyIncIteratorT(adl_end(Range)));
661661
}
662662

663663
// 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
@@ -787,7 +787,7 @@ TEST(STLExtrasTest, EarlyIncrementTest) {
787787
#endif
788788

789789
// Inserting shouldn't break anything. We should be able to keep dereferencing
790-
// the currrent iterator and increment. The increment to go to the "next"
790+
// the current iterator and increment. The increment to go to the "next"
791791
// iterator from before we inserted.
792792
L.insert(std::next(L.begin(), 2), -1);
793793
++I;
@@ -801,6 +801,14 @@ TEST(STLExtrasTest, EarlyIncrementTest) {
801801
EXPECT_EQ(EIR.end(), I);
802802
}
803803

804+
TEST(STLExtrasTest, EarlyIncADLTest) {
805+
// Make sure that we use the `begin`/`end` functions from `some_namespace`,
806+
// using ADL.
807+
some_namespace::some_struct S;
808+
S.data = {1, 2, 3};
809+
EXPECT_THAT(make_early_inc_range(S), ElementsAre(1, 2, 3));
810+
}
811+
804812
// A custom iterator that returns a pointer when dereferenced. This is used to
805813
// test make_early_inc_range with iterators that do not return a reference on
806814
// dereferencing.

0 commit comments

Comments
 (0)