[libcxx-commits] [libcxx] d6e2c95 - [libc++] Use addressof in unordered_map.
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jan 21 11:43:51 PST 2022
Author: Mark de Wever
Date: 2022-01-21T20:43:45+01:00
New Revision: d6e2c95d2252f479d5bc7a74df70f90eba94b34d
URL: https://github.com/llvm/llvm-project/commit/d6e2c95d2252f479d5bc7a74df70f90eba94b34d
DIFF: https://github.com/llvm/llvm-project/commit/d6e2c95d2252f479d5bc7a74df70f90eba94b34d.diff
LOG: [libc++] Use addressof in unordered_map.
This addresses the usage of `operator&` in `<unordered_map>`.
(Note there are still more headers with the same issue.)
Reviewed By: #libc, Quuxplusone, ldionne
Differential Revision: https://reviews.llvm.org/D117393
Added:
libcxx/test/std/containers/unord/unord.map/iterator.operators.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_constructible_value_type.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_value_type.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/try_emplace_hint.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.addressof.compile.pass.cpp
libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.addressof.compile.pass.cpp
Modified:
libcxx/include/__hash_table
libcxx/include/unordered_map
Removed:
################################################################################
diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
index 6b682ab27c6c..adc732cffb01 100644
--- a/libcxx/include/__hash_table
+++ b/libcxx/include/__hash_table
@@ -308,9 +308,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
__hash_iterator& operator=(const __hash_iterator& __i)
{
- if (this != &__i)
+ if (this != _VSTD::addressof(__i))
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
__node_ = __i.__node_;
}
return *this;
@@ -406,7 +406,7 @@ public:
: __node_(__x.__node_)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->__iterator_copy(this, &__x);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
#endif
}
@@ -415,7 +415,7 @@ public:
__hash_const_iterator(const __hash_const_iterator& __i)
: __node_(__i.__node_)
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
}
_LIBCPP_INLINE_VISIBILITY
@@ -427,9 +427,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator& operator=(const __hash_const_iterator& __i)
{
- if (this != &__i)
+ if (this != _VSTD::addressof(__i))
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
__node_ = __i.__node_;
}
return *this;
@@ -523,7 +523,7 @@ public:
__bucket_(__i.__bucket_),
__bucket_count_(__i.__bucket_count_)
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
}
_LIBCPP_INLINE_VISIBILITY
@@ -535,9 +535,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator& operator=(const __hash_local_iterator& __i)
{
- if (this != &__i)
+ if (this != _VSTD::addressof(__i))
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
__node_ = __i.__node_;
__bucket_ = __i.__bucket_;
__bucket_count_ = __i.__bucket_count_;
@@ -655,7 +655,7 @@ public:
__bucket_count_(__x.__bucket_count_)
{
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->__iterator_copy(this, &__x);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__x));
#endif
}
@@ -666,7 +666,7 @@ public:
__bucket_(__i.__bucket_),
__bucket_count_(__i.__bucket_count_)
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
}
_LIBCPP_INLINE_VISIBILITY
@@ -678,9 +678,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
{
- if (this != &__i)
+ if (this != _VSTD::addressof(__i))
{
- __get_db()->__iterator_copy(this, &__i);
+ __get_db()->__iterator_copy(this, _VSTD::addressof(__i));
__node_ = __i.__node_;
__bucket_ = __i.__bucket_;
__bucket_count_ = __i.__bucket_count_;
@@ -1615,7 +1615,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
__u.size() = 0;
}
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__u);
+ __get_db()->swap(this, _VSTD::addressof(__u));
#endif
}
@@ -2021,7 +2021,7 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
const_iterator __p, __node_pointer __cp)
{
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered container");
if (__p != end() && key_eq()(*__p, __cp->__value_))
@@ -2148,7 +2148,7 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
const_iterator __p, _Args&&... __args)
{
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered container");
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
@@ -2472,7 +2472,7 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
{
__next_pointer __np = __p.__node_;
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered container erase(iterator) called with an iterator not"
" referring to this container");
_LIBCPP_DEBUG_ASSERT(__p != end(),
@@ -2492,10 +2492,10 @@ typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
const_iterator __last)
{
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__first)) == this,
"unordered container::erase(iterator, iterator) called with an iterator not"
" referring to this container");
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__last)) == this,
"unordered container::erase(iterator, iterator) called with an iterator not"
" referring to this container");
for (const_iterator __p = __first; __first != __last; __p = __first)
@@ -2727,7 +2727,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
__u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
__u.__p1_.first().__ptr();
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__u);
+ __get_db()->swap(this, _VSTD::addressof(__u));
#endif
}
diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map
index 73edadab2099..361db707d246 100644
--- a/libcxx/include/unordered_map
+++ b/libcxx/include/unordered_map
@@ -519,6 +519,7 @@ template <class Key, class T, class Hash, class Pred, class Alloc>
#include <__functional/is_transparent.h>
#include <__hash_table>
#include <__iterator/iterator_traits.h>
+#include <__memory/addressof.h>
#include <__node_handle>
#include <__utility/forward.h>
#include <compare>
@@ -1186,7 +1187,7 @@ public:
{return __table_.__insert_unique(__x);}
iterator insert(const_iterator __p, const value_type& __x) {
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered_map::insert(const_iterator, const value_type&) called with an iterator not "
"referring to this unordered_map");
((void)__p);
@@ -1207,7 +1208,7 @@ public:
{return __table_.__insert_unique(_VSTD::move(__x));}
iterator insert(const_iterator __p, value_type&& __x) {
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
" referring to this unordered_map");
((void)__p);
@@ -1225,7 +1226,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, _Pp&& __x)
{
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
" referring to this unordered_map");
((void)__p);
@@ -1241,7 +1242,7 @@ public:
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace_hint(const_iterator __p, _Args&&... __args) {
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__p)) == this,
"unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered_map");
((void)__p);
@@ -1273,7 +1274,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
{
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__h)) == this,
"unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
" referring to this unordered_map");
((void)__h);
@@ -1284,7 +1285,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
{
- _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
+ _LIBCPP_DEBUG_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__h)) == this,
"unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
" referring to this unordered_map");
((void)__h);
@@ -1692,7 +1693,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__u);
+ __get_db()->swap(this, _VSTD::addressof(__u));
#endif
}
@@ -1712,7 +1713,7 @@ unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
}
#if _LIBCPP_DEBUG_LEVEL == 2
else
- __get_db()->swap(this, &__u);
+ __get_db()->swap(this, _VSTD::addressof(__u));
#endif
}
@@ -2468,7 +2469,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
{
_VSTD::__debug_db_insert_c(this);
#if _LIBCPP_DEBUG_LEVEL == 2
- __get_db()->swap(this, &__u);
+ __get_db()->swap(this, _VSTD::addressof(__u));
#endif
}
@@ -2489,7 +2490,7 @@ unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
}
#if _LIBCPP_DEBUG_LEVEL == 2
else
- __get_db()->swap(this, &__u);
+ __get_db()->swap(this, _VSTD::addressof(__u));
#endif
}
diff --git a/libcxx/test/std/containers/unord/unord.map/iterator.operators.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/iterator.operators.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..856b78293a10
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/iterator.operators.addressof.compile.pass.cpp
@@ -0,0 +1,49 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// Validate the constructors of the (const)(_local)_iterator classes to be
+// properly guarded against ADL-hijacking operator&.
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+template <class ToIterator, class FromIterator>
+void test() {
+ FromIterator from;
+ ToIterator copy(from);
+ copy = from;
+
+ ToIterator move(std::move(from));
+ from = FromIterator();
+ move = std::move(from);
+}
+
+void test() {
+ {
+ using I = std::unordered_map<operator_hijacker, operator_hijacker>::iterator;
+ using CI = std::unordered_map<operator_hijacker, operator_hijacker>::const_iterator;
+ test<I, I>();
+ test<CI, I>();
+ test<CI, CI>();
+ }
+ {
+ using IL = std::unordered_map<operator_hijacker, operator_hijacker>::local_iterator;
+ using CIL = std::unordered_map<operator_hijacker, operator_hijacker>::const_local_iterator;
+ test<IL, IL>();
+ test<CIL, IL>();
+ test<CIL, CIL>();
+ }
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..6dbd7aaea2a8
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.addressof.compile.pass.cpp
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// unordered_map& operator=(unordered_map&&)
+// noexcept(
+// allocator_type::propagate_on_container_move_assignment::value &&
+// is_nothrow_move_assignable<allocator_type>::value &&
+// is_nothrow_move_assignable<hasher>::value &&
+// is_nothrow_move_assignable<key_equal>::value);
+
+// Validate whether the container can be move-assigned with an ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ {
+ std::unordered_map<int, operator_hijacker> mo;
+ std::unordered_map<int, operator_hijacker> m;
+ m = std::move(mo);
+ }
+ {
+ std::unordered_map<operator_hijacker, int> mo;
+ std::unordered_map<operator_hijacker, int> m;
+ m = std::move(mo);
+ }
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..e36c6525d631
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.addressof.compile.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// unordered_map(unordered_map&& u)
+// noexcept(
+// is_nothrow_move_constructible<hasher>::value &&
+// is_nothrow_move_constructible<key_equal>::value &&
+// is_nothrow_move_constructible<allocator_type>::value);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> mo;
+ std::unordered_map<operator_hijacker, operator_hijacker> m(std::move(mo));
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..1fec0ee5d0f4
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.addressof.compile.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// unordered_map(unordered_map&& u, const allocator_type& a);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+#include "test_allocator.h"
+#include "min_allocator.h"
+
+void test() {
+ using A = test_allocator<std::pair<const operator_hijacker, operator_hijacker>>;
+ using C = std::unordered_map<operator_hijacker, operator_hijacker, std::hash<operator_hijacker>,
+ std::equal_to<operator_hijacker>, A>;
+
+ C mo;
+ C m(std::move(mo), A());
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..58ddefd8cfbf
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/emplace_hint.addressof.compile.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// template <class... Args>
+// iterator emplace_hint(const_iterator position, Args&&... args);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> m;
+ m.emplace_hint(m.cbegin());
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..1461f2499baa
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_const_iter.addressof.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// iterator erase(const_iterator p)
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> m;
+ m.erase(m.cbegin());
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..5f342f7b2152
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/erase_range.addressof.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// iterator erase(const_iterator first, const_iterator last)
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> m;
+ m.erase(m.cbegin(), m.cend());
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..db1805e7d7e6
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_hint_const_lvalue.addressof.compile.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// iterator insert(const_iterator p, const value_type& x);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> m;
+ const std::pair<operator_hijacker, operator_hijacker> v;
+ m.insert(m.cend(), v);
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_constructible_value_type.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_constructible_value_type.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..530b826b61e7
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_constructible_value_type.addressof.compile.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// template <class P,
+// class = typename enable_if<is_convertible<P, value_type>::value>::type>
+// pair<iterator, bool> insert(P&& x);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test(std::unordered_map<operator_hijacker, operator_hijacker>& m) { m.insert(m.cend(), *m.begin()); }
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_value_type.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_value_type.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..80219cb193ed
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/insert_rvalue_value_type.addressof.compile.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// iterator insert(const_iterator hint, value_type&& obj);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test(std::unordered_map<operator_hijacker, operator_hijacker>& m) {
+ m.insert(m.cend(), std::pair<operator_hijacker, operator_hijacker>{});
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/try_emplace_hint.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/try_emplace_hint.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..2c667374d4fe
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.modifiers/try_emplace_hint.addressof.compile.pass.cpp
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_map
+
+// template <class... Args>
+// iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);
+// template <class... Args>
+// iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);
+// template <class M>
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> m;
+ {
+ const operator_hijacker k;
+ m.try_emplace(m.cend(), k);
+ }
+ {
+ operator_hijacker k;
+ m.try_emplace(m.cend(), std::move(k));
+ }
+}
diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..f5b5f516d42b
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap.addressof.compile.pass.cpp
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// void swap(unordered_map& c)
+// noexcept(allocator_traits<Allocator>::is_always_equal::value &&
+// noexcept(swap(declval<Hash&>(), declval<Hash&>())) &&
+// noexcept(swap(declval<Pred&>(), declval<Pred&>())));
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_map<operator_hijacker, operator_hijacker> m1;
+ std::unordered_map<operator_hijacker, operator_hijacker> m2;
+ std::swap(m1, m2);
+}
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..73b19f35e204
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.addressof.compile.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_multimap
+
+// unordered_multimap(unordered_multimap&&)
+// noexcept(
+// is_nothrow_move_constructible<hasher>::value &&
+// is_nothrow_move_constructible<key_equal>::value &&
+// is_nothrow_move_constructible<allocator_type>::value);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_multimap<operator_hijacker, operator_hijacker> mo;
+ std::unordered_multimap<operator_hijacker, operator_hijacker> m(std::move(mo));
+}
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..6419a03666d6
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.addressof.compile.pass.cpp
@@ -0,0 +1,36 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_multimap
+
+// unordered_multimap(unordered_map&& u, const allocator_type& a);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+#include "test_allocator.h"
+#include "min_allocator.h"
+
+void test() {
+ using A = test_allocator<std::pair<const operator_hijacker, operator_hijacker>>;
+ using C = std::unordered_multimap<operator_hijacker, operator_hijacker, std::hash<operator_hijacker>,
+ std::equal_to<operator_hijacker>, A>;
+
+ C mo;
+ C m(std::move(mo), A());
+}
diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.addressof.compile.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.addressof.compile.pass.cpp
new file mode 100644
index 000000000000..5e23b73cf34b
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.addressof.compile.pass.cpp
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// <unordered_map>
+
+// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
+// class Alloc = allocator<pair<const Key, T>>>
+// class unordered_multimap
+
+// template <class... Args>
+// iterator emplace_hint(const_iterator position, Args&&... args);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <unordered_map>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+ std::unordered_multimap<operator_hijacker, operator_hijacker> m;
+ m.emplace_hint(m.cbegin());
+}
More information about the libcxx-commits
mailing list