From 312f1133f46d8a426090d071237edc6cc103d5d1 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Sun, 2 Dec 2018 07:50:14 +0100 Subject: [PATCH] change signature of 'grisu2_prettify' (#955) grisu2_prettify(..,ptrdiff_t,..,..) -> grisu2_prettify(..,size_t,..,..) because the second parameter is called only with arguments of types 'unsigned int' or 'size_t'. This squashes compiler warnings when compiled for 32 bit targets where 'size_t' may have the same size as 'int' and different implicit conversion/promotion rules apply. While at it, remove an obsolete warning suppression. --- include/fmt/format-inl.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 71f0840b..60418a80 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -48,9 +48,6 @@ # pragma warning(push) # pragma warning(disable: 4127) // conditional expression is constant # pragma warning(disable: 4702) // unreachable code -// Disable deprecation warning for strerror. The latter is not called but -// MSVC fails to detect it. -# pragma warning(disable: 4996) #endif // Dummy implementations of strerror_r and strerror_s called if corresponding @@ -617,11 +614,12 @@ struct fill { // The number is given as v = f * pow(10, exp), where f has size digits. template FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms, - ptrdiff_t size, int exp, Handler &&handler) { - if (!params.fixed) { + size_t size, int exp, Handler &&handler) { + const int int_size = static_cast(size); + if (!params.fixed) { // Insert a decimal point after the first digit and add an exponent. handler.insert(1, '.'); - exp += static_cast(size) - 1; + exp += int_size - 1; if (size < params.num_digits) handler.append(params.num_digits - size, '0'); handler.append(params.upper ? 'E' : 'e'); @@ -629,8 +627,7 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms, return; } // pow(10, full_exp - 1) <= v <= pow(10, full_exp). - int int_size = static_cast(size); - int full_exp = int_size + exp; + const int full_exp = int_size + exp; const int exp_threshold = 21; if (int_size <= full_exp && full_exp <= exp_threshold) { // 1234e7 -> 12340000000[.0+]