FMT_EXPLICIT -> explicit, FMT_NULL -> nullptr

This commit is contained in:
Victor Zverovich
2019-05-30 07:01:31 -07:00
parent 4a7966c773
commit d07cc2026b
25 changed files with 163 additions and 193 deletions

View File

@ -42,7 +42,7 @@ inline std::tm localtime(std::time_t time) {
return handle(localtime_r(&time_, &tm_)); return handle(localtime_r(&time_, &tm_));
} }
bool handle(std::tm* tm) { return tm != FMT_NULL; } bool handle(std::tm* tm) { return tm != nullptr; }
bool handle(internal::null<>) { bool handle(internal::null<>) {
using namespace fmt::internal; using namespace fmt::internal;
@ -56,7 +56,7 @@ inline std::tm localtime(std::time_t time) {
using namespace fmt::internal; using namespace fmt::internal;
std::tm* tm = std::localtime(&time_); std::tm* tm = std::localtime(&time_);
if (tm) tm_ = *tm; if (tm) tm_ = *tm;
return tm != FMT_NULL; return tm != nullptr;
} }
#endif #endif
}; };
@ -79,7 +79,7 @@ inline std::tm gmtime(std::time_t time) {
return handle(gmtime_r(&time_, &tm_)); return handle(gmtime_r(&time_, &tm_));
} }
bool handle(std::tm* tm) { return tm != FMT_NULL; } bool handle(std::tm* tm) { return tm != nullptr; }
bool handle(internal::null<>) { bool handle(internal::null<>) {
using namespace fmt::internal; using namespace fmt::internal;
@ -92,7 +92,7 @@ inline std::tm gmtime(std::time_t time) {
bool fallback(internal::null<>) { bool fallback(internal::null<>) {
std::tm* tm = std::gmtime(&time_); std::tm* tm = std::gmtime(&time_);
if (tm) tm_ = *tm; if (tm) tm_ = *tm;
return tm != FMT_NULL; return tm != nullptr;
} }
#endif #endif
}; };
@ -157,7 +157,7 @@ template <typename Char> struct formatter<std::tm, Char> {
namespace internal { namespace internal {
template <typename Period> FMT_CONSTEXPR const char* get_units() { template <typename Period> FMT_CONSTEXPR const char* get_units() {
return FMT_NULL; return nullptr;
} }
template <> FMT_CONSTEXPR const char* get_units<std::atto>() { return "as"; } template <> FMT_CONSTEXPR const char* get_units<std::atto>() { return "as"; }
template <> FMT_CONSTEXPR const char* get_units<std::femto>() { return "fs"; } template <> FMT_CONSTEXPR const char* get_units<std::femto>() { return "fs"; }

View File

@ -89,28 +89,6 @@
# endif # endif
#endif #endif
#if FMT_HAS_FEATURE(cxx_explicit_conversions) || FMT_GCC_VERSION >= 405 || \
FMT_MSC_VER >= 1800
# define FMT_USE_EXPLICIT 1
# define FMT_EXPLICIT explicit
#else
# define FMT_USE_EXPLICIT 0
# define FMT_EXPLICIT
#endif
#ifndef FMT_NULL
# if FMT_HAS_FEATURE(cxx_nullptr) || \
(FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1600
# define FMT_NULL nullptr
# define FMT_USE_NULLPTR 1
# else
# define FMT_NULL NULL
# endif
#endif
#ifndef FMT_USE_NULLPTR
# define FMT_USE_NULLPTR 0
#endif
// Check if exceptions are disabled. // Check if exceptions are disabled.
#ifndef FMT_EXCEPTIONS #ifndef FMT_EXCEPTIONS
# if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \ # if (defined(__GNUC__) && !defined(__EXCEPTIONS)) || \
@ -220,11 +198,6 @@
# define FMT_STRING_VIEW std::experimental::basic_string_view # define FMT_STRING_VIEW std::experimental::basic_string_view
#endif #endif
// std::result_of is defined in <functional> in gcc 4.4.
#if FMT_GCC_VERSION && FMT_GCC_VERSION <= 404
# include <functional>
#endif
// An enable_if helper to be used in template parameters. enable_if in template // An enable_if helper to be used in template parameters. enable_if in template
// parameters results in much shorter symbols: https://godbolt.org/z/sWw4vP. // parameters results in much shorter symbols: https://godbolt.org/z/sWw4vP.
#define FMT_ENABLE_IF_T(...) typename std::enable_if<(__VA_ARGS__), int>::type #define FMT_ENABLE_IF_T(...) typename std::enable_if<(__VA_ARGS__), int>::type
@ -272,7 +245,7 @@ template <typename T> class buffer {
// Don't initialize ptr_ since it is not accessed to save a few cycles. // Don't initialize ptr_ since it is not accessed to save a few cycles.
buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
buffer(T* p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT buffer(T* p = nullptr, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT
: ptr_(p), : ptr_(p),
size_(sz), size_(sz),
capacity_(cap) {} capacity_(cap) {}
@ -379,7 +352,7 @@ typedef char no[2];
template <typename T, typename V> struct is_constructible { template <typename T, typename V> struct is_constructible {
template <typename U> static yes& test(int (*)[sizeof(new U(declval<V>()))]); template <typename U> static yes& test(int (*)[sizeof(new U(declval<V>()))]);
template <typename U> static no& test(...); template <typename U> static no& test(...);
enum { value = sizeof(test<T>(FMT_NULL)) == sizeof(yes) }; enum { value = sizeof(test<T>(nullptr)) == sizeof(yes) };
}; };
#else #else
template <typename... T> template <typename... T>
@ -404,7 +377,7 @@ template <typename Char> class basic_string_view {
typedef Char char_type; typedef Char char_type;
typedef const Char* iterator; typedef const Char* iterator;
FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(FMT_NULL), size_(0) {} FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {}
/** Constructs a string reference object from a C string and a size. */ /** Constructs a string reference object from a C string and a size. */
FMT_CONSTEXPR basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT FMT_CONSTEXPR basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT
@ -850,10 +823,7 @@ FMT_MAKE_VALUE(string_type, const std::basic_string<typename C::char_type>&,
basic_string_view<typename C::char_type>) basic_string_view<typename C::char_type>)
FMT_MAKE_VALUE(pointer_type, void*, const void*) FMT_MAKE_VALUE(pointer_type, void*, const void*)
FMT_MAKE_VALUE_SAME(pointer_type, const void*) FMT_MAKE_VALUE_SAME(pointer_type, const void*)
#if FMT_USE_NULLPTR
FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*) FMT_MAKE_VALUE(pointer_type, std::nullptr_t, const void*)
#endif
// Formatting of arbitrary pointers is disallowed. If you want to output a // Formatting of arbitrary pointers is disallowed. If you want to output 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
@ -953,7 +923,7 @@ template <typename Context> class basic_format_arg {
FMT_CONSTEXPR basic_format_arg() : type_(internal::none_type) {} FMT_CONSTEXPR basic_format_arg() : type_(internal::none_type) {}
FMT_CONSTEXPR FMT_EXPLICIT operator bool() const FMT_NOEXCEPT { FMT_CONSTEXPR explicit operator bool() const FMT_NOEXCEPT {
return type_ != internal::none_type; return type_ != internal::none_type;
} }
@ -1041,7 +1011,7 @@ template <typename Context> class arg_map {
} }
public: public:
arg_map() : map_(FMT_NULL), size_(0) {} arg_map() : map_(nullptr), size_(0) {}
void init(const basic_format_args<Context>& args); void init(const basic_format_args<Context>& args);
~arg_map() { delete[] map_; } ~arg_map() { delete[] map_; }
@ -1061,7 +1031,7 @@ class locale_ref {
friend class locale; friend class locale;
public: public:
locale_ref() : locale_(FMT_NULL) {} locale_ref() : locale_(nullptr) {}
template <typename Locale> explicit locale_ref(const Locale& loc); template <typename Locale> explicit locale_ref(const Locale& loc);
template <typename Locale> Locale get() const; template <typename Locale> Locale get() const;

View File

@ -98,7 +98,7 @@ typedef void (*FormatFunc)(internal::buffer<char>&, int, string_view);
// Buffer should be at least of size 1. // Buffer should be at least of size 1.
int safe_strerror(int error_code, char*& buffer, int safe_strerror(int error_code, char*& buffer,
std::size_t buffer_size) FMT_NOEXCEPT { std::size_t buffer_size) FMT_NOEXCEPT {
FMT_ASSERT(buffer != FMT_NULL && buffer_size != 0, "invalid buffer"); FMT_ASSERT(buffer != nullptr && buffer_size != 0, "invalid buffer");
class dispatcher { class dispatcher {
private: private:
@ -650,9 +650,9 @@ template <int GRISU_VERSION> struct grisu_shortest_handler {
// Decrement the generated number approaching value from above. // Decrement the generated number approaching value from above.
void round(uint64_t d, uint64_t divisor, uint64_t& remainder, void round(uint64_t d, uint64_t divisor, uint64_t& remainder,
uint64_t error) { uint64_t error) {
while (remainder < d && error - remainder >= divisor && while (
(remainder + divisor < d || remainder < d && error - remainder >= divisor &&
d - remainder >= remainder + divisor - d)) { (remainder + divisor < d || d - remainder >= remainder + divisor - d)) {
--buf[size - 1]; --buf[size - 1];
remainder += divisor; remainder += divisor;
} }
@ -782,7 +782,7 @@ void sprintf_format(Double value, internal::buffer<char>& buf,
*format_ptr = '\0'; *format_ptr = '\0';
// Format using snprintf. // Format using snprintf.
char* start = FMT_NULL; char* start = nullptr;
for (;;) { for (;;) {
std::size_t buffer_size = buf.capacity(); std::size_t buffer_size = buf.capacity();
start = &buf[0]; start = &buf[0];
@ -839,7 +839,7 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) {
} }
int length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), int length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(),
s_size, FMT_NULL, 0); s_size, nullptr, 0);
if (length == 0) FMT_THROW(windows_error(GetLastError(), ERROR_MSG)); if (length == 0) FMT_THROW(windows_error(GetLastError(), ERROR_MSG));
buffer_.resize(length + 1); buffer_.resize(length + 1);
length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, length = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size,
@ -865,12 +865,12 @@ FMT_FUNC int internal::utf16_to_utf8::convert(wstring_view s) {
return 0; return 0;
} }
int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, nullptr, 0,
FMT_NULL, FMT_NULL); nullptr, nullptr);
if (length == 0) return GetLastError(); if (length == 0) return GetLastError();
buffer_.resize(length + 1); buffer_.resize(length + 1);
length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, &buffer_[0], length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, &buffer_[0],
length, FMT_NULL, FMT_NULL); length, nullptr, nullptr);
if (length == 0) return GetLastError(); if (length == 0) return GetLastError();
buffer_[length] = 0; buffer_[length] = 0;
return 0; return 0;
@ -894,9 +894,9 @@ FMT_FUNC void internal::format_windows_error(internal::buffer<char>& out,
for (;;) { for (;;) {
wchar_t* system_message = &buf[0]; wchar_t* system_message = &buf[0];
int result = FormatMessageW( int result = FormatMessageW(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, FMT_NULL, FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr,
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), system_message, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), system_message,
static_cast<uint32_t>(buf.size()), FMT_NULL); static_cast<uint32_t>(buf.size()), nullptr);
if (result != 0) { if (result != 0) {
utf16_to_utf8 utf8_message; utf16_to_utf8 utf8_message;
if (utf8_message.convert(system_message) == ERROR_SUCCESS) { if (utf8_message.convert(system_message) == ERROR_SUCCESS) {

View File

@ -285,8 +285,7 @@ FMT_CONSTEXPR T* end(T (&array)[N]) FMT_NOEXCEPT {
} }
// An implementation of iterator_t for pre-C++20 compilers such as gcc 4. // An implementation of iterator_t for pre-C++20 compilers such as gcc 4.
template <typename T> template <typename T> struct iterator_t {
struct iterator_t {
typedef decltype(internal::begin(internal::declval<const T&>())) type; typedef decltype(internal::begin(internal::declval<const T&>())) type;
}; };
@ -2101,7 +2100,7 @@ inline bool find<false, char>(const char* first, const char* last, char value,
const char*& out) { const char*& out) {
out = static_cast<const char*>( out = static_cast<const char*>(
std::memchr(first, value, internal::to_unsigned(last - first))); std::memchr(first, value, internal::to_unsigned(last - first)));
return out != FMT_NULL; return out != nullptr;
} }
template <typename Handler, typename Char> struct id_adapter { template <typename Handler, typename Char> struct id_adapter {
@ -2123,7 +2122,7 @@ FMT_CONSTEXPR void parse_format_string(basic_string_view<Char> format_str,
FMT_CONSTEXPR void operator()(const Char* begin, const Char* end) { FMT_CONSTEXPR void operator()(const Char* begin, const Char* end) {
if (begin == end) return; if (begin == end) return;
for (;;) { for (;;) {
const Char* p = FMT_NULL; const Char* p = nullptr;
if (!find<IS_CONSTEXPR>(begin, end, '}', p)) if (!find<IS_CONSTEXPR>(begin, end, '}', p))
return handler_.on_text(begin, end); return handler_.on_text(begin, end);
++p; ++p;
@ -2304,8 +2303,8 @@ class arg_formatter
\endrst \endrst
*/ */
explicit arg_formatter(context_type& ctx, explicit arg_formatter(context_type& ctx,
basic_parse_context<char_type>* parse_ctx = FMT_NULL, basic_parse_context<char_type>* parse_ctx = nullptr,
format_specs* spec = FMT_NULL) format_specs* spec = nullptr)
: base(Range(ctx.out()), spec, ctx.locale()), : base(Range(ctx.out()), spec, ctx.locale()),
ctx_(ctx), ctx_(ctx),
parse_ctx_(parse_ctx) {} parse_ctx_(parse_ctx) {}
@ -3040,7 +3039,7 @@ template <typename T, typename Char>
struct formatter<T, Char, struct formatter<T, Char,
typename std::enable_if<internal::format_type< typename std::enable_if<internal::format_type<
typename buffer_context<Char>::type, T>::value>::type> { typename buffer_context<Char>::type, T>::value>::type> {
FMT_CONSTEXPR formatter() : format_str_(FMT_NULL) {} FMT_CONSTEXPR formatter() : format_str_(nullptr) {}
// Parses format specifiers stopping either at the end of the range or at the // Parses format specifiers stopping either at the end of the range or at the
// terminating '}'. // terminating '}'.
@ -3104,7 +3103,7 @@ struct formatter<T, Char,
typedef output_range<typename FormatContext::iterator, typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> typename FormatContext::char_type>
range_type; range_type;
return visit_format_arg(arg_formatter<range_type>(ctx, FMT_NULL, &specs_), return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
internal::make_arg<FormatContext>(val)); internal::make_arg<FormatContext>(val));
} }
@ -3160,7 +3159,7 @@ template <typename Char = char> class dynamic_formatter {
typedef output_range<typename FormatContext::iterator, typedef output_range<typename FormatContext::iterator,
typename FormatContext::char_type> typename FormatContext::char_type>
range; range;
visit_format_arg(arg_formatter<range>(ctx, FMT_NULL, &specs_), visit_format_arg(arg_formatter<range>(ctx, nullptr, &specs_),
internal::make_arg<FormatContext>(val)); internal::make_arg<FormatContext>(val));
return ctx.out(); return ctx.out();
} }
@ -3329,14 +3328,14 @@ arg_join<It, wchar_t> join(It begin, It end, wstring_view sep) {
\endrst \endrst
*/ */
template <typename Range> template <typename Range>
arg_join<typename internal::iterator_t<Range>::type, char> arg_join<typename internal::iterator_t<Range>::type, char> join(
join(const Range& range, string_view sep) { const Range& range, string_view sep) {
return join(internal::begin(range), internal::end(range), sep); return join(internal::begin(range), internal::end(range), sep);
} }
template <typename Range> template <typename Range>
arg_join<typename internal::iterator_t<Range>::type, wchar_t> arg_join<typename internal::iterator_t<Range>::type, wchar_t> join(
join(const Range& range, wstring_view sep) { const Range& range, wstring_view sep) {
return join(internal::begin(range), internal::end(range), sep); return join(internal::begin(range), internal::end(range), sep);
} }
#endif #endif

View File

@ -133,7 +133,7 @@ class buffered_file {
public: public:
// Constructs a buffered_file object which doesn't represent any file. // Constructs a buffered_file object which doesn't represent any file.
buffered_file() FMT_NOEXCEPT : file_(FMT_NULL) {} buffered_file() FMT_NOEXCEPT : file_(nullptr) {}
// Destroys the object closing the file it represents if any. // Destroys the object closing the file it represents if any.
FMT_API ~buffered_file() FMT_NOEXCEPT; FMT_API ~buffered_file() FMT_NOEXCEPT;
@ -144,13 +144,13 @@ class buffered_file {
public: public:
buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) { buffered_file(buffered_file&& other) FMT_NOEXCEPT : file_(other.file_) {
other.file_ = FMT_NULL; other.file_ = nullptr;
} }
buffered_file& operator=(buffered_file&& other) { buffered_file& operator=(buffered_file&& other) {
close(); close();
file_ = other.file_; file_ = other.file_;
other.file_ = FMT_NULL; other.file_ = nullptr;
return *this; return *this;
} }
@ -295,7 +295,7 @@ class Locale {
public: public:
typedef locale_t Type; typedef locale_t Type;
Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) { Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", nullptr)) {
if (!locale_) FMT_THROW(system_error(errno, "cannot create locale")); if (!locale_) FMT_THROW(system_error(errno, "cannot create locale"));
} }
~Locale() { freelocale(locale_); } ~Locale() { freelocale(locale_); }
@ -305,7 +305,7 @@ class Locale {
// Converts string to floating-point number and advances str past the end // Converts string to floating-point number and advances str past the end
// of the parsed input. // of the parsed input.
double strtod(const char*& str) const { double strtod(const char*& str) const {
char* end = FMT_NULL; char* end = nullptr;
double result = strtod_l(str, &end, locale_); double result = strtod_l(str, &end, locale_);
str = end; str = end;
return result; return result;

View File

@ -297,7 +297,7 @@ class prepared_format {
check_prepared_specs(specs, arg.type()); check_prepared_specs(specs, arg.type());
advance_parse_context_to_specification(parse_ctx, part); advance_parse_context_to_specification(parse_ctx, part);
ctx.advance_to( ctx.advance_to(
visit_format_arg(arg_formatter<Range>(ctx, FMT_NULL, &specs), arg)); visit_format_arg(arg_formatter<Range>(ctx, nullptr, &specs), arg));
} break; } break;
} }
} }

View File

@ -82,7 +82,7 @@ template <typename T> class is_like_std_string {
public: public:
static FMT_CONSTEXPR_DECL const bool value = static FMT_CONSTEXPR_DECL const bool value =
is_string<T>::value || !std::is_void<decltype(check<T>(FMT_NULL))>::value; is_string<T>::value || !std::is_void<decltype(check<T>(nullptr))>::value;
}; };
template <typename Char> template <typename Char>
@ -113,7 +113,7 @@ template <typename T> class is_tuple_like_ {
public: public:
static FMT_CONSTEXPR_DECL const bool value = static FMT_CONSTEXPR_DECL const bool value =
!std::is_void<decltype(check<T>(FMT_NULL))>::value; !std::is_void<decltype(check<T>(nullptr))>::value;
}; };
// Check for integer_sequence // Check for integer_sequence

View File

@ -73,7 +73,7 @@ buffered_file::~buffered_file() FMT_NOEXCEPT {
buffered_file::buffered_file(cstring_view filename, cstring_view mode) { buffered_file::buffered_file(cstring_view filename, cstring_view mode) {
FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())),
FMT_NULL); nullptr);
if (!file_) if (!file_)
FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str())); FMT_THROW(system_error(errno, "cannot open file {}", filename.c_str()));
} }
@ -81,7 +81,7 @@ buffered_file::buffered_file(cstring_view filename, cstring_view mode) {
void buffered_file::close() { void buffered_file::close() {
if (!file_) return; if (!file_) return;
int result = FMT_SYSTEM(fclose(file_)); int result = FMT_SYSTEM(fclose(file_));
file_ = FMT_NULL; file_ = nullptr;
if (result != 0) FMT_THROW(system_error(errno, "cannot close file")); if (result != 0) FMT_THROW(system_error(errno, "cannot close file"));
} }

View File

@ -60,7 +60,7 @@ TEST(TimeTest, GrowBuffer) {
std::string s = "{:"; std::string s = "{:";
for (int i = 0; i < 30; ++i) s += "%c"; for (int i = 0; i < 30; ++i) s += "%c";
s += "}\n"; s += "}\n";
std::time_t t = std::time(FMT_NULL); std::time_t t = std::time(nullptr);
fmt::format(s, *std::localtime(&t)); fmt::format(s, *std::localtime(&t));
} }
@ -83,13 +83,13 @@ static bool EqualTime(const std::tm& lhs, const std::tm& rhs) {
} }
TEST(TimeTest, LocalTime) { TEST(TimeTest, LocalTime) {
std::time_t t = std::time(FMT_NULL); std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t); std::tm tm = *std::localtime(&t);
EXPECT_TRUE(EqualTime(tm, fmt::localtime(t))); EXPECT_TRUE(EqualTime(tm, fmt::localtime(t)));
} }
TEST(TimeTest, GMTime) { TEST(TimeTest, GMTime) {
std::time_t t = std::time(FMT_NULL); std::time_t t = std::time(nullptr);
std::tm tm = *std::gmtime(&t); std::tm tm = *std::gmtime(&t);
EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t))); EXPECT_TRUE(EqualTime(tm, fmt::gmtime(t)));
} }

View File

@ -84,7 +84,7 @@ TEST(BufferTest, Nonmoveable) {
// A test buffer with a dummy grow method. // A test buffer with a dummy grow method.
template <typename T> struct test_buffer : buffer<T> { template <typename T> struct test_buffer : buffer<T> {
void grow(std::size_t capacity) { this->set(FMT_NULL, capacity); } void grow(std::size_t capacity) { this->set(nullptr, capacity); }
}; };
template <typename T> struct mock_buffer : buffer<T> { template <typename T> struct mock_buffer : buffer<T> {
@ -103,7 +103,7 @@ template <typename T> struct mock_buffer : buffer<T> {
TEST(BufferTest, Ctor) { TEST(BufferTest, Ctor) {
{ {
mock_buffer<int> buffer; mock_buffer<int> buffer;
EXPECT_EQ(FMT_NULL, &buffer[0]); EXPECT_EQ(nullptr, &buffer[0]);
EXPECT_EQ(static_cast<size_t>(0), buffer.size()); EXPECT_EQ(static_cast<size_t>(0), buffer.size());
EXPECT_EQ(static_cast<size_t>(0), buffer.capacity()); EXPECT_EQ(static_cast<size_t>(0), buffer.capacity());
} }
@ -217,7 +217,7 @@ struct custom_context {
const char* format(const T&, custom_context& ctx) { const char* format(const T&, custom_context& ctx) {
ctx.called = true; ctx.called = true;
return FMT_NULL; return nullptr;
} }
}; };
}; };
@ -361,8 +361,8 @@ TEST(ArgTest, WStringArg) {
} }
TEST(ArgTest, PointerArg) { TEST(ArgTest, PointerArg) {
void* p = FMT_NULL; void* p = nullptr;
const void* cp = FMT_NULL; const void* cp = nullptr;
CHECK_ARG_(char, cp, p); CHECK_ARG_(char, cp, p);
CHECK_ARG_(wchar_t, cp, p); CHECK_ARG_(wchar_t, cp, p);
CHECK_ARG(cp, ); CHECK_ARG(cp, );
@ -571,7 +571,7 @@ TEST(FormatterTest, FormatImplicitlyConvertibleToStringView) {
} }
// std::is_constructible is broken in MSVC until version 2015. // std::is_constructible is broken in MSVC until version 2015.
#if FMT_USE_EXPLICIT && (!FMT_MSC_VER || FMT_MSC_VER >= 1900) #if !FMT_MSC_VER || FMT_MSC_VER >= 1900
struct explicitly_convertible_to_string_view { struct explicitly_convertible_to_string_view {
explicit operator fmt::string_view() const { return "foo"; } explicit operator fmt::string_view() const { return "foo"; }
}; };
@ -593,7 +593,7 @@ struct explicitly_convertible_to_string_like {
template <typename String, template <typename String,
typename = typename std::enable_if<std::is_constructible< typename = typename std::enable_if<std::is_constructible<
String, const char*, std::size_t>::value>::type> String, const char*, std::size_t>::value>::type>
FMT_EXPLICIT operator String() const { explicit operator String() const {
return String("foo", 3u); return String("foo", 3u);
} }
}; };

View File

@ -6,7 +6,7 @@
// For the license information refer to format.h. // For the license information refer to format.h.
#ifndef _CRT_SECURE_NO_WARNINGS #ifndef _CRT_SECURE_NO_WARNINGS
# define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
#include "fmt/format.h" #include "fmt/format.h"
@ -26,7 +26,7 @@ class custom_arg_formatter
custom_arg_formatter(fmt::format_context& ctx, custom_arg_formatter(fmt::format_context& ctx,
fmt::format_parse_context* parse_ctx, fmt::format_parse_context* parse_ctx,
fmt::format_specs* s = FMT_NULL) fmt::format_specs* s = nullptr)
: base(ctx, parse_ctx, s) {} : base(ctx, parse_ctx, s) {}
using base::operator(); using base::operator();

View File

@ -513,7 +513,7 @@ class arg_formatter
*spec* contains format specifier information for standard argument types. *spec* contains format specifier information for standard argument types.
\endrst \endrst
*/ */
arg_formatter(format_context& ctx, parse_context* parse_ctx = FMT_NULL, fmt::format_specs* spec = FMT_NULL) arg_formatter(format_context& ctx, parse_context* parse_ctx = nullptr, fmt::format_specs* spec = nullptr)
: base(Range(ctx.out()), spec, {}), parse_ctx_(parse_ctx), ctx_(ctx) {} : base(Range(ctx.out()), spec, {}), parse_ctx_(parse_ctx), ctx_(ctx) {}
using base::operator(); using base::operator();
@ -693,13 +693,13 @@ struct formatter {
template <typename FormatContext> template <typename FormatContext>
auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) { auto format(const T& val, FormatContext& ctx) -> decltype(ctx.out()) {
fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>( fmt::internal::handle_dynamic_spec<fmt::internal::width_checker>(
specs_.width_, specs_.width_ref, ctx, FMT_NULL); specs_.width_, specs_.width_ref, ctx, nullptr);
fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>( fmt::internal::handle_dynamic_spec<fmt::internal::precision_checker>(
specs_.precision, specs_.precision_ref, ctx, FMT_NULL); specs_.precision, specs_.precision_ref, ctx, nullptr);
typedef fmt::output_range<typename FormatContext::iterator, typedef fmt::output_range<typename FormatContext::iterator,
typename FormatContext::char_type> typename FormatContext::char_type>
range_type; range_type;
return visit_format_arg(arg_formatter<range_type>(ctx, FMT_NULL, &specs_), return visit_format_arg(arg_formatter<range_type>(ctx, nullptr, &specs_),
basic_format_arg<FormatContext>(val)); basic_format_arg<FormatContext>(val));
} }

View File

@ -169,9 +169,9 @@ TEST(FormatTest, FormatNegativeNaN) {
} }
TEST(FormatTest, StrError) { TEST(FormatTest, StrError) {
char* message = FMT_NULL; char* message = nullptr;
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = FMT_NULL, 0), EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = nullptr, 0),
"invalid buffer"); "invalid buffer");
EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = buffer, 0), EXPECT_ASSERT(fmt::safe_strerror(EDOM, message = buffer, 0),
"invalid buffer"); "invalid buffer");
@ -259,6 +259,6 @@ TEST(UtilTest, WriteUIntPtr) {
fmt::writer writer(buf); fmt::writer writer(buf);
writer.write_pointer(fmt::internal::bit_cast<fmt::internal::uintptr_t>( writer.write_pointer(fmt::internal::bit_cast<fmt::internal::uintptr_t>(
reinterpret_cast<void*>(0xface)), reinterpret_cast<void*>(0xface)),
FMT_NULL); nullptr);
EXPECT_EQ("0xface", to_string(buf)); EXPECT_EQ("0xface", to_string(buf));
} }

