diff --git a/include/fmt/format.h b/include/fmt/format.h index 0c3231b5f87e..98bfade459d3 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3888,7 +3888,8 @@ template auto ptr(T p) -> const void* { static_assert(std::is_pointer::value, ""); return detail::bit_cast(p); } -template auto ptr(const std::unique_ptr& p) -> const void* { +template +auto ptr(const std::unique_ptr& p) -> const void* { return p.get(); } template auto ptr(const std::shared_ptr& p) -> const void* { diff --git a/test/format-test.cc b/test/format-test.cc index 4db3c9c49356..49b5f54107d6 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1508,6 +1508,12 @@ TEST(format_test, format_pointer) { std::unique_ptr up(new int(1)); EXPECT_EQ(fmt::format("{}", fmt::ptr(up.get())), fmt::format("{}", fmt::ptr(up))); + struct custom_deleter { + void operator()(int* p) const { delete p; } + }; + std::unique_ptr upcd(new int(1)); + EXPECT_EQ(fmt::format("{}", fmt::ptr(upcd.get())), + fmt::format("{}", fmt::ptr(upcd))); std::shared_ptr sp(new int(1)); EXPECT_EQ(fmt::format("{}", fmt::ptr(sp.get())), fmt::format("{}", fmt::ptr(sp)));