diff --git a/contrib/json11/json11.cpp b/contrib/json11/json11.cpp index ad7f5b176..bc8bde056 100755 --- a/contrib/json11/json11.cpp +++ b/contrib/json11/json11.cpp @@ -36,6 +36,11 @@ using std::make_shared; using std::initializer_list; using std::move; +#ifdef _MSC_VER + // MSVC has funny names for snprintf, we just use it instead + #define snprintf(str, size, format, ...) _snprintf_s(str, size, _TRUNCATE, format, __VA_ARGS__) +#endif + /* * * * * * * * * * * * * * * * * * * * * Serialization */ @@ -158,7 +163,7 @@ class Value : public JsonValue { class JsonDouble final : public Value { double number_value() const { return m_value; } - int int_value() const { return m_value; } + int int_value() const { return static_cast(m_value); } bool equals(const JsonValue * other) const { return m_value == other->number_value(); } bool less(const JsonValue * other) const { return m_value < other->number_value(); } public: @@ -171,7 +176,7 @@ class JsonInt final : public Value { bool equals(const JsonValue * other) const { return m_value == other->number_value(); } bool less(const JsonValue * other) const { return m_value < other->number_value(); } public: - JsonInt(double value) : Value(value) {} + JsonInt(double value) : Value(static_cast(value)) {} }; class JsonBoolean final : public Value { @@ -212,6 +217,8 @@ class JsonNull final : public Value { * Static globals - static-init-safe */ struct Statics { + Statics() {} + const std::shared_ptr null = make_shared(); const std::shared_ptr t = make_shared(true); const std::shared_ptr f = make_shared(false); @@ -235,8 +242,8 @@ const Json & static_null() { * Constructors */ -Json::Json() noexcept : m_ptr(statics().null) {} -Json::Json(std::nullptr_t) noexcept : m_ptr(statics().null) {} +Json::Json() JSON11_NOEXCEPT : m_ptr(statics().null) {} +Json::Json(std::nullptr_t) JSON11_NOEXCEPT : m_ptr(statics().null) {} Json::Json(double value) : m_ptr(make_shared(value)) {} Json::Json(int value) : m_ptr(make_shared(value)) {} Json::Json(bool value) : m_ptr(value ? statics().t : statics().f) {} @@ -380,16 +387,16 @@ struct JsonParser { return; if (pt < 0x80) { - out += pt; + out += static_cast(pt); } else if (pt < 0x800) { - out += (pt >> 6) | 0xC0; - out += (pt & 0x3F) | 0x80; + out += static_cast(pt >> 6) | 0xC0; + out += static_cast(pt & 0x3F) | 0x80; } else if (pt < 0x10000) { - out += (pt >> 12) | 0xE0; + out += static_cast(pt >> 12) | 0xE0; out += ((pt >> 6) & 0x3F) | 0x80; out += (pt & 0x3F) | 0x80; } else { - out += (pt >> 18) | 0xF0; + out += static_cast(pt >> 18) | 0xF0; out += ((pt >> 12) & 0x3F) | 0x80; out += ((pt >> 6) & 0x3F) | 0x80; out += (pt & 0x3F) | 0x80; diff --git a/contrib/json11/json11.hpp b/contrib/json11/json11.hpp index 779445e55..3f1ca40e9 100755 --- a/contrib/json11/json11.hpp +++ b/contrib/json11/json11.hpp @@ -56,6 +56,17 @@ #include #include +#ifdef _MSC_VER + // noexcept was added to MSVC in Visual Studio 2014 + #if _MSC_VER > 1800 + #define JSON11_NOEXCEPT noexcept + #else + #define JSON11_NOEXCEPT throw() + #endif +#else + #define JSON11_NOEXCEPT noexcept +#endif + namespace json11 { class JsonValue; @@ -72,8 +83,8 @@ class Json final { typedef std::map object; // Constructors for the various types of JSON value. - Json() noexcept; // NUL - Json(std::nullptr_t) noexcept; // NUL + Json() JSON11_NOEXCEPT; // NUL + Json(std::nullptr_t) JSON11_NOEXCEPT; // NUL Json(double value); // NUMBER Json(int value); // NUMBER Json(bool value); // BOOL @@ -90,17 +101,27 @@ class Json final { Json(const T & t) : Json(t.to_json()) {} // Implicit constructor: map-like objects (std::map, std::unordered_map, etc) - template ().begin()->first)>::value - && std::is_constructible().begin()->second)>::value, - int>::type = 0> - Json(const M & m) : Json(object(m.begin(), m.end())) {} + template + Json( + const typename std::enable_if< + std::is_constructible().begin()->first)>::value && + std::is_constructible().begin()->second)>::value, + M + >::type& m + ) : + Json(object(m.begin(), m.end())) + {} // Implicit constructor: vector-like objects (std::list, std::vector, std::set, etc) - template ().begin())>::value, - int>::type = 0> - Json(const V & v) : Json(array(v.begin(), v.end())) {} + template + Json( + const typename std::enable_if< + std::is_constructible().begin()->first)>::value, + V + >::type& v + ) : + Json(array(v.begin(), v.end())) + {} // This prevents Json(some_pointer) from accidentally producing a bool. Use // Json(bool(some_pointer)) if that behavior is desired.