Skip to content

[libc++] Fix std::pair's pair-like constructor's incorrect assumption #66585

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
Sep 18, 2023
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/__utility/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ struct _LIBCPP_TEMPLATE_VIS pair

# if _LIBCPP_STD_VER >= 23
// This is a workaround for http://llvm.org/PR60710. We should be able to remove it once Clang is fixed.
template <class _PairLike, bool _Enable = tuple_size<remove_cvref_t<_PairLike>>::value == 2>
template <class _PairLike>
_LIBCPP_HIDE_FROM_ABI static constexpr bool __pair_like_explicit_wknd() {
if constexpr (tuple_size<remove_cvref_t<_PairLike>>::value == 2) {
if constexpr (__pair_like<_PairLike>) {
return !is_convertible_v<decltype(std::get<0>(std::declval<_PairLike&&>())), first_type> ||
!is_convertible_v<decltype(std::get<1>(std::declval<_PairLike&&>())), second_type>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@
#include <type_traits>
#include <utility>

namespace my_ns{

struct MyPairLike {

template <std::size_t N>
friend int get(MyPairLike const&)
{
return 0;
}

};

} // namespace my_ns

namespace std {

template <>
struct tuple_size<my_ns::MyPairLike> : std::integral_constant<std::size_t, 2> {};

template <std::size_t N>
struct tuple_element<N, my_ns::MyPairLike> {
using type = int;
};

} // namespace std

// https://github.com/llvm/llvm-project/issues/65620
// This used to be a hard error
static_assert(!std::is_constructible_v<std::pair<int,int>, my_ns::MyPairLike const&>);


constexpr bool test() {
// Make sure construction works from array, tuple, and ranges::subrange
{
Expand Down