From 07ed4215212324145bee94b94e34656923a4e9b4 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 6 May 2017 10:23:20 -0700 Subject: [PATCH] Fix handling of implicit conversion to integral types larger than int (#507) --- fmt/format.h | 11 +++-------- test/format-test.cc | 10 ++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/fmt/format.h b/fmt/format.h index 123dd207..3f011661 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1395,14 +1395,9 @@ class MakeValue : public Arg { } template - MakeValue(const T &value, - typename EnableIf::value, int>::type = 0) { - int_value = value; - } - - template - static uint64_t type(const T &) { - return ConvertToInt::value ? Arg::INT : Arg::CUSTOM; + static typename EnableIf::value>::value, uint64_t>::type + type(const T &) { + return Arg::CUSTOM; } // Additional template param `Char_` is needed here because make_type always diff --git a/test/format-test.cc b/test/format-test.cc index 852c91da..6388d5a5 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1234,6 +1234,16 @@ TEST(FormatterTest, FormatIntLocale) { EXPECT_EQ("1--234--567", format("{:n}", 1234567)); } +struct ConvertibleToLongLong { + operator fmt::LongLong() const { + return fmt::LongLong(1) << 32; + } +}; + +TEST(FormatterTest, FormatConvertibleToLongLong) { + EXPECT_EQ("100000000", format("{:x}", ConvertibleToLongLong())); +} + TEST(FormatterTest, FormatFloat) { EXPECT_EQ("392.500000", format("{0:f}", 392.5f)); }