Skip to content

Commit

Permalink
add noexcept checks, and some missing noexcepts
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo DELRIEU committed Jan 14, 2017
1 parent 7a7bc07 commit b023103
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,9 +834,10 @@ struct adl_serializer
}

template <typename Json, typename T>
static void to_json(Json& j, T&& val)
static void to_json(Json &j, T &&val) noexcept(
noexcept(::nlohmann::to_json(j, std::forward<T>(val))))
{
::nlohmann::to_json(j, std::forward<T>(val));
::nlohmann::to_json(j, std::forward<T>(val));
}
};

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
"src/unit-json_pointer.cpp"
"src/unit-modifiers.cpp"
"src/unit-msgpack.cpp"
"src/unit-noexcept.cpp"
"src/unit-pointer_access.cpp"
"src/unit-readme.cpp"
"src/unit-reference_access.cpp"
Expand Down
27 changes: 27 additions & 0 deletions test/src/unit-noexcept.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <catch.hpp>

#include "json.hpp"

using nlohmann::json;

enum test
{
};

struct pod {};
struct pod_bis {};

void to_json(json &, pod) noexcept;
void to_json(json &, pod_bis);
static json j;

static_assert(noexcept(json{}), "");
static_assert(noexcept(nlohmann::to_json(j, 2)), "");
static_assert(noexcept(nlohmann::to_json(j, 2.5)), "");
static_assert(noexcept(nlohmann::to_json(j, true)), "");
static_assert(noexcept(nlohmann::to_json(j, test{})), "");
static_assert(noexcept(nlohmann::to_json(j, pod{})), "");
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{})), "");

0 comments on commit b023103

Please sign in to comment.