diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index ace5f60b572d7..0e4de4f9e1c88 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -657,8 +657,8 @@ iterator_range>> make_early_inc_range(RangeT &&Range) { using EarlyIncIteratorT = early_inc_iterator_impl>; - return make_range(EarlyIncIteratorT(std::begin(std::forward(Range))), - EarlyIncIteratorT(std::end(std::forward(Range)))); + return make_range(EarlyIncIteratorT(adl_begin(Range)), + EarlyIncIteratorT(adl_end(Range))); } // Forward declarations required by zip_shortest/zip_equal/zip_first/zip_longest diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp index 406ff2bc16073..b700f7d7f4404 100644 --- a/llvm/unittests/ADT/STLExtrasTest.cpp +++ b/llvm/unittests/ADT/STLExtrasTest.cpp @@ -767,7 +767,7 @@ TEST(STLExtrasTest, EarlyIncrementTest) { #endif // Inserting shouldn't break anything. We should be able to keep dereferencing - // the currrent iterator and increment. The increment to go to the "next" + // the current iterator and increment. The increment to go to the "next" // iterator from before we inserted. L.insert(std::next(L.begin(), 2), -1); ++I; @@ -781,6 +781,14 @@ TEST(STLExtrasTest, EarlyIncrementTest) { EXPECT_EQ(EIR.end(), I); } +TEST(STLExtrasTest, EarlyIncADLTest) { + // Make sure that we use the `begin`/`end` functions from `some_namespace`, + // using ADL. + some_namespace::some_struct S; + S.data = {1, 2, 3}; + EXPECT_THAT(make_early_inc_range(S), ElementsAre(1, 2, 3)); +} + // A custom iterator that returns a pointer when dereferenced. This is used to // test make_early_inc_range with iterators that do not return a reference on // dereferencing.