View File

@ -63,16 +63,12 @@ TEST(FormatterTest, TestFormattersEnabled) {
unsigned short, int, unsigned, long, unsigned long, unsigned short, int, unsigned, long, unsigned long,
long long, unsigned long long, float, double, long long, unsigned long long, float, double,
long double, void*, const void*, char*, const char*, long double, void*, const void*, char*, const char*,
std::string>(); std::string, std::nullptr_t>();
check_enabled_formatters<wchar_t, bool, wchar_t, signed char, unsigned char, check_enabled_formatters<wchar_t, bool, wchar_t, signed char, unsigned char,
short, unsigned short, int, unsigned, long, short, unsigned short, int, unsigned, long,
unsigned long, long long, unsigned long long, float, unsigned long, long long, unsigned long long, float,
double, long double, void*, const void*, wchar_t*, double, long double, void*, const void*, wchar_t*,
const wchar_t*, std::wstring>(); const wchar_t*, std::wstring, std::nullptr_t>();
# if FMT_USE_NULLPTR
check_enabled_formatters<char, std::nullptr_t>();
check_enabled_formatters<wchar_t, std::nullptr_t>();
# endif
} }
#endif #endif
@ -192,7 +188,7 @@ TEST(IteratorTest, CountingIterator) {
} }
TEST(IteratorTest, TruncatingIterator) { TEST(IteratorTest, TruncatingIterator) {
char* p = FMT_NULL; char* p = nullptr;
fmt::internal::truncating_iterator<char*> it(p, 3); fmt::internal::truncating_iterator<char*> it(p, 3);
auto prev = it++; auto prev = it++;
EXPECT_EQ(prev.base(), p); EXPECT_EQ(prev.base(), p);
@ -254,7 +250,7 @@ TEST(AllocatorTest, allocator_ref) {
test_allocator_ref ref2(ref); test_allocator_ref ref2(ref);
check_forwarding(alloc, ref2); check_forwarding(alloc, ref2);
test_allocator_ref ref3; test_allocator_ref ref3;
EXPECT_EQ(FMT_NULL, ref3.get()); EXPECT_EQ(nullptr, ref3.get());
ref3 = ref; ref3 = ref;
check_forwarding(alloc, ref3); check_forwarding(alloc, ref3);
} }
@ -270,7 +266,7 @@ static void check_move_buffer(
EXPECT_EQ(str, std::string(&buffer2[0], buffer2.size())); EXPECT_EQ(str, std::string(&buffer2[0], buffer2.size()));
EXPECT_EQ(5u, buffer2.capacity()); EXPECT_EQ(5u, buffer2.capacity());
// Move should transfer allocator. // Move should transfer allocator.
EXPECT_EQ(FMT_NULL, buffer.get_allocator().get()); EXPECT_EQ(nullptr, buffer.get_allocator().get());
EXPECT_EQ(alloc, buffer2.get_allocator().get()); EXPECT_EQ(alloc, buffer2.get_allocator().get());
} }
@ -353,7 +349,7 @@ TEST(MemoryBufferTest, Grow) {
TEST(MemoryBufferTest, Allocator) { TEST(MemoryBufferTest, Allocator) {
typedef allocator_ref<mock_allocator<char>> TestAllocator; typedef allocator_ref<mock_allocator<char>> TestAllocator;
basic_memory_buffer<char, 10, TestAllocator> buffer; basic_memory_buffer<char, 10, TestAllocator> buffer;
EXPECT_EQ(FMT_NULL, buffer.get_allocator().get()); EXPECT_EQ(nullptr, buffer.get_allocator().get());
StrictMock<mock_allocator<char>> alloc; StrictMock<mock_allocator<char>> alloc;
char mem; char mem;
{ {
@ -493,7 +489,7 @@ TEST(UtilTest, FormatSystemError) {
fmt::print("warning: std::allocator allocates {} chars", max_size); fmt::print("warning: std::allocator allocates {} chars", max_size);
return; return;
} }
fmt::format_system_error(message, EDOM, fmt::string_view(FMT_NULL, max_size)); fmt::format_system_error(message, EDOM, fmt::string_view(nullptr, max_size));
EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message)); EXPECT_EQ(fmt::format("error {}", EDOM), to_string(message));
} }
@ -1548,7 +1544,7 @@ TEST(FormatterTest, FormatCString) {
EXPECT_EQ("test", format("{0:s}", "test")); EXPECT_EQ("test", format("{0:s}", "test"));
char nonconst[] = "nonconst"; char nonconst[] = "nonconst";
EXPECT_EQ("nonconst", format("{0}", nonconst)); EXPECT_EQ("nonconst", format("{0}", nonconst));
EXPECT_THROW_MSG(format("{0}", static_cast<const char*>(FMT_NULL)), EXPECT_THROW_MSG(format("{0}", static_cast<const char*>(nullptr)),
format_error, "string pointer is null"); format_error, "string pointer is null");
} }
@ -1570,7 +1566,7 @@ TEST(FormatterTest, FormatUCharString) {
TEST(FormatterTest, FormatPointer) { TEST(FormatterTest, FormatPointer) {
check_unknown_types(reinterpret_cast<void*>(0x1234), "p", "pointer"); check_unknown_types(reinterpret_cast<void*>(0x1234), "p", "pointer");
EXPECT_EQ("0x0", format("{0}", static_cast<void*>(FMT_NULL))); EXPECT_EQ("0x0", format("{0}", static_cast<void*>(nullptr)));
EXPECT_EQ("0x1234", format("{0}", reinterpret_cast<void*>(0x1234))); EXPECT_EQ("0x1234", format("{0}", reinterpret_cast<void*>(0x1234)));
EXPECT_EQ("0x1234", format("{0:p}", reinterpret_cast<void*>(0x1234))); EXPECT_EQ("0x1234", format("{0:p}", reinterpret_cast<void*>(0x1234)));
EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'), EXPECT_EQ("0x" + std::string(sizeof(void*) * CHAR_BIT / 4, 'f'),
@ -1581,7 +1577,7 @@ TEST(FormatterTest, FormatPointer) {
std::shared_ptr<int> sp(new int(1)); std::shared_ptr<int> sp(new int(1));
EXPECT_EQ(format("{}", fmt::ptr(sp.get())), format("{}", fmt::ptr(sp))); EXPECT_EQ(format("{}", fmt::ptr(sp.get())), format("{}", fmt::ptr(sp)));
#if FMT_USE_NULLPTR #if FMT_USE_NULLPTR
EXPECT_EQ("0x0", format("{}", FMT_NULL)); EXPECT_EQ("0x0", format("{}", nullptr));
#endif #endif
} }
@ -1674,7 +1670,7 @@ TEST(FormatterTest, FormatExamples) {
FILE* ftest = safe_fopen(filename, "r"); FILE* ftest = safe_fopen(filename, "r");
if (ftest) fclose(ftest); if (ftest) fclose(ftest);
int error_code = errno; int error_code = errno;
EXPECT_TRUE(ftest == FMT_NULL); EXPECT_TRUE(ftest == nullptr);
EXPECT_SYSTEM_ERROR( EXPECT_SYSTEM_ERROR(
{ {
FILE* f = safe_fopen(filename, "r"); FILE* f = safe_fopen(filename, "r");
@ -1905,7 +1901,7 @@ class mock_arg_formatter
typedef buffer_range range; typedef buffer_range range;
mock_arg_formatter(fmt::format_context& ctx, fmt::format_parse_context*, mock_arg_formatter(fmt::format_context& ctx, fmt::format_parse_context*,
fmt::format_specs* s = FMT_NULL) fmt::format_specs* s = nullptr)
: base(fmt::internal::get_container(ctx.out()), s, ctx.locale()) { : base(fmt::internal::get_container(ctx.out()), s, ctx.locale()) {
EXPECT_CALL(*this, call(42)); EXPECT_CALL(*this, call(42));
} }
@ -2170,8 +2166,8 @@ struct test_parse_context {
FMT_CONSTEXPR unsigned next_arg_id() { return 11; } FMT_CONSTEXPR unsigned next_arg_id() { return 11; }
template <typename Id> FMT_CONSTEXPR void check_arg_id(Id) {} template <typename Id> FMT_CONSTEXPR void check_arg_id(Id) {}
FMT_CONSTEXPR const char* begin() { return FMT_NULL; } FMT_CONSTEXPR const char* begin() { return nullptr; }
FMT_CONSTEXPR const char* end() { return FMT_NULL; } FMT_CONSTEXPR const char* end() { return nullptr; }
void on_error(const char*) {} void on_error(const char*) {}
}; };
@ -2337,7 +2333,7 @@ FMT_CONSTEXPR bool equal(const char* s1, const char* s2) {
template <typename... Args> template <typename... Args>
FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) { FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
const char* actual_error = FMT_NULL; const char* actual_error = nullptr;
fmt::internal::do_check_format_string<char, test_error_handler, Args...>( fmt::internal::do_check_format_string<char, test_error_handler, Args...>(
string_view(fmt, len(fmt)), test_error_handler(actual_error)); string_view(fmt, len(fmt)), test_error_handler(actual_error));
return equal(actual_error, expected_error); return equal(actual_error, expected_error);
@ -2349,7 +2345,7 @@ FMT_CONSTEXPR bool test_error(const char* fmt, const char* expected_error) {
static_assert(test_error<__VA_ARGS__>(fmt, error), "") static_assert(test_error<__VA_ARGS__>(fmt, error), "")
TEST(FormatTest, FormatStringErrors) { TEST(FormatTest, FormatStringErrors) {
EXPECT_ERROR_NOARGS("foo", FMT_NULL); EXPECT_ERROR_NOARGS("foo", nullptr);
EXPECT_ERROR_NOARGS("}", "unmatched '}' in format string"); EXPECT_ERROR_NOARGS("}", "unmatched '}' in format string");
EXPECT_ERROR("{0:s", "unknown format specifier", Date); EXPECT_ERROR("{0:s", "unknown format specifier", Date);
# if FMT_MSC_VER >= 1916 # if FMT_MSC_VER >= 1916

View File

@ -53,6 +53,4 @@ TEST(GrisuTest, Prettify) {
EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6)); EXPECT_EQ("0.001234", fmt::format("{}", 1234e-6));
} }
TEST(GrisuTest, ZeroPrecision) { TEST(GrisuTest, ZeroPrecision) { EXPECT_EQ("1", fmt::format("{:.0}", 1.0)); }
EXPECT_EQ("1", fmt::format("{:.0}", 1.0));
}

View File

@ -54,7 +54,9 @@ void do_nothing() {}
FMT_NORETURN void throw_exception() { throw std::runtime_error("test"); } FMT_NORETURN void throw_exception() { throw std::runtime_error("test"); }
FMT_NORETURN void throw_system_error() { throw fmt::system_error(EDOM, "test"); } FMT_NORETURN void throw_system_error() {
throw fmt::system_error(EDOM, "test");
}
// Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument // Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument
// exactly once. // exactly once.
@ -355,10 +357,10 @@ TEST(OutputRedirectTest, FlushErrorInCtor) {
// Put a character in a file buffer. // Put a character in a file buffer.
EXPECT_EQ('x', fputc('x', f.get())); EXPECT_EQ('x', fputc('x', f.get()));
FMT_POSIX(close(write_fd)); FMT_POSIX(close(write_fd));
std::unique_ptr<OutputRedirect> redir{FMT_NULL}; std::unique_ptr<OutputRedirect> redir{nullptr};
EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())), EBADF, EXPECT_SYSTEM_ERROR_NOASSERT(redir.reset(new OutputRedirect(f.get())), EBADF,
"cannot flush stream"); "cannot flush stream");
redir.reset(FMT_NULL); redir.reset(nullptr);
write_copy.dup2(write_fd); // "undo" close or dtor will fail write_copy.dup2(write_fd); // "undo" close or dtor will fail
} }
@ -367,7 +369,7 @@ TEST(OutputRedirectTest, DupErrorInCtor) {
int fd = (f.fileno)(); int fd = (f.fileno)();
file copy = file::dup(fd); file copy = file::dup(fd);
FMT_POSIX(close(fd)); FMT_POSIX(close(fd));
std::unique_ptr<OutputRedirect> redir{FMT_NULL}; std::unique_ptr<OutputRedirect> redir{nullptr};
EXPECT_SYSTEM_ERROR_NOASSERT( EXPECT_SYSTEM_ERROR_NOASSERT(
redir.reset(new OutputRedirect(f.get())), EBADF, redir.reset(new OutputRedirect(f.get())), EBADF,
fmt::format("cannot duplicate file descriptor {}", fd)); fmt::format("cannot duplicate file descriptor {}", fd));
@ -420,7 +422,7 @@ TEST(OutputRedirectTest, ErrorInDtor) {
// redirecting the output in EXPECT_STDERR and the second close // redirecting the output in EXPECT_STDERR and the second close
// will break output redirection. // will break output redirection.
FMT_POSIX(close(write_fd)); FMT_POSIX(close(write_fd));
SUPPRESS_ASSERT(redir.reset(FMT_NULL)); SUPPRESS_ASSERT(redir.reset(nullptr));
}, },
format_system_error(EBADF, "cannot flush stream")); format_system_error(EBADF, "cannot flush stream"));
write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail write_copy.dup2(write_fd); // "undo" close or dtor of buffered_file will fail

View File

@ -155,7 +155,7 @@ std::string read(fmt::file& f, std::size_t count);
template <typename Mock> struct ScopedMock : testing::StrictMock<Mock> { template <typename Mock> struct ScopedMock : testing::StrictMock<Mock> {
ScopedMock() { Mock::instance = this; } ScopedMock() { Mock::instance = this; }
~ScopedMock() { Mock::instance = FMT_NULL; } ~ScopedMock() { Mock::instance = nullptr; }
}; };
#endif // FMT_GTEST_EXTRA_H_ #endif // FMT_GTEST_EXTRA_H_

View File

@ -26,13 +26,13 @@ template <typename Allocator> class allocator_ref {
void move(allocator_ref& other) { void move(allocator_ref& other) {
alloc_ = other.alloc_; alloc_ = other.alloc_;
other.alloc_ = FMT_NULL; other.alloc_ = nullptr;
} }
public: public:
typedef typename Allocator::value_type value_type; typedef typename Allocator::value_type value_type;
explicit allocator_ref(Allocator* alloc = FMT_NULL) : alloc_(alloc) {} explicit allocator_ref(Allocator* alloc = nullptr) : alloc_(alloc) {}
allocator_ref(const allocator_ref& other) : alloc_(other.alloc_) {} allocator_ref(const allocator_ref& other) : alloc_(other.alloc_) {}
allocator_ref(allocator_ref&& other) { move(other); } allocator_ref(allocator_ref&& other) { move(other); }

View File

@ -167,7 +167,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
} os(streambuf); } os(streambuf);
testing::InSequence sequence; testing::InSequence sequence;
const char* data = FMT_NULL; const char* data = nullptr;
typedef std::make_unsigned<std::streamsize>::type ustreamsize; typedef std::make_unsigned<std::streamsize>::type ustreamsize;
ustreamsize size = max_size; ustreamsize size = max_size;
do { do {

View File

@ -131,7 +131,7 @@ int test::dup2(int fildes, int fildes2) {
} }
FILE* test::fdopen(int fildes, const char* mode) { FILE* test::fdopen(int fildes, const char* mode) {
EMULATE_EINTR(fdopen, FMT_NULL); EMULATE_EINTR(fdopen, nullptr);
return ::FMT_POSIX(fdopen(fildes, mode)); return ::FMT_POSIX(fdopen(fildes, mode));
} }
@ -160,7 +160,7 @@ int test::pipe(int* pfds, unsigned psize, int textmode) {
#endif #endif
FILE* test::fopen(const char* filename, const char* mode) { FILE* test::fopen(const char* filename, const char* mode) {
EMULATE_EINTR(fopen, FMT_NULL); EMULATE_EINTR(fopen, nullptr);
return ::fopen(filename, mode); return ::fopen(filename, mode);
} }
@ -214,7 +214,7 @@ TEST(UtilTest, GetPageSize) {
TEST(FileTest, OpenRetry) { TEST(FileTest, OpenRetry) {
write_file("test", "there must be something here"); write_file("test", "there must be something here");
std::unique_ptr<file> f{FMT_NULL}; std::unique_ptr<file> f{nullptr};
EXPECT_RETRY(f.reset(new file("test", file::RDONLY)), open, EXPECT_RETRY(f.reset(new file("test", file::RDONLY)), open,
"cannot open file test"); "cannot open file test");
#ifndef _WIN32 #ifndef _WIN32
@ -231,7 +231,7 @@ TEST(FileTest, CloseNoRetryInDtor) {
EXPECT_WRITE(stderr, EXPECT_WRITE(stderr,
{ {
close_count = 1; close_count = 1;
f.reset(FMT_NULL); f.reset(nullptr);
saved_close_count = close_count; saved_close_count = close_count;
close_count = 0; close_count = 0;
}, },
@ -384,7 +384,7 @@ TEST(FileTest, FdopenNoRetry) {
TEST(BufferedFileTest, OpenRetry) { TEST(BufferedFileTest, OpenRetry) {
write_file("test", "there must be something here"); write_file("test", "there must be something here");
std::unique_ptr<buffered_file> f{FMT_NULL}; std::unique_ptr<buffered_file> f{nullptr};
EXPECT_RETRY(f.reset(new buffered_file("test", "r")), fopen, EXPECT_RETRY(f.reset(new buffered_file("test", "r")), fopen,
"cannot open file test"); "cannot open file test");
#ifndef _WIN32 #ifndef _WIN32
@ -402,7 +402,7 @@ TEST(BufferedFileTest, CloseNoRetryInDtor) {
EXPECT_WRITE(stderr, EXPECT_WRITE(stderr,
{ {
fclose_count = 1; fclose_count = 1;
f.reset(FMT_NULL); f.reset(nullptr);
saved_fclose_count = fclose_count; saved_fclose_count = fclose_count;
fclose_count = 0; fclose_count = 0;
}, },
@ -441,7 +441,7 @@ TEST(ScopedMock, Scope) {
TestMock& copy = mock; TestMock& copy = mock;
static_cast<void>(copy); static_cast<void>(copy);
} }
EXPECT_EQ(FMT_NULL, TestMock::instance); EXPECT_EQ(nullptr, TestMock::instance);
} }
#ifdef FMT_LOCALE #ifdef FMT_LOCALE
@ -526,7 +526,7 @@ TEST(LocaleTest, Locale) {
# endif # endif
ScopedMock<LocaleMock> mock; ScopedMock<LocaleMock> mock;
LocaleType impl = reinterpret_cast<LocaleType>(42); LocaleType impl = reinterpret_cast<LocaleType>(42);
EXPECT_CALL(mock, newlocale(LC_NUMERIC_MASK, StrEq("C"), FMT_NULL)) EXPECT_CALL(mock, newlocale(LC_NUMERIC_MASK, StrEq("C"), nullptr))
.WillOnce(Return(impl)); .WillOnce(Return(impl));
EXPECT_CALL(mock, freelocale(impl)); EXPECT_CALL(mock, freelocale(impl));
fmt::Locale locale; fmt::Locale locale;

View File

@ -58,26 +58,26 @@ static void write(file& f, fmt::string_view s) {
TEST(BufferedFileTest, DefaultCtor) { TEST(BufferedFileTest, DefaultCtor) {
buffered_file f; buffered_file f;
EXPECT_TRUE(f.get() == FMT_NULL); EXPECT_TRUE(f.get() == nullptr);
} }
TEST(BufferedFileTest, MoveCtor) { TEST(BufferedFileTest, MoveCtor) {
buffered_file bf = open_buffered_file(); buffered_file bf = open_buffered_file();
FILE* fp = bf.get(); FILE* fp = bf.get();
EXPECT_TRUE(fp != FMT_NULL); EXPECT_TRUE(fp != nullptr);
buffered_file bf2(std::move(bf)); buffered_file bf2(std::move(bf));
EXPECT_EQ(fp, bf2.get()); EXPECT_EQ(fp, bf2.get());
EXPECT_TRUE(bf.get() == FMT_NULL); EXPECT_TRUE(bf.get() == nullptr);
} }
TEST(BufferedFileTest, MoveAssignment) { TEST(BufferedFileTest, MoveAssignment) {
buffered_file bf = open_buffered_file(); buffered_file bf = open_buffered_file();
FILE* fp = bf.get(); FILE* fp = bf.get();
EXPECT_TRUE(fp != FMT_NULL); EXPECT_TRUE(fp != nullptr);
buffered_file bf2; buffered_file bf2;
bf2 = std::move(bf); bf2 = std::move(bf);
EXPECT_EQ(fp, bf2.get()); EXPECT_EQ(fp, bf2.get());
EXPECT_TRUE(bf.get() == FMT_NULL); EXPECT_TRUE(bf.get() == nullptr);
} }
TEST(BufferedFileTest, MoveAssignmentClosesFile) { TEST(BufferedFileTest, MoveAssignmentClosesFile) {
@ -89,13 +89,13 @@ TEST(BufferedFileTest, MoveAssignmentClosesFile) {
} }
TEST(BufferedFileTest, MoveFromTemporaryInCtor) { TEST(BufferedFileTest, MoveFromTemporaryInCtor) {
FILE* fp = FMT_NULL; FILE* fp = nullptr;
buffered_file f(open_buffered_file(&fp)); buffered_file f(open_buffered_file(&fp));
EXPECT_EQ(fp, f.get()); EXPECT_EQ(fp, f.get());
} }
TEST(BufferedFileTest, MoveFromTemporaryInAssignment) { TEST(BufferedFileTest, MoveFromTemporaryInAssignment) {
FILE* fp = FMT_NULL; FILE* fp = nullptr;
buffered_file f; buffered_file f;
f = open_buffered_file(&fp); f = open_buffered_file(&fp);
EXPECT_EQ(fp, f.get()); EXPECT_EQ(fp, f.get());
@ -126,7 +126,7 @@ TEST(BufferedFileTest, CloseErrorInDtor) {
// redirecting the output in EXPECT_STDERR and the second close // redirecting the output in EXPECT_STDERR and the second close
// will break output redirection. // will break output redirection.
FMT_POSIX(close(f->fileno())); FMT_POSIX(close(f->fileno()));
SUPPRESS_ASSERT(f.reset(FMT_NULL)); SUPPRESS_ASSERT(f.reset(nullptr));
}, },
format_system_error(EBADF, "cannot close file") + "\n"); format_system_error(EBADF, "cannot close file") + "\n");
} }
@ -135,7 +135,7 @@ TEST(BufferedFileTest, Close) {
buffered_file f = open_buffered_file(); buffered_file f = open_buffered_file();
int fd = f.fileno(); int fd = f.fileno();
f.close(); f.close();
EXPECT_TRUE(f.get() == FMT_NULL); EXPECT_TRUE(f.get() == nullptr);
EXPECT_TRUE(isclosed(fd)); EXPECT_TRUE(isclosed(fd));
} }
@ -143,7 +143,7 @@ TEST(BufferedFileTest, CloseError) {
buffered_file f = open_buffered_file(); buffered_file f = open_buffered_file();
FMT_POSIX(close(f.fileno())); FMT_POSIX(close(f.fileno()));
EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file"); EXPECT_SYSTEM_ERROR_NOASSERT(f.close(), EBADF, "cannot close file");
EXPECT_TRUE(f.get() == FMT_NULL); EXPECT_TRUE(f.get() == nullptr);
} }
TEST(BufferedFileTest, Fileno) { TEST(BufferedFileTest, Fileno) {
@ -257,7 +257,7 @@ TEST(FileTest, CloseErrorInDtor) {
// redirecting the output in EXPECT_STDERR and the second close // redirecting the output in EXPECT_STDERR and the second close
// will break output redirection. // will break output redirection.
FMT_POSIX(close(f->descriptor())); FMT_POSIX(close(f->descriptor()));
SUPPRESS_ASSERT(f.reset(FMT_NULL)); SUPPRESS_ASSERT(f.reset(nullptr));
}, },
format_system_error(EBADF, "cannot close file") + "\n"); format_system_error(EBADF, "cannot close file") + "\n");
} }

View File

@ -620,7 +620,7 @@ template <typename T> struct user_allocator {
pointer allocate( pointer allocate(
size_type cnt, size_type cnt,
typename std::allocator<fmt::monostate>::const_pointer = FMT_NULL) { typename std::allocator<fmt::monostate>::const_pointer = nullptr) {
return new value_type[cnt]; return new value_type[cnt];
} }

View File

@ -434,11 +434,11 @@ TEST(PrintfTest, Char) {
TEST(PrintfTest, String) { TEST(PrintfTest, String) {
EXPECT_PRINTF("abc", "%s", "abc"); EXPECT_PRINTF("abc", "%s", "abc");
const char* null_str = FMT_NULL; const char* null_str = nullptr;
EXPECT_PRINTF("(null)", "%s", null_str); EXPECT_PRINTF("(null)", "%s", null_str);
EXPECT_PRINTF(" (null)", "%10s", null_str); EXPECT_PRINTF(" (null)", "%10s", null_str);
EXPECT_PRINTF(L"abc", L"%s", L"abc"); EXPECT_PRINTF(L"abc", L"%s", L"abc");
const wchar_t* null_wstr = FMT_NULL; const wchar_t* null_wstr = nullptr;
EXPECT_PRINTF(L"(null)", L"%s", null_wstr); EXPECT_PRINTF(L"(null)", L"%s", null_wstr);
EXPECT_PRINTF(L" (null)", L"%10s", null_wstr); EXPECT_PRINTF(L" (null)", L"%10s", null_wstr);
} }
@ -447,22 +447,22 @@ TEST(PrintfTest, Pointer) {
int n; int n;
void* p = &n; void* p = &n;
EXPECT_PRINTF(fmt::format("{}", p), "%p", p); EXPECT_PRINTF(fmt::format("{}", p), "%p", p);
p = FMT_NULL; p = nullptr;
EXPECT_PRINTF("(nil)", "%p", p); EXPECT_PRINTF("(nil)", "%p", p);
EXPECT_PRINTF(" (nil)", "%10p", p); EXPECT_PRINTF(" (nil)", "%10p", p);
const char* s = "test"; const char* s = "test";
EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s); EXPECT_PRINTF(fmt::format("{:p}", s), "%p", s);
const char* null_str = FMT_NULL; const char* null_str = nullptr;
EXPECT_PRINTF("(nil)", "%p", null_str); EXPECT_PRINTF("(nil)", "%p", null_str);
p = &n; p = &n;
EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p); EXPECT_PRINTF(fmt::format(L"{}", p), L"%p", p);
p = FMT_NULL; p = nullptr;
EXPECT_PRINTF(L"(nil)", L"%p", p); EXPECT_PRINTF(L"(nil)", L"%p", p);
EXPECT_PRINTF(L" (nil)", L"%10p", p); EXPECT_PRINTF(L" (nil)", L"%10p", p);
const wchar_t* w = L"test"; const wchar_t* w = L"test";
EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w); EXPECT_PRINTF(fmt::format(L"{:p}", w), L"%p", w);
const wchar_t* null_wstr = FMT_NULL; const wchar_t* null_wstr = nullptr;
EXPECT_PRINTF(L"(nil)", L"%p", null_wstr); EXPECT_PRINTF(L"(nil)", L"%p", null_wstr);
} }

View File

@ -50,8 +50,10 @@ TEST(StdFormatTest, Float) {
double nan = numeric_limits<double>::quiet_NaN(); double nan = numeric_limits<double>::quiet_NaN();
string s0 = format("{0:} {0:+} {0:-} {0: }", 1); // s0 == "1 +1 1 1" string s0 = format("{0:} {0:+} {0:-} {0: }", 1); // s0 == "1 +1 1 1"
string s1 = format("{0:} {0:+} {0:-} {0: }", -1); // s1 == "-1 -1 -1 -1" string s1 = format("{0:} {0:+} {0:-} {0: }", -1); // s1 == "-1 -1 -1 -1"
string s2 = format("{0:} {0:+} {0:-} {0: }", inf); // s2 == "inf +inf inf inf" string s2 =
string s3 = format("{0:} {0:+} {0:-} {0: }", nan); // s3 == "nan +nan nan nan" format("{0:} {0:+} {0:-} {0: }", inf); // s2 == "inf +inf inf inf"
string s3 =
format("{0:} {0:+} {0:-} {0: }", nan); // s3 == "nan +nan nan nan"
EXPECT_EQ(s0, "1 +1 1 1"); EXPECT_EQ(s0, "1 +1 1 1");
EXPECT_EQ(s1, "-1 -1 -1 -1"); EXPECT_EQ(s1, "-1 -1 -1 -1");
EXPECT_EQ(s2, "inf +inf inf inf"); EXPECT_EQ(s2, "inf +inf inf inf");
@ -74,9 +76,9 @@ TEST(StdFormatTest, Int) {
enum color { red, green, blue }; enum color { red, green, blue };
const char* color_names[] = { "red", "green", "blue" }; const char* color_names[] = {"red", "green", "blue"};
template<> struct std::formatter<color> : std::formatter<const char*> { template <> struct std::formatter<color> : std::formatter<const char*> {
auto format(color c, format_context& ctx) { auto format(color c, format_context& ctx) {
return formatter<const char*>::format(color_names[c], ctx); return formatter<const char*>::format(color_names[c], ctx);
} }
@ -86,9 +88,11 @@ struct err {};
TEST(StdFormatTest, Formatter) { TEST(StdFormatTest, Formatter) {
std::string s0 = std::format("{}", 42); // OK: library-provided formatter std::string s0 = std::format("{}", 42); // OK: library-provided formatter
//std::string s1 = std::format("{}", L"foo"); // Ill-formed: disabled formatter // std::string s1 = std::format("{}", L"foo"); // Ill-formed: disabled
// formatter
std::string s2 = std::format("{}", red); // OK: user-provided formatter std::string s2 = std::format("{}", red); // OK: user-provided formatter
//std::string s3 = std::format("{}", err{}); // Ill-formed: disabled formatter // std::string s3 = std::format("{}", err{}); // Ill-formed: disabled
// formatter
EXPECT_EQ(s0, "42"); EXPECT_EQ(s0, "42");
EXPECT_EQ(s2, "red"); EXPECT_EQ(s2, "red");
} }
@ -97,15 +101,14 @@ struct S {
int value; int value;
}; };
template<> struct std::formatter<S> { template <> struct std::formatter<S> {
size_t width_arg_id = 0; size_t width_arg_id = 0;
// Parses a width argument id in the format { <digit> }. // Parses a width argument id in the format { <digit> }.
constexpr auto parse(format_parse_context& ctx) { constexpr auto parse(format_parse_context& ctx) {
auto iter = ctx.begin(); auto iter = ctx.begin();
auto get_char = [&]() { return iter != ctx.end() ? *iter : 0; }; auto get_char = [&]() { return iter != ctx.end() ? *iter : 0; };
if (get_char() != '{') if (get_char() != '{') return iter;
return iter;
++iter; ++iter;
char c = get_char(); char c = get_char();
if (!isdigit(c) || (++iter, get_char()) != '}') if (!isdigit(c) || (++iter, get_char()) != '}')
@ -117,14 +120,16 @@ template<> struct std::formatter<S> {
// Formats S with width given by the argument width_arg_id. // Formats S with width given by the argument width_arg_id.
auto format(S s, format_context& ctx) { auto format(S s, format_context& ctx) {
int width = visit_format_arg([](auto value) -> int { int width = visit_format_arg(
[](auto value) -> int {
if constexpr (!is_integral_v<decltype(value)>) if constexpr (!is_integral_v<decltype(value)>)
throw format_error("width is not integral"); throw format_error("width is not integral");
else if (value < 0 || value > numeric_limits<int>::max()) else if (value < 0 || value > numeric_limits<int>::max())
throw format_error("invalid width"); throw format_error("invalid width");
else else
return value; return value;
}, ctx.arg(width_arg_id)); },
ctx.arg(width_arg_id));
return format_to(ctx.out(), "{0:{1}}", s.value, width); return format_to(ctx.out(), "{0:{1}}", s.value, width);
} }
}; };

View File

@ -35,7 +35,7 @@ std::string get_system_error(int error_code);
extern const char* const FILE_CONTENT; extern const char* const FILE_CONTENT;
// Opens a buffered file for reading. // Opens a buffered file for reading.
fmt::buffered_file open_buffered_file(FILE** fp = FMT_NULL); fmt::buffered_file open_buffered_file(FILE** fp = nullptr);
inline FILE* safe_fopen(const char* filename, const char* mode) { inline FILE* safe_fopen(const char* filename, const char* mode) {
#if defined(_WIN32) && !defined(__MINGW32__) #if defined(_WIN32) && !defined(__MINGW32__)