Skip to content

[libc++] Fix set::operator= when instantiating with a std::pair #140385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libcxx/include/__tree
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading