From baf0dd4ca69d37bf86b466bfb92690701d12a0a4 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 12 Nov 2017 20:25:09 +0100 Subject: [PATCH] MB_CUR_MAX is not a constant --- ostd/format.hh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ostd/format.hh b/ostd/format.hh index fbd32f0..c9a5a80 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -233,6 +233,9 @@ namespace detail { template inline constexpr bool fmt_tofmt_test = decltype(test_tofmt(0))::value; + + /* any unicode character can be encoded in 6 bytes */ + constexpr std::size_t MaxMultibyte = 6; } /** @brief A structure implementing type safe C-style formatting. @@ -1015,7 +1018,7 @@ private: template void write_int(R &writer, bool ptr, bool neg, T val) const { /* binary representation is the biggest, assume grouping */ - char buf[sizeof(T) * CHAR_BIT * (MB_CUR_MAX + 1)]; + char buf[sizeof(T) * CHAR_BIT * (detail::MaxMultibyte + 1)]; std::size_t n = 0; char isp = spec(); @@ -1038,7 +1041,7 @@ private: /* this is bullshit */ auto const &fac = std::use_facet>(p_loc); auto const &grp = fac.grouping(); - char tseps[MB_CUR_MAX]; + char tseps[detail::MaxMultibyte]; int ntsep = wctomb(tseps, fac.thousands_sep()); auto grpp = reinterpret_cast(grp.data()); unsigned char grpn = *grpp; @@ -1440,7 +1443,7 @@ private: using difference_type = typename std::char_traits::off_type; fmt_out &operator=(wchar_t c) { - char buf[MB_CUR_MAX]; + char buf[detail::MaxMultibyte]; for (int i = 0, j = wctomb(buf, c); i < j; ++i) { p_out->put(buf[i]); }