// __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ (supporting code) // | | |__ | | | | | | version 3.11.3 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2023 Niels Lohmann // SPDX-License-Identifier: MIT #include "doctest_compatibility.h" // disable -Wnoexcept due to struct pod_bis DOCTEST_GCC_SUPPRESS_WARNING_PUSH DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept") #include using nlohmann::json; namespace { enum test {}; struct pod {}; struct pod_bis {}; void to_json(json& /*unused*/, pod /*unused*/) noexcept; void to_json(json& /*unused*/, pod_bis /*unused*/); void from_json(const json& /*unused*/, pod /*unused*/) noexcept; void from_json(const json& /*unused*/, pod_bis /*unused*/); void to_json(json& /*unused*/, pod /*unused*/) noexcept {} void to_json(json& /*unused*/, pod_bis /*unused*/) {} void from_json(const json& /*unused*/, pod /*unused*/) noexcept {} void from_json(const json& /*unused*/, pod_bis /*unused*/) {} static_assert(noexcept(json{}), ""); static_assert(noexcept(nlohmann::to_json(std::declval(), 2)), ""); static_assert(noexcept(nlohmann::to_json(std::declval(), 2.5)), ""); static_assert(noexcept(nlohmann::to_json(std::declval(), true)), ""); static_assert(noexcept(nlohmann::to_json(std::declval(), test{})), ""); static_assert(noexcept(nlohmann::to_json(std::declval(), pod{})), ""); static_assert(!noexcept(nlohmann::to_json(std::declval(), pod_bis{})), ""); static_assert(noexcept(json(2)), ""); static_assert(noexcept(json(test{})), ""); static_assert(noexcept(json(pod{})), ""); static_assert(noexcept(std::declval().get()), ""); static_assert(!noexcept(std::declval().get()), ""); static_assert(noexcept(json(pod{})), ""); } // namespace TEST_CASE("noexcept") { // silence -Wunneeded-internal-declaration errors static_cast(static_cast(&to_json)); static_cast(static_cast(&to_json)); static_cast(static_cast(&from_json)); static_cast(static_cast(&from_json)); SECTION("nothrow-copy-constructible exceptions") { // for ERR60-CPP (https://github.com/nlohmann/json/issues/531): // Exceptions should be nothrow-copy-constructible. However, compilers // treat std::runtime_exception differently in this regard. Therefore, // we can only demand nothrow-copy-constructibility for our exceptions // if std::runtime_exception is. CHECK(std::is_nothrow_copy_constructible::value == std::is_nothrow_copy_constructible::value); CHECK(std::is_nothrow_copy_constructible::value == std::is_nothrow_copy_constructible::value); CHECK(std::is_nothrow_copy_constructible::value == std::is_nothrow_copy_constructible::value); CHECK(std::is_nothrow_copy_constructible::value == std::is_nothrow_copy_constructible::value); CHECK(std::is_nothrow_copy_constructible::value == std::is_nothrow_copy_constructible::value); CHECK(std::is_nothrow_copy_constructible::value == std::is_nothrow_copy_constructible::value); } } DOCTEST_GCC_SUPPRESS_WARNING_POP