Revert changes of nullptr

This commit is contained in:
Carter Li 2015-02-13 23:14:04 +08:00
parent 651f8286b1
commit 2fb9ddafc6
5 changed files with 14 additions and 31 deletions

View File

@ -117,14 +117,6 @@ if (NOT FMT_VARIADIC_TEMPLATES)
add_definitions(-DGTEST_LANG_CXX11=0) add_definitions(-DGTEST_LANG_CXX11=0)
endif () endif ()
# g++ 4.6 supports nullptr with __cplusplus==1
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773
check_cxx_source_compiles("
int main(){int*p=nullptr;}" FMT_NULLPTR)
if (FMT_NULLPTR)
# add_definitions(-DFMT_USE_NULLPTR=1)
endif ()
check_cxx_source_compiles(" check_cxx_source_compiles("
struct C{ struct C{
C()=delete; C()=delete;

View File

@ -147,7 +147,7 @@ typedef void (*FormatFunc)(fmt::Writer &, int, fmt::StringRef);
// Buffer should be at least of size 1. // Buffer should be at least of size 1.
int safe_strerror( int safe_strerror(
int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT { int error_code, char *&buffer, std::size_t buffer_size) FMT_NOEXCEPT {
assert(buffer != nullptr && buffer_size != 0); assert(buffer != 0 && buffer_size != 0);
int result = 0; int result = 0;
#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || __ANDROID__ #if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || __ANDROID__
// XSI-compliant version of strerror_r. // XSI-compliant version of strerror_r.
@ -457,7 +457,7 @@ FMT_FUNC void fmt::internal::report_unknown_type(char code, const char *type) {
FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) { FMT_FUNC fmt::internal::UTF8ToUTF16::UTF8ToUTF16(fmt::StringRef s) {
int length = MultiByteToWideChar( int length = MultiByteToWideChar(
CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, nullptr, 0); CP_UTF8, MB_ERR_INVALID_CHARS, s.c_str(), -1, 0, 0);
static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16"; static const char ERROR_MSG[] = "cannot convert string from UTF-8 to UTF-16";
if (length == 0) if (length == 0)
FMT_THROW(WindowsError(GetLastError(), ERROR_MSG)); FMT_THROW(WindowsError(GetLastError(), ERROR_MSG));
@ -476,12 +476,12 @@ FMT_FUNC fmt::internal::UTF16ToUTF8::UTF16ToUTF8(fmt::WStringRef s) {
} }
FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) { FMT_FUNC int fmt::internal::UTF16ToUTF8::convert(fmt::WStringRef s) {
int length = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, nullptr, 0, nullptr, nullptr); int length = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, 0, 0, 0, 0);
if (length == 0) if (length == 0)
return GetLastError(); return GetLastError();
buffer_.resize(length); buffer_.resize(length);
length = WideCharToMultiByte( length = WideCharToMultiByte(
CP_UTF8, 0, s.c_str(), -1, &buffer_[0], length, nullptr, nullptr); CP_UTF8, 0, s.c_str(), -1, &buffer_[0], length, 0, 0);
if (length == 0) if (length == 0)
return GetLastError(); return GetLastError();
return 0; return 0;
@ -536,9 +536,9 @@ FMT_FUNC void fmt::internal::format_windows_error(
FMT_TRY { FMT_TRY {
String system_message; String system_message;
if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | if (FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0,
error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
reinterpret_cast<LPWSTR>(system_message.ptr()), 0, nullptr)) { reinterpret_cast<LPWSTR>(system_message.ptr()), 0, 0)) {
UTF16ToUTF8 utf8_message; UTF16ToUTF8 utf8_message;
if (utf8_message.convert(system_message.c_str()) == ERROR_SUCCESS) { if (utf8_message.convert(system_message.c_str()) == ERROR_SUCCESS) {
out << message << ": " << utf8_message; out << message << ": " << utf8_message;
@ -648,7 +648,7 @@ void fmt::BasicWriter<Char>::write_str(
template <typename Char> template <typename Char>
inline Arg fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) { inline Arg fmt::BasicFormatter<Char>::parse_arg_index(const Char *&s) {
const char *error = nullptr; const char *error = 0;
Arg arg = *s < '0' || *s > '9' ? Arg arg = *s < '0' || *s > '9' ?
next_arg(error) : get_arg(parse_nonnegative_int(s), error); next_arg(error) : get_arg(parse_nonnegative_int(s), error);
if (error) { if (error) {
@ -713,7 +713,7 @@ void fmt::internal::PrintfFormatter<Char>::parse_flags(
template <typename Char> template <typename Char>
Arg fmt::internal::PrintfFormatter<Char>::get_arg( Arg fmt::internal::PrintfFormatter<Char>::get_arg(
const Char *s, unsigned arg_index) { const Char *s, unsigned arg_index) {
const char *error = nullptr; const char *error = 0;
Arg arg = arg_index == UINT_MAX ? Arg arg = arg_index == UINT_MAX ?
next_arg(error) : FormatterBase::get_arg(arg_index - 1, error); next_arg(error) : FormatterBase::get_arg(arg_index - 1, error);
if (error) if (error)

View File

@ -133,15 +133,6 @@
TypeName& operator=(const TypeName&) TypeName& operator=(const TypeName&)
#endif #endif
#if FMT_USE_NULLPTR || FMT_HAS_FEATURE(cxx_nullptr)\
|| (FMT_GCC_VERSION >= 406 && __cplusplus >= 201103L)\
|| (_MSC_VER >= 1600)
// Use nullptr
#elif !defined(nullptr)
// Some standard library implementations define nullptr themselves such as libc++
# define nullptr 0
#endif
namespace fmt { namespace fmt {
// Fix the warning about long long on older versions of GCC // Fix the warning about long long on older versions of GCC
@ -280,7 +271,7 @@ class Buffer {
std::size_t size_; std::size_t size_;
std::size_t capacity_; std::size_t capacity_;
Buffer(T *ptr = nullptr, std::size_t capacity = 0) Buffer(T *ptr = 0, std::size_t capacity = 0)
: ptr_(ptr), size_(0), capacity_(capacity) {} : ptr_(ptr), size_(0), capacity_(capacity) {}
virtual void grow(std::size_t size) = 0; virtual void grow(std::size_t size) = 0;

View File

@ -92,7 +92,7 @@ void fmt::BufferedFile::close() {
if (!file_) if (!file_)
return; return;
int result = FMT_SYSTEM(fclose(file_)); int result = FMT_SYSTEM(fclose(file_));
file_ = nullptr; file_ = 0;
if (result != 0) if (result != 0)
throw SystemError(errno, "cannot close file"); throw SystemError(errno, "cannot close file");
} }

View File

@ -113,7 +113,7 @@ class BufferedFile {
public: public:
// Constructs a BufferedFile object which doesn't represent any file. // Constructs a BufferedFile object which doesn't represent any file.
BufferedFile() FMT_NOEXCEPT : file_(nullptr) {} BufferedFile() FMT_NOEXCEPT : file_(0) {}
// Destroys the object closing the file it represents if any. // Destroys the object closing the file it represents if any.
~BufferedFile() FMT_NOEXCEPT; ~BufferedFile() FMT_NOEXCEPT;
@ -167,13 +167,13 @@ public:
public: public:
BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_) { BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : file_(other.file_) {
other.file_ = nullptr; other.file_ = 0;
} }
BufferedFile& operator=(BufferedFile &&other) { BufferedFile& operator=(BufferedFile &&other) {
close(); close();
file_ = other.file_; file_ = other.file_;
other.file_ = nullptr; other.file_ = 0;
return *this; return *this;
} }
#endif #endif
@ -182,7 +182,7 @@ public:
BufferedFile(fmt::StringRef filename, fmt::StringRef mode); BufferedFile(fmt::StringRef filename, fmt::StringRef mode);
// Gets whether a file is opened // Gets whether a file is opened
bool is_open() const FMT_NOEXCEPT { return file_ != nullptr; } bool is_open() const FMT_NOEXCEPT { return file_ != 0; }
// Closes the file. // Closes the file.
void close(); void close();