diff --git a/libcxx/include/__type_traits/conditional.h b/libcxx/include/__type_traits/conditional.h --- a/libcxx/include/__type_traits/conditional.h +++ b/libcxx/include/__type_traits/conditional.h @@ -26,6 +26,9 @@ template using conditional_t = typename conditional<_Bp, _If, _Then>::type; #endif +// Helper so we can use "conditional_t" in all language versions. +template using __conditional_t = typename conditional<_Bp, _If, _Then>::type; + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP___TYPE_TRAITS_CONDITIONAL_H diff --git a/libcxx/include/charconv b/libcxx/include/charconv --- a/libcxx/include/charconv +++ b/libcxx/include/charconv @@ -487,16 +487,21 @@ inline _LIBCPP_HIDE_FROM_ABI to_chars_result to_chars(char* __first, char* __last, _Tp __value) { - return __to_chars_itoa(__first, __last, __value, is_signed<_Tp>()); + using _Type = __make_32_64_or_128_bit_t<_Tp>; + static_assert(!is_same<_Type, void>::value, "unsupported integral type used in to_chars"); + static_assert(sizeof(_Tp) <= sizeof(int64_t), "128-bit integral support isn't available yet in to_chars"); + return std::__to_chars_itoa(__first, __last, static_cast<_Type>(__value), is_signed<_Tp>()); } template ::value, int>::type = 0> inline _LIBCPP_HIDE_FROM_ABI to_chars_result to_chars(char* __first, char* __last, _Tp __value, int __base) { - _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]"); - return __to_chars_integral(__first, __last, __value, __base, - is_signed<_Tp>()); + _LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]"); + + using _Type = __make_32_64_or_128_bit_t<_Tp>; + static_assert(sizeof(_Tp) <= sizeof(int64_t), "128-bit integral support isn't available yet in to_chars"); + return std::__to_chars_integral(__first, __last, static_cast<_Type>(__value), __base, is_signed<_Tp>()); } template diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -517,6 +517,7 @@ #include <__type_traits/void_t.h> #include <__utility/declval.h> #include +#include #include #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -1020,6 +1021,23 @@ } #endif +template +using __copy_unsigned_t = __conditional_t::value, typename make_unsigned<_Up>::type, _Up>; + +template +using __make_32_64_or_128_bit_t = + __copy_unsigned_t<_Tp, + __conditional_t +#else + /* else */ void +#endif + >> + >; + #if _LIBCPP_STD_VER > 17 // Let COND_RES(X, Y) be: template