@@ -18,9 +18,7 @@ using nlohmann::json;
1818
1919namespace
2020{
21- enum test
22- {
23- };
21+ enum test {};
2422
2523struct pod {};
2624struct pod_bis {};
@@ -34,25 +32,29 @@ void to_json(json& /*unused*/, pod_bis /*unused*/) {}
3432void from_json (const json& /* unused*/ , pod /* unused*/ ) noexcept {}
3533void from_json (const json& /* unused*/ , pod_bis /* unused*/ ) {}
3634
37- json* j = nullptr ;
38-
3935static_assert (noexcept (json{}), " " );
40- static_assert (noexcept (nlohmann::to_json(*j , 2 )), " " );
41- static_assert (noexcept (nlohmann::to_json(*j , 2.5 )), " " );
42- static_assert (noexcept (nlohmann::to_json(*j , true )), " " );
43- static_assert (noexcept (nlohmann::to_json(*j , test{})), " " );
44- static_assert (noexcept (nlohmann::to_json(*j , pod{})), " " );
45- static_assert (!noexcept (nlohmann::to_json(*j , pod_bis{})), " " );
36+ static_assert (noexcept (nlohmann::to_json(std::declval<json&>() , 2 )), " " );
37+ static_assert (noexcept (nlohmann::to_json(std::declval<json&>() , 2.5 )), " " );
38+ static_assert (noexcept (nlohmann::to_json(std::declval<json&>() , true )), " " );
39+ static_assert (noexcept (nlohmann::to_json(std::declval<json&>() , test{})), " " );
40+ static_assert (noexcept (nlohmann::to_json(std::declval<json&>() , pod{})), " " );
41+ static_assert (!noexcept (nlohmann::to_json(std::declval<json&>() , pod_bis{})), " " );
4642static_assert (noexcept (json(2 )), " " );
4743static_assert (noexcept (json(test{})), " " );
4844static_assert (noexcept (json(pod{})), " " );
49- static_assert (noexcept (j-> get<pod>()), " " );
50- static_assert (!noexcept (j-> get<pod_bis>()), " " );
45+ static_assert (noexcept (std::declval<json>(). get<pod>()), " " );
46+ static_assert (!noexcept (std::declval<json>(). get<pod_bis>()), " " );
5147static_assert (noexcept (json(pod{})), " " );
5248} // namespace
5349
54- TEST_CASE (" runtime checks " )
50+ TEST_CASE (" noexcept " )
5551{
52+ // silence -Wunneeded-internal-declaration errors
53+ static_cast <void >(static_cast <void (*)(json&, pod)>(&to_json));
54+ static_cast <void >(static_cast <void (*)(json&, pod_bis)>(&to_json));
55+ static_cast <void >(static_cast <void (*)(const json&, pod)>(&from_json));
56+ static_cast <void >(static_cast <void (*)(const json&, pod_bis)>(&from_json));
57+
5658 SECTION (" nothrow-copy-constructible exceptions" )
5759 {
5860 // for ERR60-CPP (https://github.com/nlohmann/json/issues/531):
@@ -67,16 +69,6 @@ TEST_CASE("runtime checks")
6769 CHECK (std::is_nothrow_copy_constructible<json::out_of_range>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
6870 CHECK (std::is_nothrow_copy_constructible<json::other_error>::value == std::is_nothrow_copy_constructible<std::runtime_error>::value);
6971 }
70-
71- SECTION (" silence -Wunneeded-internal-declaration errors" )
72- {
73- j = nullptr ;
74- json j2;
75- to_json (j2, pod ());
76- to_json (j2, pod_bis ());
77- from_json (j2, pod ());
78- from_json (j2, pod_bis ());
79- }
8072}
8173
8274DOCTEST_GCC_SUPPRESS_WARNING_POP
0 commit comments