From 200015cb0e764dabb75922ff7ddb0ddd466439dd Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sun, 22 Aug 2021 17:56:28 +0200 Subject: [PATCH] :rotating_light: suppress warnings --- include/nlohmann/detail/meta/type_traits.hpp | 2 +- include/nlohmann/json.hpp | 7 +++++++ single_include/nlohmann/json.hpp | 9 ++++++++- test/src/unit-diagnostics.cpp | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 02f65a005..ede55acc2 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -451,7 +451,7 @@ struct is_ordered_map template static one test( decltype(&C::capacity) ) ; template static two test(...); - enum { value = sizeof(test(nullptr)) == sizeof(char) }; + enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) }; // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index c64e9ab57..1e85feb4e 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1338,11 +1338,18 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // ordered_json uses a vector internally, so pointers could have // been invalidated; see https://github.com/nlohmann/json/issues/2962 +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning(push ) +#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr +#endif if (detail::is_ordered_map::value) { set_parents(); return j; } +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning( pop ) +#endif j.m_parent = this; #else diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 8e8648e0b..cedac86fa 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3860,7 +3860,7 @@ struct is_ordered_map template static one test( decltype(&C::capacity) ) ; template static two test(...); - enum { value = sizeof(test(nullptr)) == sizeof(char) }; + enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) }; // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) @@ -18739,11 +18739,18 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // ordered_json uses a vector internally, so pointers could have // been invalidated; see https://github.com/nlohmann/json/issues/2962 +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning(push ) +#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr +#endif if (detail::is_ordered_map::value) { set_parents(); return j; } +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning( pop ) +#endif j.m_parent = this; #else diff --git a/test/src/unit-diagnostics.cpp b/test/src/unit-diagnostics.cpp index 5b20784c0..28c4a37a0 100644 --- a/test/src/unit-diagnostics.cpp +++ b/test/src/unit-diagnostics.cpp @@ -179,7 +179,7 @@ TEST_CASE("Better diagnostics") { nlohmann::ordered_json j; nlohmann::ordered_json j2; - const std::string value = ""; + const std::string value; j["first"] = value; j["second"] = value; j2["something"] = j;