From 62dfdf3f5d47711db35cc18f7f6500e27a0298a3 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 28 Mar 2017 23:24:59 +0200 Subject: [PATCH 1/2] :memo: addressed #514 NaN values never compare equal to themselves or to other NaN values. --- src/json.hpp | 10 +++++++--- src/json.hpp.re2c | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index cae427ef3..37db5c45f 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -5640,7 +5640,7 @@ class basic_json @ref push_back(const typename object_t::value_type&). Otherwise, @a init is converted to a JSON value and added using @ref push_back(basic_json&&). - @param init an initializer list + @param[in] init an initializer list @complexity Linear in the size of the initializer list @a init. @@ -6117,13 +6117,17 @@ class basic_json Compares two JSON values for equality according to the following rules: - Two JSON values are equal if (1) they are from the same type and (2) - their stored values are the same. + their stored values are the same according to their respective + `operator==`. - Integer and floating-point numbers are automatically converted before comparison. Floating-point numbers are compared indirectly: two floating-point numbers `f1` and `f2` are considered equal if neither - `f1 > f2` nor `f2 > f1` holds. + `f1 > f2` nor `f2 > f1` holds. Note than two NaN values are always + treated as unequal. - Two JSON null values are equal. + @note NaN values never compare equal to themselves or to other NaN values. + @param[in] lhs first JSON value to consider @param[in] rhs second JSON value to consider @return whether the values @a lhs and @a rhs are equal diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 3aabece5c..cafb20671 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -5640,7 +5640,7 @@ class basic_json @ref push_back(const typename object_t::value_type&). Otherwise, @a init is converted to a JSON value and added using @ref push_back(basic_json&&). - @param init an initializer list + @param[in] init an initializer list @complexity Linear in the size of the initializer list @a init. @@ -6117,13 +6117,17 @@ class basic_json Compares two JSON values for equality according to the following rules: - Two JSON values are equal if (1) they are from the same type and (2) - their stored values are the same. + their stored values are the same according to their respective + `operator==`. - Integer and floating-point numbers are automatically converted before comparison. Floating-point numbers are compared indirectly: two floating-point numbers `f1` and `f2` are considered equal if neither - `f1 > f2` nor `f2 > f1` holds. + `f1 > f2` nor `f2 > f1` holds. Note than two NaN values are always + treated as unequal. - Two JSON null values are equal. + @note NaN values never compare equal to themselves or to other NaN values. + @param[in] lhs first JSON value to consider @param[in] rhs second JSON value to consider @return whether the values @a lhs and @a rhs are equal From b4dbebffcdb98c91130133adb6583a1b5dafe6a6 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Tue, 28 Mar 2017 23:28:54 +0200 Subject: [PATCH 2/2] :white_check_mark: added regression test for #464 --- test/src/unit-regression.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/src/unit-regression.cpp b/test/src/unit-regression.cpp index f7f4c350e..a7b6e117a 100644 --- a/test/src/unit-regression.cpp +++ b/test/src/unit-regression.cpp @@ -837,6 +837,14 @@ TEST_CASE("regression tests") CHECK(j["double_value"].is_number_float()); } + SECTION("issue #464 - VS2017 implicit to std::string conversion fix") + { + json v = "test"; + std::string test; + test = v; + CHECK(v == "test"); + } + SECTION("issue #465 - roundtrip error while parsing 1000000000000000010E5") { json j1 = json::parse("1000000000000000010E5");