diff --git a/README.md b/README.md index cd9be0d3..b671f357 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 9de73ddf..6bfb44bf 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 5cee92f4..3ab1dfce 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 8826d835..b143f31b 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");