mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-28 06:36:02 +00:00
Fix handling of implicit conversion to integral types larger than int (#507)
This commit is contained in:
parent
c56d345985
commit
07ed421521
11
fmt/format.h
11
fmt/format.h
@ -1395,14 +1395,9 @@ class MakeValue : public Arg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
MakeValue(const T &value,
|
static typename EnableIf<Not<ConvertToInt<T>::value>::value, uint64_t>::type
|
||||||
typename EnableIf<ConvertToInt<T>::value, int>::type = 0) {
|
type(const T &) {
|
||||||
int_value = value;
|
return Arg::CUSTOM;
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static uint64_t type(const T &) {
|
|
||||||
return ConvertToInt<T>::value ? Arg::INT : Arg::CUSTOM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additional template param `Char_` is needed here because make_type always
|
// Additional template param `Char_` is needed here because make_type always
|
||||||
|
@ -1234,6 +1234,16 @@ TEST(FormatterTest, FormatIntLocale) {
|
|||||||
EXPECT_EQ("1--234--567", format("{:n}", 1234567));
|
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) {
|
TEST(FormatterTest, FormatFloat) {
|
||||||
EXPECT_EQ("392.500000", format("{0:f}", 392.5f));
|
EXPECT_EQ("392.500000", format("{0:f}", 392.5f));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user