[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
This commit is contained in:
Mark de Wever 2021-11-07 19:44:59 +01:00
parent f24fe96f46
commit cab9616938
17 changed files with 527 additions and 30 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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>();
}
}

View File

@ -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);
}
}

View File

@ -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));
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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());
}

View File

@ -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);
}

View File

@ -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()); }

View File

@ -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>{});
}

View File

@ -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));
}
}

View File

@ -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);
}

View File

@ -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));
}

View File

@ -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());
}

View File

@ -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());
}