diff --git a/include/fmt/core.h b/include/fmt/core.h index 900d0464..8959dac9 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -31,6 +31,16 @@ # define FMT_MSC_VER 0 #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 +# else +# define FMT_NULL NULL +# endif +#endif + // Check if exceptions are disabled. #if defined(__GNUC__) && !defined(__EXCEPTIONS) # define FMT_EXCEPTIONS 0 @@ -211,7 +221,7 @@ class basic_buffer { std::size_t capacity_; protected: - basic_buffer(T *p = 0, std::size_t size = 0, std::size_t capacity = 0) + basic_buffer(T *p = FMT_NULL, std::size_t size = 0, std::size_t capacity = 0) FMT_NOEXCEPT: ptr_(p), size_(size), capacity_(capacity) {} /** Sets the buffer data and capacity. */ diff --git a/include/fmt/format.cc b/include/fmt/format.cc index 15702a0c..57f68185 100644 --- a/include/fmt/format.cc +++ b/include/fmt/format.cc @@ -154,7 +154,8 @@ int safe_strerror( : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} int run() { - strerror_r(0, 0, ""); // Suppress a warning about unused strerror_r. + // Suppress a warning about unused strerror_r. + strerror_r(0, FMT_NULL, ""); return handle(strerror_r(error_code_, buffer_, buffer_size_)); } }; @@ -282,7 +283,7 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) { FMT_THROW(windows_error(ERROR_INVALID_PARAMETER, ERROR_MSG)); int s_size = static_cast(s.size()); int length = MultiByteToWideChar( - CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, 0, 0); + CP_UTF8, MB_ERR_INVALID_CHARS, s.data(), s_size, FMT_NULL, 0); if (length == 0) FMT_THROW(windows_error(GetLastError(), ERROR_MSG)); buffer_.resize(length + 1); @@ -304,12 +305,13 @@ FMT_FUNC int internal::utf16_to_utf8::convert(wstring_view s) { if (s.size() > INT_MAX) return ERROR_INVALID_PARAMETER; int s_size = static_cast(s.size()); - int length = WideCharToMultiByte(CP_UTF8, 0, s.data(), s_size, 0, 0, 0, 0); + int length = WideCharToMultiByte( + CP_UTF8, 0, s.data(), s_size, FMT_NULL, 0, FMT_NULL, FMT_NULL); if (length == 0) return GetLastError(); buffer_.resize(length + 1); length = WideCharToMultiByte( - CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, 0, 0); + CP_UTF8, 0, s.data(), s_size, &buffer_[0], length, FMT_NULL, FMT_NULL); if (length == 0) return GetLastError(); buffer_[length] = 0; @@ -334,8 +336,8 @@ FMT_FUNC void internal::format_windows_error( wchar_t *system_message = &buf[0]; int result = FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - 0, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - system_message, static_cast(buf.size()), 0); + FMT_NULL, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + system_message, static_cast(buf.size()), FMT_NULL); if (result != 0) { utf16_to_utf8 utf8_message; if (utf8_message.convert(system_message) == ERROR_SUCCESS) { diff --git a/include/fmt/format.h b/include/fmt/format.h index b87826db..ac9af06f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2560,7 +2560,7 @@ void basic_writer::write_double(T value, const format_specs &spec) { // Format using snprintf. unsigned n = 0; - char_type *start = 0; + char_type *start = FMT_NULL; for (;;) { std::size_t buffer_size = buffer.capacity(); #if FMT_MSC_VER diff --git a/include/fmt/posix.cc b/include/fmt/posix.cc index 8cc42cd2..a3c076ca 100644 --- a/include/fmt/posix.cc +++ b/include/fmt/posix.cc @@ -77,7 +77,7 @@ void fmt::BufferedFile::close() { if (!file_) return; int result = FMT_SYSTEM(fclose(file_)); - file_ = 0; + file_ = FMT_NULL; if (result != 0) FMT_THROW(system_error(errno, "cannot close file")); } diff --git a/include/fmt/posix.h b/include/fmt/posix.h index 2cf838d7..42b27e92 100644 --- a/include/fmt/posix.h +++ b/include/fmt/posix.h @@ -156,7 +156,7 @@ public: // A "move constructor" for moving from an lvalue. BufferedFile(BufferedFile &f) FMT_NOEXCEPT : file_(f.file_) { - f.file_ = 0; + f.file_ = FMT_NULL; } // A "move assignment operator" for moving from a temporary. @@ -170,7 +170,7 @@ public: BufferedFile &operator=(BufferedFile &other) { close(); file_ = other.file_; - other.file_ = 0; + other.file_ = FMT_NULL; return *this; } @@ -178,7 +178,7 @@ public: // BufferedFile file = BufferedFile(...); operator Proxy() FMT_NOEXCEPT { Proxy p = {file_}; - file_ = 0; + file_ = FMT_NULL; return p; } @@ -188,13 +188,13 @@ public: public: BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_) { - other.file_ = 0; + other.file_ = FMT_NULL; } BufferedFile& operator=(BufferedFile &&other) { close(); file_ = other.file_; - other.file_ = 0; + other.file_ = FMT_NULL; return *this; } #endif @@ -386,7 +386,7 @@ class Locale { public: typedef locale_t Type; - Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) { + Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", FMT_NULL)) { if (!locale_) FMT_THROW(fmt::system_error(errno, "cannot create locale")); } @@ -397,7 +397,7 @@ class Locale { // Converts string to floating-point number and advances str past the end // of the parsed input. double strtod(const char *&str) const { - char *end = 0; + char *end = FMT_NULL; double result = strtod_l(str, &end, locale_); str = end; return result; diff --git a/include/fmt/time.h b/include/fmt/time.h index a33c0b30..08199425 100644 --- a/include/fmt/time.h +++ b/include/fmt/time.h @@ -33,7 +33,7 @@ inline std::tm localtime(std::time_t time) { return handle(localtime_r(&time_, &tm_)); } - bool handle(std::tm* tm) { return tm != 0; } + bool handle(std::tm *tm) { return tm != FMT_NULL; } bool handle(internal::null<>) { using namespace fmt::internal; @@ -44,9 +44,9 @@ inline std::tm localtime(std::time_t time) { bool fallback(internal::null<>) { using namespace fmt::internal; - std::tm* tm = std::localtime(&time_); - if (tm != 0) tm_ = *tm; - return tm != 0; + std::tm *tm = std::localtime(&time_); + if (tm) tm_ = *tm; + return tm != FMT_NULL; } }; LocalTime lt(time); @@ -70,7 +70,7 @@ inline std::tm gmtime(std::time_t time) { return handle(gmtime_r(&time_, &tm_)); } - bool handle(std::tm* tm) { return tm != 0; } + bool handle(std::tm *tm) { return tm != FMT_NULL; } bool handle(internal::null<>) { using namespace fmt::internal; @@ -80,9 +80,9 @@ inline std::tm gmtime(std::time_t time) { bool fallback(int res) { return res == 0; } bool fallback(internal::null<>) { - std::tm* tm = std::gmtime(&time_); - if (tm != 0) tm_ = *tm; - return tm != 0; + std::tm *tm = std::gmtime(&time_); + if (tm) tm_ = *tm; + return tm != FMT_NULL; } }; GMTime gt(time);