diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -1587,7 +1587,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_, diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue.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(forward_list& x); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::forward_list lo; + std::forward_list l; + lo.merge(l); +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue_pred.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue_pred.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_lvalue_pred.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(forward_list& x, Compare comp); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::forward_list lo; + std::forward_list l; + lo.merge(l, std::less()); +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue.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 + +// + +// template void merge(forward_list&& x); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::forward_list lo; + std::forward_list l; + lo.merge(std::move(l)); +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue_pred.addressof.compile.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue_pred.addressof.compile.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_rvalue_pred.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 + +// + +// template void merge(forward_list&& x, Compare comp); + +// Validate whether the operation properly guards against ADL-hijacking operator& + +#include + +#include "test_macros.h" +#include "operator_hijacker.h" + +void test() { + std::forward_list lo; + std::forward_list l; + lo.merge(std::move(l), std::less()); +}