From b56117b148b346b78a9928764b03326bce96d3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Mon, 16 Jan 2017 21:59:47 +0100 Subject: [PATCH] add noexcept tests --- src/json.hpp | 2 +- src/json.hpp.re2c | 2 +- test/src/unit-noexcept.cpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index 838d2d071..9c0a8168b 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 a35391800..8fbff2ad5 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 212abdf71..de13e0578 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{})), "");