From 566061d1f1658321a116690350d48995bf254c14 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 6 Aug 2014 08:21:12 -0700 Subject: [PATCH] Fix formatting of signed ints in test. --- test/printf-test.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/printf-test.cc b/test/printf-test.cc index aa8def9a..0de77265 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -282,12 +282,27 @@ bool IsSupported(const std::string &format) { #endif } +template +struct MakeSigned { typedef T Type; }; + +#define SPECIALIZE_MAKE_SIGNED(T, S) \ + template <> \ + struct MakeSigned { typedef S Type; } + +SPECIALIZE_MAKE_SIGNED(char, signed char); +SPECIALIZE_MAKE_SIGNED(unsigned char, signed char); +SPECIALIZE_MAKE_SIGNED(unsigned short, short); +SPECIALIZE_MAKE_SIGNED(unsigned, int); +SPECIALIZE_MAKE_SIGNED(unsigned long, long); +SPECIALIZE_MAKE_SIGNED(fmt::ULongLong, fmt::LongLong); + template std::string sprintf_int(std::string format, U value) { char buffer[BUFFER_SIZE]; char type = format[format.size() - 1]; if (type == 'd' || type == 'i') { - safe_sprintf(buffer, format.c_str(), static_cast(value)); + typedef typename MakeSigned::Type Signed; + safe_sprintf(buffer, format.c_str(), static_cast(value)); } else { typedef typename fmt::internal::MakeUnsigned::Type Unsigned; safe_sprintf(buffer, format.c_str(), static_cast(value));