add noexcept checks, and some missing noexcepts

This commit is contained in:
Théo DELRIEU 2017-01-14 02:20:53 +01:00
parent 1554baa01d
commit b8012876a5
3 changed files with 31 additions and 2 deletions

View file

@ -843,9 +843,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));
}
};

View file

@ -29,6 +29,7 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
"src/unit-meta.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"

View file

@ -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{})), "");