diff --git a/src/json.hpp b/src/json.hpp index 838d2d07..9c0a8168 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -840,7 +840,7 @@ template struct adl_serializer { template - static void from_json(Json&& j, T& val) + static void from_json(Json&& j, T& val) noexcept(noexcept(::nlohmann::from_json(std::forward(j), val))) { ::nlohmann::from_json(std::forward(j), val); } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index a3539180..8fbff2ad 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -840,7 +840,7 @@ template struct adl_serializer { template - static void from_json(Json&& j, T& val) + static void from_json(Json&& j, T& val) noexcept(noexcept(::nlohmann::from_json(std::forward(j), val))) { ::nlohmann::from_json(std::forward(j), val); } diff --git a/test/src/unit-noexcept.cpp b/test/src/unit-noexcept.cpp index 212abdf7..de13e057 100644 --- a/test/src/unit-noexcept.cpp +++ b/test/src/unit-noexcept.cpp @@ -13,6 +13,8 @@ struct pod_bis {}; void to_json(json &, pod) noexcept; void to_json(json &, pod_bis); +void from_json(const json&, pod) noexcept; +void from_json(const json&, pod_bis); static json j; static_assert(noexcept(json{}), ""); @@ -25,3 +27,6 @@ static_assert(not noexcept(nlohmann::to_json(j, pod_bis{})), ""); static_assert(noexcept(json(2)), ""); static_assert(noexcept(json(test{})), ""); static_assert(noexcept(json(pod{})), ""); +static_assert(noexcept(j.get()), ""); +static_assert(not noexcept(j.get()), ""); +static_assert(noexcept(json(pod{})), "");