@@ -198,6 +198,23 @@ struct is_contiguous<std::basic_string<Char, Traits, Allocator>>
198198
199199namespace detail {
200200
201+ #ifdef FMT_USE_BITINT
202+ // Use the provided definition.
203+ #elif FMT_CLANG_VERSION >= 1500 && !defined(__CUDACC__)
204+ # define FMT_USE_BITINT 1
205+ #else
206+ # define FMT_USE_BITINT 0
207+ #endif
208+
209+ #if FMT_USE_BITINT
210+ FMT_PRAGMA_CLANG (diagnostic ignored " -Wbit-int-extension" )
211+ template <int N> using bitint = _BitInt(N);
212+ template <int N> using ubitint = unsigned _BitInt (N);
213+ #else
214+ template <int N> struct bitint {};
215+ template <int N> struct ubitint {};
216+ #endif // FMT_USE_BITINT
217+
201218// __builtin_clz is broken in clang with Microsoft codegen:
202219// https://github.com/fmtlib/fmt/issues/519.
203220#if !FMT_MSC_VERSION
@@ -4039,9 +4056,28 @@ class formatter<std::basic_string<Char, Traits, Allocator>, Char>
40394056 : public formatter<basic_string_view<Char>, Char> {};
40404057
40414058template <int N, typename Char>
4042- struct formatter <detail::bitint<N>, Char> : formatter<long long , Char> {};
4059+ struct formatter <detail::bitint<N>, Char> : formatter<long long , Char> {
4060+ static_assert (N <= 64 , " unsupported _BitInt" );
4061+ static auto format_as (detail::bitint<N> x) -> long long {
4062+ return static_cast <long long >(x);
4063+ }
4064+ template <typename Context>
4065+ auto format (detail::bitint<N> x, Context& ctx) const -> decltype(ctx.out()) {
4066+ return formatter<long long , Char>::format (format_as (x), ctx);
4067+ }
4068+ };
4069+
40434070template <int N, typename Char>
4044- struct formatter <detail::ubitint<N>, Char> : formatter<ullong, Char> {};
4071+ struct formatter <detail::ubitint<N>, Char> : formatter<ullong, Char> {
4072+ static_assert (N <= 64 , " unsupported _BitInt" );
4073+ static auto format_as (detail::ubitint<N> x) -> ullong {
4074+ return static_cast <ullong>(x);
4075+ }
4076+ template <typename Context>
4077+ auto format (detail::ubitint<N> x, Context& ctx) const -> decltype(ctx.out()) {
4078+ return formatter<ullong, Char>::format (format_as (x), ctx);
4079+ }
4080+ };
40454081
40464082template <typename Char>
40474083struct formatter <detail::float128, Char>
0 commit comments