diff --git a/libcxx/include/__utility/pair.h b/libcxx/include/__utility/pair.h index 85d2f21af2420..62dac6dd1da3f 100644 --- a/libcxx/include/__utility/pair.h +++ b/libcxx/include/__utility/pair.h @@ -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 >::value == 2> + template _LIBCPP_HIDE_FROM_ABI static constexpr bool __pair_like_explicit_wknd() { - if constexpr (tuple_size>::value == 2) { + if constexpr (__pair_like<_PairLike>) { return !is_convertible_v(std::declval<_PairLike&&>())), first_type> || !is_convertible_v(std::declval<_PairLike&&>())), second_type>; } diff --git a/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_like.pass.cpp b/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_like.pass.cpp index 3362a872a5857..b93adb0ef3ebc 100644 --- a/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_like.pass.cpp +++ b/libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_like.pass.cpp @@ -23,6 +23,37 @@ #include #include +namespace my_ns{ + +struct MyPairLike { + +template +friend int get(MyPairLike const&) +{ + return 0; +} + +}; + +} // namespace my_ns + +namespace std { + +template <> +struct tuple_size : std::integral_constant {}; + +template +struct tuple_element { + 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, my_ns::MyPairLike const&>); + + constexpr bool test() { // Make sure construction works from array, tuple, and ranges::subrange {