diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 31ca64539..c4c00c667 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1798,6 +1798,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ValueType & get_to(ValueType& v) const noexcept(noexcept( JSONSerializer::from_json(std::declval(), v))) { + static_assert(!std::is_const::value, "Cannot deserialize into constant fields"); JSONSerializer::from_json(*this, v); return v; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a858728c4..4db1a90ac 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21101,6 +21101,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ValueType & get_to(ValueType& v) const noexcept(noexcept( JSONSerializer::from_json(std::declval(), v))) { + static_assert(!std::is_const::value, "Cannot deserialize into constant fields"); JSONSerializer::from_json(*this, v); return v; }