From 8a2bc0ab1b337dfc6988891145a9c66c67b3a370 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Mon, 4 Sep 2017 11:10:08 -0700 Subject: [PATCH] Add nullptr support --- fmt/format.h | 2 ++ test/format-test.cc | 1 + 2 files changed, 3 insertions(+) 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) {