From f4658de2701f2290baf076bbbd8540260015518c Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Mon, 19 Sep 2022 08:04:39 +0200 Subject: [PATCH] Fix 'declaration hides global declaration' warning (#3751) --- tests/src/unit-noexcept.cpp | 40 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/tests/src/unit-noexcept.cpp b/tests/src/unit-noexcept.cpp index 2cac058ce..656bc2ab8 100644 --- a/tests/src/unit-noexcept.cpp +++ b/tests/src/unit-noexcept.cpp @@ -18,9 +18,7 @@ using nlohmann::json; namespace { -enum test -{ -}; +enum test {}; struct pod {}; struct pod_bis {}; @@ -34,25 +32,29 @@ 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*/) {} -json* j = nullptr; - 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(!noexcept(nlohmann::to_json(*j, pod_bis{})), ""); +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(j->get()), ""); -static_assert(!noexcept(j->get()), ""); +static_assert(noexcept(std::declval().get()), ""); +static_assert(!noexcept(std::declval().get()), ""); static_assert(noexcept(json(pod{})), ""); } // namespace -TEST_CASE("runtime checks") +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): @@ -67,16 +69,6 @@ TEST_CASE("runtime checks") 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); } - - SECTION("silence -Wunneeded-internal-declaration errors") - { - j = nullptr; - json j2; - to_json(j2, pod()); - to_json(j2, pod_bis()); - from_json(j2, pod()); - from_json(j2, pod_bis()); - } } DOCTEST_GCC_SUPPRESS_WARNING_POP