[libcxx-commits] [libcxx] 968e273 - [libc++] Use addressof to fix debug tests.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Oct 12 09:15:39 PDT 2021
Author: Mark de Wever
Date: 2021-10-12T18:15:35+02:00
New Revision: 968e27397caabafdad46a79dee5677f64bc8da89
URL: https://github.com/llvm/llvm-project/commit/968e27397caabafdad46a79dee5677f64bc8da89
DIFF: https://github.com/llvm/llvm-project/commit/968e27397caabafdad46a79dee5677f64bc8da89.diff
LOG: [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
Added:
Modified:
libcxx/include/__hash_table
libcxx/include/list
libcxx/include/unordered_map
libcxx/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index b7bd17436fb3f..126e1884a6644 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -298,7 +298,7 @@ public:
__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/libcxx/include/list b/libcxx/include/list
index b5b98af0654a0..80abe1c890aed 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -330,7 +330,7 @@ public:
__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 @@ public:
_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 @@ public:
: __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 @@ public:
__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 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
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 @@ typename list<_Tp, _Alloc>::iterator
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/libcxx/include/unordered_map b/libcxx/include/unordered_map
index c6cd5e1c52a50..417180a530e7c 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -1448,13 +1448,13 @@ public:
#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, ptr
diff _t __n) const
- {return __table_.__addable(&__i->__i_, __n);}
+ {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
bool __subscriptable(const const_iterator* __i, ptr
diff _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 @@ public:
#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, ptr
diff _t __n) const
- {return __table_.__addable(&__i->__i_, __n);}
+ {return __table_.__addable(_VSTD::addressof(__i->__i_), __n);}
bool __subscriptable(const const_iterator* __i, ptr
diff _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/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp
index f07e8cc69d737..4d183b16154db 100644
--- a/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.addressof.compile.pass.cpp
+++ b/libcxx/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/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp
index 49765c5f6345c..d0013594b1136 100644
--- a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/libcxx/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/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp
index 395c5d18ecac3..ddb3a5d187cab 100644
--- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/libcxx/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/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp
index baf9fd286ade6..e167c7ad4186d 100644
--- a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/libcxx/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/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp
index d7a09028c476d..de2784eeee672 100644
--- a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.addressof.compile.pass.cpp
+++ b/libcxx/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>,
More information about the libcxx-commits
mailing list