diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0bbaa9503..d11a51d52 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -3236,6 +3236,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 2716e1e7b..0447d793a 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -20256,6 +20256,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; }