Skip to content

Commit

Permalink
Support printing (const) volatile void*
Browse files Browse the repository at this point in the history
Fixes #4049
  • Loading branch information
Arghnews committed Jul 7, 2024
1 parent a433911 commit 63fb57c
Show file tree
Hide file tree
Showing 2 changed files with 21 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
15 changes: 15 additions & 0 deletions test/base-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ TEST(arg_test, pointer_arg) {
CHECK_ARG_SIMPLE(cp);
}

TEST(arg_test, volatile_pointer_arg) {
auto check = [](const int val) {
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)));
};
check(0);
check(1);
check(2);
check(0xbeef);
}

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

0 comments on commit 63fb57c

Please sign in to comment.