Skip to content

Commit

Permalink
Fix handling of implicit conversion to integral types larger than int (
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut authored and Bjoern Thiel committed May 11, 2017
1 parent 0a87a95 commit f8e8928
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 3 additions & 8 deletions fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1395,14 +1395,9 @@ class MakeValue : public Arg {
}

template <typename T>
MakeValue(const T &value,
typename EnableIf<ConvertToInt<T>::value, int>::type = 0) {
int_value = value;
}

template <typename T>
static uint64_t type(const T &) {
return ConvertToInt<T>::value ? Arg::INT : Arg::CUSTOM;
static typename EnableIf<Not<ConvertToInt<T>::value>::value, uint64_t>::type
type(const T &) {
return Arg::CUSTOM;
}

// Additional template param `Char_` is needed here because make_type always
Expand Down
10 changes: 10 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit f8e8928

Please sign in to comment.