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));