Skip to content

Commit

Permalink
Support printing (const) volatile void*
Browse files Browse the repository at this point in the history
  • Loading branch information
Arghnews committed Jul 9, 2024
1 parent e60ff50 commit cc5e38f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,12 @@ template <typename Context> 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<const void*>(val);
}
FMT_MAP_API auto map(const volatile void* val) -> const void* {
return const_cast<const void*>(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
Expand Down
9 changes: 9 additions & 0 deletions test/base-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<const void*>(val),
static_cast<volatile void*>(reinterpret_cast<volatile int*>(val)));
CHECK_ARG(char, reinterpret_cast<const void*>(val),
static_cast<const volatile void*>(
reinterpret_cast<const volatile int*>(val)));
}

struct check_custom {
auto operator()(fmt::basic_format_arg<fmt::format_context>::handle h) const
-> test_result {
Expand Down

0 comments on commit cc5e38f

Please sign in to comment.