From b94cb02a7fed5843dd81280f6e076798b31d87d1 Mon Sep 17 00:00:00 2001 From: asynts Date: Wed, 7 Oct 2020 12:47:35 +0200 Subject: [PATCH] AK+Format: Use pointer mode for pointers by default. --- AK/Format.h | 3 +++ AK/Tests/TestFormat.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/AK/Format.h b/AK/Format.h index b11139ae361..295dc8a1f72 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -284,6 +284,9 @@ template struct Formatter : StandardFormatter { void format(TypeErasedFormatParams& params, FormatBuilder& builder, T* value) { + if (m_mode == Mode::Default) + m_mode = Mode::Pointer; + Formatter formatter { *this }; formatter.format(params, builder, reinterpret_cast(value)); } diff --git a/AK/Tests/TestFormat.cpp b/AK/Tests/TestFormat.cpp index 8e29659beff..0e7e9aae6af 100644 --- a/AK/Tests/TestFormat.cpp +++ b/AK/Tests/TestFormat.cpp @@ -156,9 +156,11 @@ TEST_CASE(pointers) if (sizeof(void*) == 4) { EXPECT_EQ(String::formatted("{:p}", 32), "0x00000020"); EXPECT_EQ(String::formatted("{:p}", ptr), "0x00004000"); + EXPECT_EQ(String::formatted("{}", ptr), "0x00004000"); } else if (sizeof(void*) == 8) { EXPECT_EQ(String::formatted("{:p}", 32), "0x0000000000000020"); EXPECT_EQ(String::formatted("{:p}", ptr), "0x0000000000004000"); + EXPECT_EQ(String::formatted("{}", ptr), "0x0000000000004000"); } else { ASSERT_NOT_REACHED(); }