Commit 09887be9 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

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
parent 58006ffb
...@@ -44,7 +44,7 @@ struct hash< ::folly::dynamic> { ...@@ -44,7 +44,7 @@ struct hash< ::folly::dynamic> {
do { \ do { \
switch ((type)) { \ switch ((type)) { \
case NULLT: \ case NULLT: \
apply(void*); \ apply(std::nullptr_t); \
break; \ break; \
case ARRAY: \ case ARRAY: \
apply(Array); \ apply(Array); \
...@@ -419,7 +419,7 @@ inline bool dynamic::isInt() const { ...@@ -419,7 +419,7 @@ inline bool dynamic::isInt() const {
return get_nothrow<int64_t>() != nullptr; return get_nothrow<int64_t>() != nullptr;
} }
inline bool dynamic::isNull() const { inline bool dynamic::isNull() const {
return get_nothrow<void*>() != nullptr; return get_nothrow<std::nullptr_t>() != nullptr;
} }
inline bool dynamic::isNumber() const { inline bool dynamic::isNumber() const {
return isInt() || isDouble(); return isInt() || isDouble();
...@@ -484,6 +484,12 @@ struct dynamic::CompareOp<dynamic::ObjectImpl> { ...@@ -484,6 +484,12 @@ struct dynamic::CompareOp<dynamic::ObjectImpl> {
return false; return false;
} }
}; };
template<>
struct dynamic::CompareOp<std::nullptr_t> {
static bool comp(std::nullptr_t const&, std::nullptr_t const&) {
return true;
}
};
inline dynamic& dynamic::operator+=(dynamic const& o) { inline dynamic& dynamic::operator+=(dynamic const& o) {
if (type() == STRING && o.type() == STRING) { if (type() == STRING && o.type() == STRING) {
...@@ -708,7 +714,7 @@ inline dynamic::dynamic(Array&& r) : type_(ARRAY) { ...@@ -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(bool, "boolean", dynamic::BOOL)
FOLLY_DYNAMIC_DEC_TYPEINFO(std::string, "string", dynamic::STRING) FOLLY_DYNAMIC_DEC_TYPEINFO(std::string, "string", dynamic::STRING)
FOLLY_DYNAMIC_DEC_TYPEINFO(dynamic::Array, "array", dynamic::ARRAY) FOLLY_DYNAMIC_DEC_TYPEINFO(dynamic::Array, "array", dynamic::ARRAY)
...@@ -758,8 +764,8 @@ T const* dynamic::getAddress() const noexcept { ...@@ -758,8 +764,8 @@ T const* dynamic::getAddress() const noexcept {
} }
template<class T> struct dynamic::GetAddrImpl {}; template<class T> struct dynamic::GetAddrImpl {};
template<> struct dynamic::GetAddrImpl<void*> { template<> struct dynamic::GetAddrImpl<std::nullptr_t> {
static void** get(Data& d) noexcept { return &d.nul; } static std::nullptr_t* get(Data& d) noexcept { return &d.nul; }
}; };
template<> struct dynamic::GetAddrImpl<dynamic::Array> { template<> struct dynamic::GetAddrImpl<dynamic::Array> {
static Array* get(Data& d) noexcept { return &d.array; } static Array* get(Data& d) noexcept { return &d.array; }
...@@ -818,11 +824,10 @@ struct dynamic::PrintImpl { ...@@ -818,11 +824,10 @@ struct dynamic::PrintImpl {
}; };
// Otherwise, null, being (void*)0, would print as 0. // Otherwise, null, being (void*)0, would print as 0.
template <> template <>
struct dynamic::PrintImpl<void*> { struct dynamic::PrintImpl<std::nullptr_t> {
static void print(dynamic const& /* d */, static void print(dynamic const& /* d */,
std::ostream& out, std::ostream& out,
void* const& nul) { std::nullptr_t const&) {
DCHECK_EQ((void*)0, nul);
out << "null"; out << "null";
} }
}; };
......
...@@ -29,7 +29,7 @@ namespace folly { ...@@ -29,7 +29,7 @@ namespace folly {
constexpr dynamic::Type dynamic::TypeInfo<T>::type; \ constexpr dynamic::Type dynamic::TypeInfo<T>::type; \
// //
FOLLY_DYNAMIC_DEF_TYPEINFO(void*) FOLLY_DYNAMIC_DEF_TYPEINFO(std::nullptr_t)
FOLLY_DYNAMIC_DEF_TYPEINFO(bool) FOLLY_DYNAMIC_DEF_TYPEINFO(bool)
FOLLY_DYNAMIC_DEF_TYPEINFO(std::string) FOLLY_DYNAMIC_DEF_TYPEINFO(std::string)
FOLLY_DYNAMIC_DEF_TYPEINFO(dynamic::Array) FOLLY_DYNAMIC_DEF_TYPEINFO(dynamic::Array)
...@@ -65,7 +65,7 @@ TypeError::~TypeError() = default; ...@@ -65,7 +65,7 @@ TypeError::~TypeError() = default;
do { \ do { \
switch ((type)) { \ switch ((type)) { \
case NULLT: \ case NULLT: \
apply(void*); \ apply(std::nullptr_t); \
break; \ break; \
case ARRAY: \ case ARRAY: \
apply(Array); \ apply(Array); \
......
...@@ -552,9 +552,7 @@ private: ...@@ -552,9 +552,7 @@ private:
explicit Data() : nul(nullptr) {} explicit Data() : nul(nullptr) {}
~Data() {} ~Data() {}
// XXX: gcc does an ICE if we use std::nullptr_t instead of void* std::nullptr_t nul;
// here. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50361
void* nul;
Array array; Array array;
bool boolean; bool boolean;
double doubl; double doubl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment