From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id C6D863888C7F; Sun, 13 Nov 2022 01:14:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6D863888C7F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668302053; bh=xjwPyLrdAmL/zLBKKkVEFEgq8QKODB7TxLj5FEENB6g=; h=From:To:Subject:Date:From; b=YurhZ0TUMcTPqb0Ut0N+FQqdsGx0tL0wKiQqsDVfw2xh0JsCc/1vmo1C8x1Bh5Fep HFG2hDPl07QrC6+wlll8Dq/0dukizgLtB2X674F904BKT+DDXj7gS5Opp9rVUazXgQ zoQRI97BqkW+aCmoQpo4wYv4bg4CZswTosyyLZBI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-3935] libstdc++: Allow std::to_chars for 128-bit integers in strict mode X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 7ce0cee77adf33397d0ba61e7445effd8a5d8fcc X-Git-Newrev: d4ba3b369cbe9bce0a1212670825ecfb99762520 Message-Id: <20221113011413.C6D863888C7F@sourceware.org> Date: Sun, 13 Nov 2022 01:14:13 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d4ba3b369cbe9bce0a1212670825ecfb99762520 commit r13-3935-gd4ba3b369cbe9bce0a1212670825ecfb99762520 Author: Jonathan Wakely Date: Tue Nov 1 09:48:41 2022 +0000 libstdc++: Allow std::to_chars for 128-bit integers in strict mode This allows std::format to support __int128 when __STRICT_ANSI__ is defined, which previously failed because __int128 is not an integral type in strict mode. With these changes, std::to_chars still rejects 128-bit integers in strict mode, but std::format will be able to use __detail::__to_chars_i for unsigned __int128. libstdc++-v3/ChangeLog: * include/bits/charconv.h (__integer_to_chars_is_unsigned): New variable template. (__to_chars_len, __to_chars_10_impl): Use variable template in assertions to allow unsigned __int128 in strict mode. * include/std/charconv (__to_chars, __to_chars_16) (__to_chars_10, __to_chars_8, __to_chars_2): Likewise. Diff: --- libstdc++-v3/include/bits/charconv.h | 18 ++++++++++++++---- libstdc++-v3/include/std/charconv | 19 +++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/include/bits/charconv.h b/libstdc++-v3/include/bits/charconv.h index d04aab77624..103cfcb8177 100644 --- a/libstdc++-v3/include/bits/charconv.h +++ b/libstdc++-v3/include/bits/charconv.h @@ -35,19 +35,28 @@ #if __cplusplus >= 201103L #include +#include namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION namespace __detail { +#if __cpp_variable_templates + // This accepts 128-bit integers even in strict mode. + template + constexpr bool __integer_to_chars_is_unsigned + = ! __gnu_cxx::__int_traits<_Tp>::__is_signed; +#endif + // Generic implementation for arbitrary bases. template _GLIBCXX14_CONSTEXPR unsigned __to_chars_len(_Tp __value, int __base = 10) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); +#if __cpp_variable_templates + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); +#endif unsigned __n = 1; const unsigned __b2 = __base * __base; @@ -71,8 +80,9 @@ namespace __detail _GLIBCXX23_CONSTEXPR void __to_chars_10_impl(char* __first, unsigned __len, _Tp __val) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); +#if __cpp_variable_templates + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); +#endif constexpr char __digits[201] = "0001020304050607080910111213141516171819" diff --git a/libstdc++-v3/include/std/charconv b/libstdc++-v3/include/std/charconv index c5ed6fac73b..8f02395172f 100644 --- a/libstdc++-v3/include/std/charconv +++ b/libstdc++-v3/include/std/charconv @@ -88,6 +88,10 @@ namespace __detail using __integer_to_chars_result_type = enable_if_t<__or_<__is_signed_integer<_Tp>, __is_unsigned_integer<_Tp>, +#if defined __SIZEOF_INT128__ && defined __STRICT_ANSI__ + is_same<_Tp, signed __int128>, + is_same<_Tp, unsigned __int128>, +#endif is_same>>::value, to_chars_result>; @@ -126,8 +130,7 @@ namespace __detail constexpr to_chars_result __to_chars(char* __first, char* __last, _Tp __val, int __base) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); to_chars_result __res; @@ -167,8 +170,7 @@ namespace __detail constexpr __integer_to_chars_result_type<_Tp> __to_chars_16(char* __first, char* __last, _Tp __val) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); to_chars_result __res; @@ -214,8 +216,7 @@ namespace __detail constexpr __integer_to_chars_result_type<_Tp> __to_chars_10(char* __first, char* __last, _Tp __val) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); to_chars_result __res; @@ -238,8 +239,7 @@ namespace __detail constexpr __integer_to_chars_result_type<_Tp> __to_chars_8(char* __first, char* __last, _Tp __val) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); to_chars_result __res; unsigned __len; @@ -292,8 +292,7 @@ namespace __detail constexpr __integer_to_chars_result_type<_Tp> __to_chars_2(char* __first, char* __last, _Tp __val) noexcept { - static_assert(is_integral<_Tp>::value, "implementation bug"); - static_assert(is_unsigned<_Tp>::value, "implementation bug"); + static_assert(__integer_to_chars_is_unsigned<_Tp>, "implementation bug"); to_chars_result __res;