From 249493264a9c1deba647a1656ed436c6e3745ad6 Mon Sep 17 00:00:00 2001 From: Alexander Lanin Date: Mon, 14 Jun 2021 23:02:08 +0200 Subject: [PATCH] Improve error message for const fields --- include/nlohmann/json.hpp | 1 + single_include/nlohmann/json.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 0bbaa9503a..d11a51d524 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 2716e1e7b3..0447d793a9 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; }