Skip to content

Commit

Permalink
work on #144
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Dec 20, 2015
1 parent 1adb9d6 commit 457bfc2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
6 changes: 5 additions & 1 deletion src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -2571,6 +2573,8 @@ class basic_json
template<typename ValueType, typename
std::enable_if<
not std::is_pointer<ValueType>::value
and not std::is_same<ValueType, typename string_t::value_type>::value
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
, int>::type = 0>
operator ValueType() const
{
Expand Down
6 changes: 5 additions & 1 deletion src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -2571,6 +2573,8 @@ class basic_json
template<typename ValueType, typename
std::enable_if<
not std::is_pointer<ValueType>::value
and not std::is_same<ValueType, typename string_t::value_type>::value
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
, int>::type = 0>
operator ValueType() const
{
Expand Down
13 changes: 13 additions & 0 deletions test/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<json::string_t>() == u8"\U00013060abc");
Expand Down

0 comments on commit 457bfc2

Please sign in to comment.