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 {