add noexcept checks, and some missing noexcepts
This commit is contained in:
parent
1554baa01d
commit
b8012876a5
3 changed files with 31 additions and 2 deletions
|
@ -843,7 +843,8 @@ 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));
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
27
test/src/unit-noexcept.cpp
Normal file
27
test/src/unit-noexcept.cpp
Normal 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{})), "");
|
Loading…
Reference in a new issue