[libcxx-commits] [libcxx] [libc++] Fix set::operator= when instantiating with a std::pair (PR #140385)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sat May 17 13:32:28 PDT 2025
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/140385
>From 874669fd54e17d483ee5d27930a53e328ad79d55 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 17 May 2025 19:45:21 +0200
Subject: [PATCH] [libc++] Fix set::operator= when instantiating with a
std::pair
---
libcxx/include/__tree | 4 ++--
.../associative/set/set.cons/copy_assign.pass.cpp | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__tree b/libcxx/include/__tree
index 1903533898481..403cfe1ba4036 100644
--- a/libcxx/include/__tree
+++ b/libcxx/include/__tree
@@ -1281,7 +1281,7 @@ private:
}
_LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {}
- template <class _From, __enable_if_t<__is_pair_v<__remove_cvref_t<_From> >, int> = 0>
+ template <class _From, class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI static void __assign_value(__get_node_value_type_t<value_type>& __lhs, _From&& __rhs) {
using __key_type = typename _NodeTypes::key_type;
@@ -1291,7 +1291,7 @@ private:
__lhs.second = std::forward<_From>(__rhs).second;
}
- template <class _To, class _From, class _ValueT = _Tp, __enable_if_t<!__is_pair_v<__remove_cvref_t<_From> >, int> = 0>
+ template <class _To, class _From, class _ValueT = _Tp, __enable_if_t<!__is_tree_value_type<_ValueT>::value, int> = 0>
_LIBCPP_HIDE_FROM_ABI static void __assign_value(_To& __lhs, _From&& __rhs) {
__lhs = std::forward<_From>(__rhs);
}
diff --git a/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp
index e21e07734d888..f154f5d8b994c 100644
--- a/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp
+++ b/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp
@@ -80,5 +80,15 @@ int main(int, char**) {
assert(*std::next(mo.begin(), 2) == 3);
}
+ { // Test with std::pair, since we have some special handling for pairs inside __tree
+ std::pair<int, int> arr[] = {
+ std::make_pair(1, 2), std::make_pair(2, 3), std::make_pair(3, 4), std::make_pair(4, 5)};
+ std::set<std::pair<int, int> > a(arr, arr + 4);
+ std::set<std::pair<int, int> > b;
+
+ b = a;
+ assert(a == b);
+ }
+
return 0;
}
More information about the libcxx-commits
mailing list