Skip to content

Commit

Permalink
add noexcept tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo DELRIEU committed Jan 21, 2017
1 parent af94e71 commit b56117b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ template <typename = void, typename = void>
struct adl_serializer
{
template <typename Json, typename T>
static void from_json(Json&& j, T& val)
static void from_json(Json&& j, T& val) noexcept(noexcept(::nlohmann::from_json(std::forward<Json>(j), val)))
{
::nlohmann::from_json(std::forward<Json>(j), val);
}
Expand Down
2 changes: 1 addition & 1 deletion src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ template <typename = void, typename = void>
struct adl_serializer
{
template <typename Json, typename T>
static void from_json(Json&& j, T& val)
static void from_json(Json&& j, T& val) noexcept(noexcept(::nlohmann::from_json(std::forward<Json>(j), val)))
{
::nlohmann::from_json(std::forward<Json>(j), val);
}
Expand Down
5 changes: 5 additions & 0 deletions test/src/unit-noexcept.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{}), "");
Expand All @@ -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<pod>()), "");
static_assert(not noexcept(j.get<pod_bis>()), "");
static_assert(noexcept(json(pod{})), "");

0 comments on commit b56117b

Please sign in to comment.