[libcxx-commits] [PATCH] D112660: [libc++] Use addressof in forward_list.

Mark de Wever via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 27 13:29:42 PDT 2021


Mordante created this revision.
Mordante requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112660

Files:
  libcxx/include/forward_list
  libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.addressof.compile.pass.cpp


Index: libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.addressof.compile.pass.cpp
===================================================================
--- /dev/null
+++ libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.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
+//
+//===----------------------------------------------------------------------===//
+
+// <forward_list>
+
+// template <class Compare> void merge(forward_list&& x, Compare comp);
+
+// Validate whether the container can be copy-assigned with an ADL-hijacking operator&
+
+#include <forward_list>
+
+#include "test_macros.h"
+#include "operator_hijacker.h"
+
+void test() {
+  std::forward_list<operator_hijacker> l;
+  l.merge(l, std::less<operator_hijacker>());
+}
Index: libcxx/include/forward_list
===================================================================
--- libcxx/include/forward_list
+++ libcxx/include/forward_list
@@ -1585,7 +1585,7 @@
 void
 forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
 {
-    if (this != &__x)
+    if (this != _VSTD::addressof(__x))
     {
         base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
                                                     __x.__before_begin()->__next_,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112660.382769.patch
Type: text/x-patch
Size: 1581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211027/c5113123/attachment.bin>


More information about the libcxx-commits mailing list