From 13038f37e87efa44e2a1409f41da1fa7c02fee7d Mon Sep 17 00:00:00 2001 From: Justin Riddell Date: Wed, 10 Jul 2024 16:35:06 +0100 Subject: [PATCH] Support printing (const) volatile void* (#4056) Fixes #4049 --- include/fmt/base.h | 6 ++++++ test/base-test.cc | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/include/fmt/base.h b/include/fmt/base.h index ceb9845591eb..c95ca6a48ca7 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 c82e7378cd94..7f0a6abfd669 100644 --- a/test/base-test.cc +++ b/test/base-test.cc @@ -425,6 +425,14 @@ TEST(arg_test, pointer_arg) { CHECK_ARG_SIMPLE(cp); } +TEST(arg_test, volatile_pointer_arg) { + const void* p = nullptr; + volatile int* vip = nullptr; + const volatile int* cvip = nullptr; + CHECK_ARG(char, p, static_cast(vip)); + CHECK_ARG(char, p, static_cast(cvip)); +} + struct check_custom { auto operator()(fmt::basic_format_arg::handle h) const -> test_result {