Skip to content

Commit 7b84047

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

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
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+
#if !defined(__GNUC__) || (__GNUC__ >= 5 || defined(__clang__))
11+
12+
# include "fmt/compile.h"
1313

1414
TEST(no_builtin_types_test, format) {
1515
EXPECT_EQ(fmt::format("{}", 42), "42");
@@ -22,4 +22,9 @@ TEST(no_builtin_types_test, double_is_custom_type) {
2222
EXPECT_EQ(fmt::format_args(args).get(0).type(),
2323
fmt::detail::type::custom_type);
2424
}
25+
26+
TEST(no_builtin_types_test, format_pointer_compiled) {
27+
const void* p = nullptr;
28+
fmt::format(FMT_COMPILE("{:} {}"), 42, p);
29+
}
2530
#endif

0 commit comments

Comments
 (0)