diff --git a/README.md b/README.md index ccc529354c3bccbf128ba87ae57438e180ccdfd8..0ce18829bb8fe7acea0e30f09c129f038aca6db7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ include(FetchContent) FetchContent_Declare(json GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent - GIT_TAG v3.10.0) + GIT_TAG v3.10.1) FetchContent_GetProperties(json) if(NOT json_POPULATED) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index bd1dc6ad1410b71d033c6971498b9bf297920400..5ba4a4bed7603efb4876dd2749ff305f8ab88b05 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1,7 +1,7 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.10.0 +| | |__ | | | | | | version 3.10.1 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License <http://opensource.org/licenses/MIT>. @@ -32,7 +32,7 @@ SOFTWARE. #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 -#define NLOHMANN_JSON_VERSION_PATCH 0 +#define NLOHMANN_JSON_VERSION_PATCH 1 #include <algorithm> // all_of, find, for_each #include <cstddef> // nullptr_t, ptrdiff_t, size_t @@ -3845,6 +3845,24 @@ struct is_constructible_tuple : std::false_type {}; template<typename T1, typename... Args> struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {}; +// a naive helper to check if a type is an ordered_map (exploits the fact that +// ordered_map inherits capacity() from std::vector) +template <typename T> +struct is_ordered_map +{ + using one = char; + + struct two + { + char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + }; + + template <typename C> static one test( decltype(&C::capacity) ) ; + template <typename C> static two test(...); + + enum { value = sizeof(test<T>(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) +}; + // to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value, int > = 0 > T conditional_static_cast(U value) @@ -4602,7 +4620,7 @@ struct external_constructor<value_t::binary> { j.m_value.destroy(j.m_type); j.m_type = value_t::binary; - j.m_value = typename BasicJsonType::binary_t(std::move(b));; + j.m_value = typename BasicJsonType::binary_t(std::move(b)); j.assert_invariant(); } }; @@ -5169,6 +5187,8 @@ class byte_container_with_subtype : public BinaryType // #include <nlohmann/detail/macro_scope.hpp> +// #include <nlohmann/detail/value_t.hpp> + namespace nlohmann { @@ -13615,7 +13635,7 @@ class binary_writer case value_t::discarded: default: { - JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));; + JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j)); } } } @@ -18446,7 +18466,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.0", basic_json())); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.1", basic_json())); // LCOV_EXCL_LINE } break; } @@ -18717,6 +18737,21 @@ 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<object_t>::value) + { + set_parents(); + return j; + } +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning( pop ) +#endif + j.m_parent = this; #else static_cast<void>(j);