Skip to content

Commit f686770

Browse files
authored
[libc++] Fix set::operator= when instantiating with a std::pair (#140385)
This has been introduced by #134819, most likely due to a merge conflict I didn't resolve properly (I thought I did in that patch what I'm now doing here).
1 parent 962aa26 commit f686770

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

libcxx/include/__tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,7 @@ private:
12811281
}
12821282
_LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {}
12831283

1284-
template <class _From, __enable_if_t<__is_pair_v<__remove_cvref_t<_From> >, int> = 0>
1284+
template <class _From, class _ValueT = _Tp, __enable_if_t<__is_tree_value_type<_ValueT>::value, int> = 0>
12851285
_LIBCPP_HIDE_FROM_ABI static void __assign_value(__get_node_value_type_t<value_type>& __lhs, _From&& __rhs) {
12861286
using __key_type = typename _NodeTypes::key_type;
12871287

@@ -1291,7 +1291,7 @@ private:
12911291
__lhs.second = std::forward<_From>(__rhs).second;
12921292
}
12931293

1294-
template <class _To, class _From, class _ValueT = _Tp, __enable_if_t<!__is_pair_v<__remove_cvref_t<_From> >, int> = 0>
1294+
template <class _To, class _From, class _ValueT = _Tp, __enable_if_t<!__is_tree_value_type<_ValueT>::value, int> = 0>
12951295
_LIBCPP_HIDE_FROM_ABI static void __assign_value(_To& __lhs, _From&& __rhs) {
12961296
__lhs = std::forward<_From>(__rhs);
12971297
}

libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,15 @@ int main(int, char**) {
8080
assert(*std::next(mo.begin(), 2) == 3);
8181
}
8282

83+
{ // Test with std::pair, since we have some special handling for pairs inside __tree
84+
std::pair<int, int> arr[] = {
85+
std::make_pair(1, 2), std::make_pair(2, 3), std::make_pair(3, 4), std::make_pair(4, 5)};
86+
std::set<std::pair<int, int> > a(arr, arr + 4);
87+
std::set<std::pair<int, int> > b;
88+
89+
b = a;
90+
assert(a == b);
91+
}
92+
8393
return 0;
8494
}

0 commit comments

Comments
 (0)