From 19e4d5ecd9f423df05d372fbfc288b03ce2b6306 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 7 Dec 2025 07:23:19 -0800 Subject: [PATCH] Fix handling of pointers in format string compilation and FMT_BUILTIN_TYPES=0 --- include/fmt/base.h | 7 +++++-- test/no-builtin-types-test.cc | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 094ff302..8281fe28 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -2258,8 +2258,11 @@ template class value { : pointer(const_cast(x)) {} FMT_INLINE value(nullptr_t) : pointer(nullptr) {} - template ::value || - std::is_member_pointer::value)> + template ::value || + std::is_member_pointer::value) && + !std::is_void::type>::value)> value(const T&) { // Formatting of arbitrary pointers is disallowed. If you want to format a // pointer cast it to `void*` or `const void*`. In particular, this forbids diff --git a/test/no-builtin-types-test.cc b/test/no-builtin-types-test.cc index 75c7fd16..1780220a 100644 --- a/test/no-builtin-types-test.cc +++ b/test/no-builtin-types-test.cc @@ -7,9 +7,10 @@ #include "gtest/gtest.h" -#if !defined(__GNUC__) || __GNUC__ >= 5 +#if !defined(__GNUC__) || (__GNUC__ >= 5 || defined(__clang__)) + # define FMT_BUILTIN_TYPES 0 -# include "fmt/format.h" +# include "fmt/compile.h" TEST(no_builtin_types_test, format) { EXPECT_EQ(fmt::format("{}", 42), "42"); @@ -22,4 +23,9 @@ TEST(no_builtin_types_test, double_is_custom_type) { EXPECT_EQ(fmt::format_args(args).get(0).type(), fmt::detail::type::custom_type); } + +TEST(no_builtin_types_test, format_pointer_compiled) { + const void* p = nullptr; + fmt::format(FMT_COMPILE("{:} {}"), 42, p); +} #endif