From cc5e38fa5c356c8593f7f592649a353bed9154ed Mon Sep 17 00:00:00 2001 From: Justin Riddell Date: Tue, 9 Jul 2024 21:04:08 +0100 Subject: [PATCH] Support printing (const) volatile void* Fixes #4049 --- include/fmt/base.h | 6 ++++++ test/base-test.cc | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/include/fmt/base.h b/include/fmt/base.h index ceb9845591ebe..c95ca6a48ca73 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -1476,6 +1476,12 @@ template struct arg_mapper { FMT_MAP_API auto map(void* val) -> const void* { return val; } FMT_MAP_API auto map(const void* val) -> const void* { return val; } + FMT_MAP_API auto map(volatile void* val) -> const void* { + return const_cast(val); + } + FMT_MAP_API auto map(const volatile void* val) -> const void* { + return const_cast(val); + } FMT_MAP_API auto map(std::nullptr_t val) -> const void* { return val; } // Use SFINAE instead of a const T* parameter to avoid a conflict with the diff --git a/test/base-test.cc b/test/base-test.cc index c82e7378cd94d..703728f7b5ab2 100644 --- a/test/base-test.cc +++ b/test/base-test.cc @@ -425,6 +425,15 @@ TEST(arg_test, pointer_arg) { CHECK_ARG_SIMPLE(cp); } +TEST(arg_test, volatile_pointer_arg) { + int val = 0; + CHECK_ARG(char, reinterpret_cast(val), + static_cast(reinterpret_cast(val))); + CHECK_ARG(char, reinterpret_cast(val), + static_cast( + reinterpret_cast(val))); +} + struct check_custom { auto operator()(fmt::basic_format_arg::handle h) const -> test_result {