diff --git a/fmt/format.h b/fmt/format.h index bd90e187..0be4cd70 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -1267,6 +1267,7 @@ template <> constexpr Type gettype() { return TSTRING; } template <> constexpr Type gettype() { return TSTRING; } template <> constexpr Type gettype() { return POINTER; } template <> constexpr Type gettype() { return POINTER; } +template <> constexpr Type gettype() { return POINTER; } template constexpr Type type() { return gettype::type>(); } @@ -1419,6 +1420,7 @@ class value { FMT_MAKE_VALUE(void *, pointer, POINTER) FMT_MAKE_VALUE(const void *, pointer, POINTER) + value(std::nullptr_t) { pointer = nullptr; } template value(const T &value, diff --git a/test/format-test.cc b/test/format-test.cc index 5a14950c..85dac3dc 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1219,6 +1219,7 @@ TEST(FormatterTest, FormatPointer) { EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'), format("{0}", reinterpret_cast(~uintptr_t()))); EXPECT_EQ("0x1234", format("{}", fmt::ptr(reinterpret_cast(0x1234)))); + EXPECT_EQ("0x0", format("{}", nullptr)); } TEST(FormatterTest, FormatString) {