mirror of
https://github.com/fmtlib/fmt.git
synced 2026-01-18 21:41:20 +01:00
Fix handling of pointers in format string compilation and FMT_BUILTIN_TYPES=0
This commit is contained in:
@@ -2258,8 +2258,11 @@ template <typename Context> class value {
|
|||||||
: pointer(const_cast<const void*>(x)) {}
|
: pointer(const_cast<const void*>(x)) {}
|
||||||
FMT_INLINE value(nullptr_t) : pointer(nullptr) {}
|
FMT_INLINE value(nullptr_t) : pointer(nullptr) {}
|
||||||
|
|
||||||
template <typename T, FMT_ENABLE_IF(std::is_pointer<T>::value ||
|
template <typename T,
|
||||||
std::is_member_pointer<T>::value)>
|
FMT_ENABLE_IF(
|
||||||
|
(std::is_pointer<T>::value ||
|
||||||
|
std::is_member_pointer<T>::value) &&
|
||||||
|
!std::is_void<typename std::remove_pointer<T>::type>::value)>
|
||||||
value(const T&) {
|
value(const T&) {
|
||||||
// Formatting of arbitrary pointers is disallowed. If you want to format a
|
// Formatting of arbitrary pointers is disallowed. If you want to format a
|
||||||
// pointer cast it to `void*` or `const void*`. In particular, this forbids
|
// pointer cast it to `void*` or `const void*`. In particular, this forbids
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
#if !defined(__GNUC__) || __GNUC__ >= 5
|
#if !defined(__GNUC__) || (__GNUC__ >= 5 || defined(__clang__))
|
||||||
|
|
||||||
# define FMT_BUILTIN_TYPES 0
|
# define FMT_BUILTIN_TYPES 0
|
||||||
# include "fmt/format.h"
|
# include "fmt/compile.h"
|
||||||
|
|
||||||
TEST(no_builtin_types_test, format) {
|
TEST(no_builtin_types_test, format) {
|
||||||
EXPECT_EQ(fmt::format("{}", 42), "42");
|
EXPECT_EQ(fmt::format("{}", 42), "42");
|
||||||
@@ -22,4 +23,9 @@ TEST(no_builtin_types_test, double_is_custom_type) {
|
|||||||
EXPECT_EQ(fmt::format_args(args).get(0).type(),
|
EXPECT_EQ(fmt::format_args(args).get(0).type(),
|
||||||
fmt::detail::type::custom_type);
|
fmt::detail::type::custom_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(no_builtin_types_test, format_pointer_compiled) {
|
||||||
|
const void* p = nullptr;
|
||||||
|
fmt::format(FMT_COMPILE("{:} {}"), 42, p);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user