From 457bfc2401028a9eb42b738401935d3ad1e1d984 Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 20 Dec 2015 15:30:07 +0100 Subject: [PATCH] work on #144 --- README.md | 2 +- src/json.hpp | 6 +++++- src/json.hpp.re2c | 6 +++++- test/unit.cpp | 13 +++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cd9be0d32..b671f3571 100644 --- a/README.md +++ b/README.md @@ -398,7 +398,7 @@ $ make $ ./json_unit "*" =============================================================================== -All tests passed (3341846 assertions in 28 test cases) +All tests passed (3341848 assertions in 28 test cases) ``` For more information, have a look at the file [.travis.yml](https://github.com/nlohmann/json/blob/master/.travis.yml). diff --git a/src/json.hpp b/src/json.hpp index 9de73ddf1..6bfb44bff 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -2550,7 +2550,9 @@ class basic_json @tparam ValueType non-pointer type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or - `std::vector` types for JSON arrays + `std::vector` types for JSON arrays. The character type of @ref string_t + as well as an initializer list of this type is excluded to avoid + ambiguities as these types implicitly convert to `std::string`. @return copy of the JSON value, converted to type @a ValueType @@ -2571,6 +2573,8 @@ class basic_json template::value + and not std::is_same::value + and not std::is_same>::value , int>::type = 0> operator ValueType() const { diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 5cee92f4b..3ab1dfce1 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -2550,7 +2550,9 @@ class basic_json @tparam ValueType non-pointer type compatible to the JSON value, for instance `int` for JSON integer numbers, `bool` for JSON booleans, or - `std::vector` types for JSON arrays + `std::vector` types for JSON arrays. The character type of @ref string_t + as well as an initializer list of this type is excluded to avoid + ambiguities as these types implicitly convert to `std::string`. @return copy of the JSON value, converted to type @a ValueType @@ -2571,6 +2573,8 @@ class basic_json template::value + and not std::is_same::value + and not std::is_same>::value , int>::type = 0> operator ValueType() const { diff --git a/test/unit.cpp b/test/unit.cpp index 8826d835e..b143f31b5 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -10323,6 +10323,19 @@ TEST_CASE("regression tests") CHECK(j["string"] == "\u0007\u0007"); } + SECTION("issue #144 - implicit assignment to std::string fails") + { + json o = {{"name", "value"}}; + + std::string s1 = o["name"]; + CHECK(s1 == "value"); + + std::string s2; + s2 = o["name"]; + + CHECK(s2 == "value"); + } + SECTION("character following a surrogate pair is skipped") { CHECK(json::parse("\"\\ud80c\\udc60abc\"").get() == u8"\U00013060abc"); -- GitLab