From 1fb9b6d3362a50be4e9b439b363ed79acf038eac Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Tue, 29 Jul 2014 21:07:12 -0700 Subject: [PATCH 1/5] noexcept not added until Visual Studio 2014 --- contrib/json11/json11.cpp | 4 ++-- contrib/json11/json11.hpp | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/contrib/json11/json11.cpp b/contrib/json11/json11.cpp index ad7f5b176..f5a99ee42 100755 --- a/contrib/json11/json11.cpp +++ b/contrib/json11/json11.cpp @@ -235,8 +235,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) {} diff --git a/contrib/json11/json11.hpp b/contrib/json11/json11.hpp index 779445e55..e785105ae 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 From d4a6f45c38a90e5fc963685b51ff3d5fbb031c9e Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Tue, 29 Jul 2014 21:25:32 -0700 Subject: [PATCH 2/5] enable_if::type cannot form part of a template parameter space --- contrib/json11/json11.hpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/contrib/json11/json11.hpp b/contrib/json11/json11.hpp index e785105ae..36ffc6fe5 100755 --- a/contrib/json11/json11.hpp +++ b/contrib/json11/json11.hpp @@ -101,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. From de5683895563d7a78ee58fc62af69d1ef4c548be Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Tue, 29 Jul 2014 21:27:43 -0700 Subject: [PATCH 3/5] Implicit conversion warnings silenced --- contrib/json11/json11.cpp | 14 +++++++------- contrib/json11/json11.hpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contrib/json11/json11.cpp b/contrib/json11/json11.cpp index f5a99ee42..2ba35359a 100755 --- a/contrib/json11/json11.cpp +++ b/contrib/json11/json11.cpp @@ -158,7 +158,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 +171,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 { @@ -380,16 +380,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 36ffc6fe5..3f1ca40e9 100755 --- a/contrib/json11/json11.hpp +++ b/contrib/json11/json11.hpp @@ -116,7 +116,7 @@ class Json final { template Json( const typename std::enable_if< - std::is_constructible().begin()->first)>::value, + std::is_constructible().begin()->first)>::value, V >::type& v ) : From 6588d00ace8ee8ac8e8117e1af5bc98f199b08ed Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Tue, 29 Jul 2014 21:35:57 -0700 Subject: [PATCH 4/5] MSVC's version of snprintf is called _snprintf_s --- contrib/json11/json11.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contrib/json11/json11.cpp b/contrib/json11/json11.cpp index 2ba35359a..912d937fc 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 */ From 3c259ff533894f7af488037a40413cc39180970b Mon Sep 17 00:00:00 2001 From: Jason Lokerson Date: Tue, 29 Jul 2014 21:36:05 -0700 Subject: [PATCH 5/5] Silenced MSVC initializer error --- contrib/json11/json11.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/json11/json11.cpp b/contrib/json11/json11.cpp index 912d937fc..bc8bde056 100755 --- a/contrib/json11/json11.cpp +++ b/contrib/json11/json11.cpp @@ -217,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);