[libcxx] Qualify make_pair in searcher implementations to prevent ADL

This patch adds `_VSTD::` to some calls to `make_pair` inside the
implementations of searchers, to prevent things exploding if there is
a make_pair in an associated namespace of a user-defined type.
https://godbolt.org/z/xAFG98

Differential Revision: https://reviews.llvm.org/D72640

Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 5b4a98eb58aa7672bbdc5e31e573f8f1220fc9c7
diff --git a/include/functional b/include/functional
index 67be9ee..fa55864 100644
--- a/include/functional
+++ b/include/functional
@@ -3050,14 +3050,14 @@
          forward_iterator_tag, forward_iterator_tag)
 {
     if (__first2 == __last2)
-        return make_pair(__first1, __first1);  // Everything matches an empty sequence
+        return _VSTD::make_pair(__first1, __first1);  // Everything matches an empty sequence
     while (true)
     {
         // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
         while (true)
         {
             if (__first1 == __last1)  // return __last1 if no element matches *__first2
-                return make_pair(__last1, __last1);
+                return _VSTD::make_pair(__last1, __last1);
             if (__pred(*__first1, *__first2))
                 break;
             ++__first1;
@@ -3068,9 +3068,9 @@
         while (true)
         {
             if (++__m2 == __last2)  // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
-                return make_pair(__first1, __m1);
+                return _VSTD::make_pair(__first1, __m1);
             if (++__m1 == __last1)  // Otherwise if source exhaused, pattern not found
-                return make_pair(__last1, __last1);
+                return _VSTD::make_pair(__last1, __last1);
             if (!__pred(*__m1, *__m2))  // if there is a mismatch, restart with a new __first1
             {
                 ++__first1;
@@ -3092,10 +3092,10 @@
     // Take advantage of knowing source and pattern lengths.  Stop short when source is smaller than pattern
     const _D2 __len2 = __last2 - __first2;
     if (__len2 == 0)
-        return make_pair(__first1, __first1);
+        return _VSTD::make_pair(__first1, __first1);
     const _D1 __len1 = __last1 - __first1;
     if (__len1 < __len2)
-        return make_pair(__last1, __last1);
+        return _VSTD::make_pair(__last1, __last1);
     const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
 
     while (true)
@@ -3103,7 +3103,7 @@
         while (true)
         {
             if (__first1 == __s)
-                return make_pair(__last1, __last1);
+                return _VSTD::make_pair(__last1, __last1);
             if (__pred(*__first1, *__first2))
                 break;
             ++__first1;
@@ -3114,7 +3114,7 @@
          while (true)
          {
              if (++__m2 == __last2)
-                 return make_pair(__first1, __first1 + __len2);
+                 return _VSTD::make_pair(__first1, __first1 + __len2);
              ++__m1;          // no need to check range on __m1 because __s guarantees we have enough source
              if (!__pred(*__m1, *__m2))
              {
diff --git a/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp
index 5aaa832..cb1bd1c 100644
--- a/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp
+++ b/test/std/algorithms/alg.nonmodifying/alg.search/search.pass.cpp
@@ -56,6 +56,19 @@
     }
 };
 
+namespace User {
+struct S {
+    S(int x) : x(x) {}
+    int x;
+};
+bool operator==(S lhs, S rhs)
+{
+    return lhs.x == rhs.x;
+}
+template <class T, class U>
+void make_pair(T&&, U&&) = delete;
+} // namespace User
+
 template <class Iter1, class Iter2>
 void
 test()
@@ -95,6 +108,14 @@
     assert(std::search(Iter1(ij), Iter1(ij+sj), Iter2(ik), Iter2(ik+sk)) == Iter1(ij+6));
 }
 
+template <class Iter>
+void
+adl_test()
+{
+    User::S ua[] = {1};
+    assert(std::search(Iter(ua), Iter(ua), Iter(ua), Iter(ua)) == Iter(ua));
+}
+
 int main(int, char**)
 {
     test<forward_iterator<const int*>, forward_iterator<const int*> >();
@@ -107,6 +128,9 @@
     test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >();
     test<random_access_iterator<const int*>, random_access_iterator<const int*> >();
 
+    adl_test<forward_iterator<User::S*> >();
+    adl_test<random_access_iterator<User::S*> >();
+
 #if TEST_STD_VER > 14
 {
     typedef int * RI;