Skip to content

Commit 1ba3e90

Browse files
committed
Fix handling of pointers in format string compilation and FMT_BUILTIN_TYPES=0
1 parent a6e871e commit 1ba3e90

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

include/fmt/base.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,8 +2258,11 @@ template <typename Context> class value {
22582258
: pointer(const_cast<const void*>(x)) {}
22592259
FMT_INLINE value(nullptr_t) : pointer(nullptr) {}
22602260

2261-
template <typename T, FMT_ENABLE_IF(std::is_pointer<T>::value ||
2262-
std::is_member_pointer<T>::value)>
2261+
template <typename T,
2262+
FMT_ENABLE_IF(
2263+
(std::is_pointer<T>::value ||
2264+
std::is_member_pointer<T>::value) &&
2265+
!std::is_void<typename std::remove_pointer<T>::type>::value)>
22632266
value(const T&) {
22642267
// Formatting of arbitrary pointers is disallowed. If you want to format a
22652268
// pointer cast it to `void*` or `const void*`. In particular, this forbids

test/no-builtin-types-test.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
#include "gtest/gtest.h"
99

10-
#if !defined(__GNUC__) || __GNUC__ >= 5
11-
# define FMT_BUILTIN_TYPES 0
12-
# include "fmt/format.h"
10+
#define FMT_BUILTIN_TYPES 0
11+
#include "fmt/compile.h"
12+
13+
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 500
1314

1415
TEST(no_builtin_types_test, format) {
1516
EXPECT_EQ(fmt::format("{}", 42), "42");
@@ -22,4 +23,9 @@ TEST(no_builtin_types_test, double_is_custom_type) {
2223
EXPECT_EQ(fmt::format_args(args).get(0).type(),
2324
fmt::detail::type::custom_type);
2425
}
26+
27+
TEST(no_builtin_types_test, format_pointer_compiled) {
28+
const void* p = nullptr;
29+
fmt::format(FMT_COMPILE("{:} {}"), 42, p);
30+
}
2531
#endif

0 commit comments

Comments
 (0)