From 09887be9e29c63ab1e9dcbf5795e22bd3428b346 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Fri, 21 Apr 2017 11:25:39 -0700 Subject: [PATCH 1/1] Use std::nullptr_t in dynamic Summary: It was changed to a `void*` previously due to an ICE in GCC 4.7. GCC 4.7 hasn't been supported in quite a while, and newer versions of GCC don't crash, so it's time to switch it back to `nullptr_t`. Reviewed By: yfeldblum Differential Revision: D4917389 fbshipit-source-id: fc48642026c7e3aaeadef27bb949f70648c2312c --- folly/dynamic-inl.h | 21 +++++++++++++-------- folly/dynamic.cpp | 4 ++-- folly/dynamic.h | 4 +--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index 3c85ee4b..fe65cbbc 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -44,7 +44,7 @@ struct hash< ::folly::dynamic> { do { \ switch ((type)) { \ case NULLT: \ - apply(void*); \ + apply(std::nullptr_t); \ break; \ case ARRAY: \ apply(Array); \ @@ -419,7 +419,7 @@ inline bool dynamic::isInt() const { return get_nothrow() != nullptr; } inline bool dynamic::isNull() const { - return get_nothrow() != nullptr; + return get_nothrow() != nullptr; } inline bool dynamic::isNumber() const { return isInt() || isDouble(); @@ -484,6 +484,12 @@ struct dynamic::CompareOp { return false; } }; +template<> +struct dynamic::CompareOp { + static bool comp(std::nullptr_t const&, std::nullptr_t const&) { + return true; + } +}; inline dynamic& dynamic::operator+=(dynamic const& o) { if (type() == STRING && o.type() == STRING) { @@ -708,7 +714,7 @@ inline dynamic::dynamic(Array&& r) : type_(ARRAY) { }; \ // -FOLLY_DYNAMIC_DEC_TYPEINFO(void*, "null", dynamic::NULLT) +FOLLY_DYNAMIC_DEC_TYPEINFO(std::nullptr_t, "null", dynamic::NULLT) FOLLY_DYNAMIC_DEC_TYPEINFO(bool, "boolean", dynamic::BOOL) FOLLY_DYNAMIC_DEC_TYPEINFO(std::string, "string", dynamic::STRING) FOLLY_DYNAMIC_DEC_TYPEINFO(dynamic::Array, "array", dynamic::ARRAY) @@ -758,8 +764,8 @@ T const* dynamic::getAddress() const noexcept { } template struct dynamic::GetAddrImpl {}; -template<> struct dynamic::GetAddrImpl { - static void** get(Data& d) noexcept { return &d.nul; } +template<> struct dynamic::GetAddrImpl { + static std::nullptr_t* get(Data& d) noexcept { return &d.nul; } }; template<> struct dynamic::GetAddrImpl { static Array* get(Data& d) noexcept { return &d.array; } @@ -818,11 +824,10 @@ struct dynamic::PrintImpl { }; // Otherwise, null, being (void*)0, would print as 0. template <> -struct dynamic::PrintImpl { +struct dynamic::PrintImpl { static void print(dynamic const& /* d */, std::ostream& out, - void* const& nul) { - DCHECK_EQ((void*)0, nul); + std::nullptr_t const&) { out << "null"; } }; diff --git a/folly/dynamic.cpp b/folly/dynamic.cpp index cc1ffdea..8ef7d08e 100644 --- a/folly/dynamic.cpp +++ b/folly/dynamic.cpp @@ -29,7 +29,7 @@ namespace folly { constexpr dynamic::Type dynamic::TypeInfo::type; \ // -FOLLY_DYNAMIC_DEF_TYPEINFO(void*) +FOLLY_DYNAMIC_DEF_TYPEINFO(std::nullptr_t) FOLLY_DYNAMIC_DEF_TYPEINFO(bool) FOLLY_DYNAMIC_DEF_TYPEINFO(std::string) FOLLY_DYNAMIC_DEF_TYPEINFO(dynamic::Array) @@ -65,7 +65,7 @@ TypeError::~TypeError() = default; do { \ switch ((type)) { \ case NULLT: \ - apply(void*); \ + apply(std::nullptr_t); \ break; \ case ARRAY: \ apply(Array); \ diff --git a/folly/dynamic.h b/folly/dynamic.h index 1c9ac0e0..a6280509 100644 --- a/folly/dynamic.h +++ b/folly/dynamic.h @@ -552,9 +552,7 @@ private: explicit Data() : nul(nullptr) {} ~Data() {} - // XXX: gcc does an ICE if we use std::nullptr_t instead of void* - // here. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50361 - void* nul; + std::nullptr_t nul; Array array; bool boolean; double doubl; -- 2.34.1