[libcxx-commits] [libcxx] 4732dd3 - [libc++] Use addressof in list.

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 11 09:56:12 PST 2021


Author: Mark de Wever
Date: 2021-11-11T18:56:08+01:00
New Revision: 4732dd301086ce056d869eded4e1543fcb45506d

URL: https://github.com/llvm/llvm-project/commit/4732dd301086ce056d869eded4e1543fcb45506d
DIFF: https://github.com/llvm/llvm-project/commit/4732dd301086ce056d869eded4e1543fcb45506d.diff

LOG: [libc++] Use addressof in list.

This addresses the usage of `operator&` in `<list>`.

(Note there are still more headers with the same issue.)

Reviewed By: #libc, Quuxplusone, ldionne

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

Added: 
    libcxx/test/std/containers/sequences/list/list.cons/assign_move.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.modifiers/emplace.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.ops/merge_comp.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.addressof.compile.pass.cpp
    libcxx/test/std/containers/sequences/list/list.special/swap.addressof.compile.pass.cpp

Modified: 
    libcxx/include/list
    libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp
    libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/include/list b/libcxx/include/list
index cd526f12e2ffc..2d04b782673c3 100644
--- a/libcxx/include/list
+++ b/libcxx/include/list
@@ -470,9 +470,9 @@ public:
     _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 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
 #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 @@ typename list<_Tp, _Alloc>::iterator
 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 @@ typename list<_Tp, _Alloc>::iterator
 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 @@ typename list<_Tp, _Alloc>::iterator
 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 @@ typename list<_Tp, _Alloc>::iterator
 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 @@ typename list<_Tp, _Alloc>::iterator
 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 @@ template <class _Tp, class _Alloc>
 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 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
         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 @@ void
 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 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
         --__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 @@ void
 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 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
         __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 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
         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 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
 #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
index 0000000000000..a305587ca91f0
--- /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>
+
+// list& operator=(list&& c);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> lo;
+  std::list<operator_hijacker> 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
index 0000000000000..ac6a9d440d303
--- /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
+
+// <list>
+
+// template <class... Args> void emplace(const_iterator p, Args&&... args);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test(std::list<operator_hijacker>& 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
index 0000000000000..6e84d7059daab
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// iterator erase(const_iterator position);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> 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
index 0000000000000..90608ce7c2a6f
--- /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
+
+// <list>
+
+// iterator insert(const_iterator position, value_type&& x);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> 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
index 0000000000000..cd31a5f373f58
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// iterator insert(const_iterator position, size_type n, const value_type& x);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test(std::list<operator_hijacker>& 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
index 0000000000000..7a97cfebd6973
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// iterator insert(const_iterator position, const value_type& x);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test(std::list<operator_hijacker>& 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
index 08a5139f942b0..5faa3f34a3626 100644
--- 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 @@
 // <list>
 
 // void merge(list& x);
-// If (&addressof(x) == this) does nothing; otherwise ...
+// If (addressof(x) == this) does nothing; otherwise ...
 
 #include <list>
 #include <cassert>

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
index 0000000000000..042e252abe1c1
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// template <class Compare> void merge(list& x, Compare comp);
+// If (addressof(x) == this) does nothing; otherwise ...
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> l;
+  l.merge(l, std::less<operator_hijacker>());
+}

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
index 594e58643e7b7..3d4f8cc7fc2aa 100644
--- 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 @@
 // <list>
 
 // template <class Compare> void merge(list& x, Compare comp);
-// If (&addressof(x) == this) does nothing; otherwise ...
+// If (addressof(x) == this) does nothing; otherwise ...
 
 #include <list>
 #include <functional>

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
index 0000000000000..a6d69c497af10
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// void splice(const_iterator position, list<T,Allocator>& x, iterator i);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> 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
index 0000000000000..e79756580631b
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// void splice(const_iterator position, list& x, iterator first, iterator last);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> 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
index 0000000000000..0e15d1653d0c3
--- /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
+//
+//===----------------------------------------------------------------------===//
+
+// <list>
+
+// template <class T, class Alloc>
+//   void swap(list<T,Alloc>& x, list<T,Alloc>& y);
+
+// Validate whether the operation properly guards against ADL-hijacking operator&
+
+#include <list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::list<operator_hijacker> lo;
+  std::list<operator_hijacker> l;
+  swap(l, lo);
+}


        


More information about the libcxx-commits mailing list