Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support printing (const) volatile void* #4056

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions test/base-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<volatile void*>(vip));
CHECK_ARG(char, p, static_cast<const volatile void*>(cvip));
}

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