diff --git a/format.cc b/format.cc index 98b0f4ba..c7405f99 100644 --- a/format.cc +++ b/format.cc @@ -974,6 +974,7 @@ void fmt::internal::PrintfFormatter::format( break; default: --s; + ArgConverter(arg, *s).visit(arg); } // Parse type. diff --git a/test/printf-test.cc b/test/printf-test.cc index a6fc16d3..297cecdf 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -165,12 +165,13 @@ TEST(PrintfTest, SpaceFlag) { TEST(PrintfTest, HashFlag) { EXPECT_PRINTF("042", "%#o", 042); - EXPECT_PRINTF("-042", "%#o", -042); + EXPECT_PRINTF(fmt::format("0{:o}", static_cast(-042)), "%#o", -042); EXPECT_PRINTF("0", "%#o", 0); EXPECT_PRINTF("0x42", "%#x", 0x42); EXPECT_PRINTF("0X42", "%#X", 0x42); - EXPECT_PRINTF("-0x42", "%#x", -0x42); + EXPECT_PRINTF( + fmt::format("0x{:x}", static_cast(-0x42)), "%#x", -0x42); EXPECT_PRINTF("0", "%#x", 0); EXPECT_PRINTF("0x0042", "%#06x", 0x42); @@ -370,6 +371,16 @@ TEST(PrintfTest, Length) { EXPECT_PRINTF(fmt::format("{}", max), "%Lg", max); } +TEST(PrintfTest, Int) { + EXPECT_PRINTF("-42", "%d", -42); + EXPECT_PRINTF("-42", "%i", -42); + unsigned u = -42; + EXPECT_PRINTF(fmt::format("{}", u), "%u", -42); + EXPECT_PRINTF(fmt::format("{:o}", u), "%o", -42); + EXPECT_PRINTF(fmt::format("{:x}", u), "%x", -42); + EXPECT_PRINTF(fmt::format("{:X}", u), "%X", -42); +} + TEST(PrintfTest, Char) { EXPECT_PRINTF("x", "%c", 'x'); int max = std::numeric_limits::max();