[libc++] Use addressof to fix debug tests.

Fixes the tests added in D110852 for the debug iterators.

Similar issues with hijacking `operator&` still exist, they will be
addressed separately.

Reviewed By: #libc, ldionne, Quuxplusone

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

GitOrigin-RevId: 968e27397caabafdad46a79dee5677f64bc8da89
diff --git a/include/__hash_table b/include/__hash_table
index b7bd174..126e188 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -298,7 +298,7 @@
     __hash_iterator(const __hash_iterator& __i)
         : __node_(__i.__node_)
     {
-        __get_db()->__iterator_copy(this, &__i);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
     }
 
     _LIBCPP_INLINE_VISIBILITY
diff --git a/include/list b/include/list
index b5b98af..80abe1c 100644
--- a/include/list
+++ b/include/list
@@ -330,7 +330,7 @@
     __list_iterator(const __list_iterator& __p)
         : __ptr_(__p.__ptr_)
     {
-        __get_db()->__iterator_copy(this, &__p);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -342,9 +342,9 @@
     _LIBCPP_INLINE_VISIBILITY
     __list_iterator& operator=(const __list_iterator& __p)
     {
-        if (this != &__p)
+        if (this != _VSTD::addressof(__p))
         {
-            __get_db()->__iterator_copy(this, &__p);
+            __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
             __ptr_ = __p.__ptr_;
         }
         return *this;
@@ -448,7 +448,7 @@
         : __ptr_(__p.__ptr_)
     {
 #if _LIBCPP_DEBUG_LEVEL == 2
-        __get_db()->__iterator_copy(this, &__p);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
 #endif
     }
 
@@ -458,7 +458,7 @@
     __list_const_iterator(const __list_const_iterator& __p)
         : __ptr_(__p.__ptr_)
     {
-        __get_db()->__iterator_copy(this, &__p);
+        __get_db()->__iterator_copy(this, _VSTD::addressof(__p));
     }
 
     _LIBCPP_INLINE_VISIBILITY
@@ -1536,7 +1536,7 @@
              typename enable_if<__is_cpp17_input_iterator<_InpIter>::value>::type*)
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
         "list::insert(iterator, range) called with an iterator not"
         " referring to this list");
     iterator __r(__p.__ptr_, this);
@@ -1842,10 +1842,10 @@
 list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
 {
 #if _LIBCPP_DEBUG_LEVEL == 2
-    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
+    _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == this,
         "list::erase(iterator, iterator) called with an iterator not"
         " referring to this list");
-   _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
+   _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == this,
         "list::erase(iterator, iterator) called with an iterator not"
         " referring to this list");
 #endif
diff --git a/include/unordered_map b/include/unordered_map
index c6cd5e1..417180a 100644
--- a/include/unordered_map
+++ b/include/unordered_map
@@ -1448,13 +1448,13 @@
 #if _LIBCPP_DEBUG_LEVEL == 2
 
     bool __dereferenceable(const const_iterator* __i) const
-        {return __table_.__dereferenceable(&__i->__i_);}
+        {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
     bool __decrementable(const const_iterator* __i) const
-        {return __table_.__decrementable(&__i->__i_);}
+        {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
     bool __addable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
     bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 
@@ -2250,13 +2250,13 @@
 #if _LIBCPP_DEBUG_LEVEL == 2
 
     bool __dereferenceable(const const_iterator* __i) const
-        {return __table_.__dereferenceable(&__i->__i_);}
+        {return __table_.__dereferenceable(_VSTD::addressof(__i->__i_));}
     bool __decrementable(const const_iterator* __i) const
-        {return __table_.__decrementable(&__i->__i_);}
+        {return __table_.__decrementable(_VSTD::addressof(__i->__i_));}
     bool __addable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
     bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
-        {return __table_.__addable(&__i->__i_, __n);}
+        {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
 
 #endif // _LIBCPP_DEBUG_LEVEL == 2
 
diff --git a/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp b/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp
index f07e8cc..4d183b1 100644
--- a/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp
+++ b/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// Guard the debug iterators against ADL-hijacking.
-// XFAIL: LIBCXX-DEBUG-FIXME
-
 // <list>
 
 // list& operator=(const list& c);
diff --git a/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp b/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp
index 49765c5..d001359 100644
--- a/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// Guard the debug iterators against ADL-hijacking.
-// XFAIL: LIBCXX-DEBUG-FIXME
-
 // <unordered_map>
 
 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
diff --git a/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp b/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp
index 395c5d1..ddb3a5d 100644
--- a/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// Guard the debug iterators against ADL-hijacking.
-// XFAIL: LIBCXX-DEBUG-FIXME
-
 // <unordered_map>
 
 // template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
diff --git a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp
index baf9fd2..e167c7a 100644
--- a/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// Guard the debug iterators against ADL-hijacking.
-// XFAIL: LIBCXX-DEBUG-FIXME
-
 // <unordered_set>
 
 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
diff --git a/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp b/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp
index d7a0902..de2784e 100644
--- a/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp
@@ -6,9 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-// Guard the debug iterators against ADL-hijacking.
-// XFAIL: LIBCXX-DEBUG-FIXME
-
 // <unordered_set>
 
 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,