mirror of
https://github.com/fmtlib/fmt.git
synced 2026-05-06 08:26:15 +02:00
Don't perform narrowing conversion for integers in printf (#255)
This commit is contained in:
@@ -289,6 +289,7 @@ SPECIALIZE_MAKE_SIGNED(unsigned, int);
|
||||
SPECIALIZE_MAKE_SIGNED(unsigned long, long);
|
||||
SPECIALIZE_MAKE_SIGNED(fmt::ULongLong, fmt::LongLong);
|
||||
|
||||
// Test length format specifier ``length_spec``.
|
||||
template <typename T, typename U>
|
||||
void TestLength(const char *length_spec, U value) {
|
||||
fmt::LongLong signed_value = value;
|
||||
@@ -388,6 +389,13 @@ TEST(PrintfTest, Int) {
|
||||
EXPECT_PRINTF(fmt::format("{:X}", u), "%X", -42);
|
||||
}
|
||||
|
||||
TEST(PrintfTest, LongLong) {
|
||||
// fmt::printf allows passing long long arguments to %d without length
|
||||
// specifiers.
|
||||
fmt::LongLong max = std::numeric_limits<fmt::LongLong>::max();
|
||||
EXPECT_PRINTF(fmt::format("{}", max), "%d", max);
|
||||
}
|
||||
|
||||
TEST(PrintfTest, Float) {
|
||||
EXPECT_PRINTF("392.650000", "%f", 392.65);
|
||||
EXPECT_PRINTF("392.650000", "%F", 392.65);
|
||||
|
||||
Reference in New Issue
Block a user