mirror of
https://github.com/nlohmann/json.git
synced 2026-09-28 18:50:31 +00:00
Improve error message for const fields (#2818)
* Improve error message for const fields * Reject const arguments to get_to() with a clear message Reword the static_assert, add it to the C array overload of get_to() as well, and document that v must not be const. Signed-off-by: Niels Lohmann <mail@nlohmann.me> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> Co-authored-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
co-authored by
Niels Lohmann
parent
02dd3e67f2
commit
465407f3ce
@@ -2553,6 +2553,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
ValueType & get_to(ValueType& v) const noexcept(noexcept(
|
||||
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
|
||||
{
|
||||
static_assert(!std::is_const<ValueType>::value, "get_to() cannot deserialize into a const value");
|
||||
JSONSerializer<ValueType>::from_json(*this, v);
|
||||
return v;
|
||||
}
|
||||
@@ -2578,6 +2579,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
noexcept(noexcept(JSONSerializer<Array>::from_json(
|
||||
std::declval<const basic_json_t&>(), v)))
|
||||
{
|
||||
static_assert(!std::is_const<T>::value, "get_to() cannot deserialize into a const value");
|
||||
JSONSerializer<Array>::from_json(*this, v);
|
||||
return v;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user