Add a comment to clarify why convert to unsigned

This commit is contained in:
vitaut 2016-01-26 07:13:34 -08:00
parent bb7a80b1ab
commit ae6368c985

View File

@ -328,6 +328,9 @@ class ArgConverter : public fmt::internal::ArgVisitor<ArgConverter<T>, void> {
} else { } else {
if (is_signed) { if (is_signed) {
arg_.type = Arg::LONG_LONG; arg_.type = Arg::LONG_LONG;
// Convert value to unsigned type before converting to long long for
// consistency with glibc's printf even though in general it's UB:
// std::printf("%lld", -42); // prints "4294967254"
arg_.long_long_value = arg_.long_long_value =
static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value); static_cast<typename fmt::internal::MakeUnsigned<U>::Type>(value);
} else { } else {