mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 03:30:31 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14558ba011 | ||
|
|
ccb419ca64 | ||
|
|
4494890be6 | ||
|
|
c4469c9f82 |
@@ -7,15 +7,15 @@ void clear() noexcept;
|
||||
Clears the content of a JSON value and resets it to the default value as if [`basic_json(value_t)`](basic_json.md) would
|
||||
have been called with the current value type from [`type()`](type.md):
|
||||
|
||||
| Value type | initial value |
|
||||
|------------|-----------------------------------------|
|
||||
| null | `null` |
|
||||
| boolean | `false` |
|
||||
| string | `""` |
|
||||
| number | `0` |
|
||||
| binary | An empty byte vector with no subtype |
|
||||
| object | `{}` |
|
||||
| array | `[]` |
|
||||
| Value type | initial value |
|
||||
|------------|----------------------|
|
||||
| null | `null` |
|
||||
| boolean | `false` |
|
||||
| string | `""` |
|
||||
| number | `0` |
|
||||
| binary | An empty byte vector |
|
||||
| object | `{}` |
|
||||
| array | `[]` |
|
||||
|
||||
Has the same effect as calling
|
||||
|
||||
@@ -56,4 +56,3 @@ All iterators, pointers, and references related to this container are invalidate
|
||||
|
||||
- Added in version 1.0.0.
|
||||
- Added support for binary types in version 3.8.0.
|
||||
- Fixed in version 3.13.0 to also clear the subtype of a binary value; before, the subtype was left unchanged.
|
||||
|
||||
@@ -3833,7 +3833,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
case value_t::binary:
|
||||
{
|
||||
m_data.m_value.binary->clear();
|
||||
m_data.m_value.binary->clear_subtype();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -29914,7 +29914,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
case value_t::binary:
|
||||
{
|
||||
m_data.m_value.binary->clear();
|
||||
m_data.m_value.binary->clear_subtype();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -155,18 +155,6 @@ TEST_CASE("modifiers")
|
||||
CHECK(j == json(json::value_t::binary));
|
||||
CHECK(j == json(k.type()));
|
||||
}
|
||||
|
||||
SECTION("filled binary with subtype")
|
||||
{
|
||||
json j = json::binary({1, 2, 3, 4, 5}, 42);
|
||||
json const k = j;
|
||||
|
||||
j.clear();
|
||||
CHECK(!j.empty());
|
||||
CHECK(!j.get_binary().has_subtype());
|
||||
CHECK(j == json(json::value_t::binary));
|
||||
CHECK(j == json(k.type()));
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("number (integer)")
|
||||
|
||||
@@ -766,6 +766,25 @@ TEST_CASE("regression tests 2")
|
||||
CHECK(j == k);
|
||||
}
|
||||
|
||||
#ifdef JSON_HAS_CPP_17
|
||||
SECTION("issue #5066 - MSVC converts json to std::variant<json> via the conversion operator")
|
||||
{
|
||||
// std::variant<json> must not be retrievable via get<>(), because otherwise the
|
||||
// implicit conversion operator becomes a candidate that MSVC picks over the variant's
|
||||
// converting constructor, routing a number through the string from_json overload
|
||||
static_assert(!nlohmann::detail::is_detected<nlohmann::detail::get_template_function, const json&, std::variant<json>>::value,
|
||||
"std::variant<json> must not be retrievable via get<>()");
|
||||
|
||||
// clang before 7 cannot instantiate libstdc++'s std::variant<json>
|
||||
#if !(defined(__clang__) && __clang_major__ < 7)
|
||||
// push_back, not emplace_back: #5066 needs the implicit conversion
|
||||
// from json to the vector's value type
|
||||
std::vector<std::variant<json>> v;
|
||||
v.push_back(json(1)); // NOLINT(hicpp-use-emplace,modernize-use-emplace)
|
||||
CHECK(std::get<0>(v[0]) == 1);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("regression test - parser callback must not lose a duplicate key's prior value")
|
||||
|
||||
Reference in New Issue
Block a user