diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -470,9 +470,9 @@ _LIBCPP_INLINE_VISIBILITY __list_const_iterator& operator=(const __list_const_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; @@ -797,7 +797,7 @@ #if _LIBCPP_DEBUG_LEVEL == 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); + __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); _VSTD::swap(__cn1->beg_, __cn2->beg_); _VSTD::swap(__cn1->end_, __cn2->end_); _VSTD::swap(__cn1->cap_, __cn2->cap_); @@ -1451,7 +1451,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) { #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, x) called with an iterator not" " referring to this list"); #endif @@ -1472,7 +1472,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) { #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, n, x) called with an iterator not" " referring to this list"); iterator __r(__p.__ptr_, this); @@ -1697,7 +1697,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) { #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::emplace(iterator, args...) called with an iterator not" " referring to this list"); #endif @@ -1720,7 +1720,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) { #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, x) called with an iterator not" " referring to this list"); #endif @@ -1803,7 +1803,7 @@ list<_Tp, _Alloc>::erase(const_iterator __p) { #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::erase(iterator) called with an iterator not" " referring to this list"); #endif @@ -2006,10 +2006,10 @@ void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) { - _LIBCPP_ASSERT(this != &__c, + _LIBCPP_ASSERT(this != _VSTD::addressof(__c), "list::splice(iterator, list) called with this == &list"); #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::splice(iterator, list) called with an iterator not" " referring to this list"); #endif @@ -2022,10 +2022,10 @@ base::__sz() += __c.__sz(); __c.__sz() = 0; #if _LIBCPP_DEBUG_LEVEL == 2 - if (&__c != this) { + if (_VSTD::addressof(__c) != this) { __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); + __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { --__ip; @@ -2049,13 +2049,13 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) { #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::splice(iterator, list, iterator) called with the first iterator" " not referring to this list"); - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c, + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__i)) == _VSTD::addressof(__c), "list::splice(iterator, list, iterator) called with the second iterator" " not referring to the list argument"); - _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i), + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(_VSTD::addressof(__i)), "list::splice(iterator, list, iterator) called with the second iterator" " not dereferenceable"); #endif @@ -2067,10 +2067,10 @@ --__c.__sz(); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL == 2 - if (&__c != this) { + if (_VSTD::addressof(__c) != this) { __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); + __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { --__ip; @@ -2094,16 +2094,16 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) { #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::splice(iterator, list, iterator, iterator) called with first iterator not" " referring to this list"); - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c, + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__f)) == _VSTD::addressof(__c), "list::splice(iterator, list, iterator, iterator) called with second iterator not" " referring to the list argument"); - _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == &__c, + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(_VSTD::addressof(__l)) == _VSTD::addressof(__c), "list::splice(iterator, list, iterator, iterator) called with third iterator not" " referring to the list argument"); - if (this == &__c) + if (this == _VSTD::addressof(__c)) { for (const_iterator __i = __f; __i != __l; ++__i) _LIBCPP_ASSERT(__i != __p, @@ -2117,7 +2117,7 @@ __link_pointer __first = __f.__ptr_; --__l; __link_pointer __last = __l.__ptr_; - if (this != &__c) + if (this != _VSTD::addressof(__c)) { size_type __s = _VSTD::distance(__f, __l) + 1; __c.__sz() -= __s; @@ -2126,10 +2126,10 @@ base::__unlink_nodes(__first, __last); __link_nodes(__p.__ptr_, __first, __last); #if _LIBCPP_DEBUG_LEVEL == 2 - if (&__c != this) { + if (_VSTD::addressof(__c) != this) { __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); + __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;) { --__ip; @@ -2265,7 +2265,7 @@ #if _LIBCPP_DEBUG_LEVEL == 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); - __c_node* __cn2 = __db->__find_c(&__c); + __c_node* __cn2 = __db->__find_c(_VSTD::addressof(__c)); for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) { --__p; diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_move.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_move.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_move.addressof.compile.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// list& operator=(list&& c); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list lo; + std::list l; + l = std::move(lo); +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.addressof.compile.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// template void emplace(const_iterator p, Args&&... args); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test(std::list& l) { l.emplace(l.begin(), l.front()); } diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.addressof.compile.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase(const_iterator position); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list l; + l.erase(l.begin()); +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// iterator insert(const_iterator position, value_type&& x); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list l; + l.insert(l.begin(), operator_hijacker{}); +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.addressof.compile.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test(std::list& l) { l.insert(l.begin(), l.size(), l.front()); } diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.addressof.compile.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, const value_type& x); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test(std::list& l) { l.insert(l.begin(), l.front()); } diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp --- a/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp @@ -9,7 +9,7 @@ // // void merge(list& x); -// If (&addressof(x) == this) does nothing; otherwise ... +// If (addressof(x) == this) does nothing; otherwise ... #include #include diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.addressof.compile.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// template void merge(list& x, Compare comp); +// If (addressof(x) == this) does nothing; otherwise ... + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list l; + l.merge(l, std::less()); +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp --- a/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp @@ -9,7 +9,7 @@ // // template void merge(list& x, Compare comp); -// If (&addressof(x) == this) does nothing; otherwise ... +// If (addressof(x) == this) does nothing; otherwise ... #include #include diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.addressof.compile.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// void splice(const_iterator position, list& x, iterator i); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list l; + l.splice(l.end(), l, l.begin()); +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.addressof.compile.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// void splice(const_iterator position, list& x, iterator first, iterator last); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list l; + l.splice(l.end(), l, l.begin(), l.end()); +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/swap.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/swap.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/swap.addressof.compile.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(list& x, list& y); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::list lo; + std::list l; + swap(l, lo); +}