From e5b8f453e5373adf2be63582fbd060dca6d941c5 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Fri, 16 Oct 2026 08:31:07 +0200 Subject: [PATCH] Fix MSVC 2015 failures on AppVeyor - object_capacity() (#5832) overloaded a static with a non-static member function template, which MSVC 2015 rejects (C2686); make all three overloads non-static. - The JSON pointer hash constants (#5836) truncate on 32-bit size_t (C4309 with /WX); mask them to size_t's range before the cast. - unit-diagnostics: MSVC 2015 cannot use-declare the base's Container typedef (C2886); use alias declarations instead. Signed-off-by: Niels Lohmann --- include/nlohmann/detail/json_pointer.hpp | 4 ++-- include/nlohmann/json.hpp | 4 ++-- single_include/nlohmann/json.hpp | 8 ++++---- tests/src/unit-diagnostics.cpp | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index b19ec5757..232b49d24 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -529,10 +529,10 @@ class json_pointer static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept { - std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL); + std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL & static_cast((std::numeric_limits::max)())); for (std::size_t i = 0; i < token.size(); ++i) { - h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL); + h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL & static_cast((std::numeric_limits::max)())); } return h ^ (h >> 29u); } diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index a05071e9d..595fe11e5 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -1225,7 +1225,7 @@ public: } template < typename O = object_t, detail::enable_if_t < detail::has_stable_elements::value, int > = 0 > - static constexpr std::size_t object_capacity() noexcept + std::size_t object_capacity() const noexcept { return 0; } @@ -1237,7 +1237,7 @@ public: } template < typename O = object_t, detail::enable_if_t < !detail::has_stable_elements::value && !detail::is_nlohmann_ordered_map::value, int > = 0 > - static constexpr std::size_t object_capacity() noexcept + std::size_t object_capacity() const noexcept { return detail::unknown_size(); } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cae524061..68d6b5bec 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -21502,10 +21502,10 @@ class json_pointer static std::size_t hash_of(std::size_t parent, const string_t& token) noexcept { - std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL); + std::size_t h = parent * static_cast(0x9E3779B97F4A7C15ULL & static_cast((std::numeric_limits::max)())); for (std::size_t i = 0; i < token.size(); ++i) { - h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL); + h = (h ^ static_cast(token[i])) * static_cast(0x100000001B3ULL & static_cast((std::numeric_limits::max)())); } return h ^ (h >> 29u); } @@ -31290,7 +31290,7 @@ public: } template < typename O = object_t, detail::enable_if_t < detail::has_stable_elements::value, int > = 0 > - static constexpr std::size_t object_capacity() noexcept + std::size_t object_capacity() const noexcept { return 0; } @@ -31302,7 +31302,7 @@ public: } template < typename O = object_t, detail::enable_if_t < !detail::has_stable_elements::value && !detail::is_nlohmann_ordered_map::value, int > = 0 > - static constexpr std::size_t object_capacity() noexcept + std::size_t object_capacity() const noexcept { return detail::unknown_size(); } diff --git a/tests/src/unit-diagnostics.cpp b/tests/src/unit-diagnostics.cpp index 1d7b45a97..504a95322 100644 --- a/tests/src/unit-diagnostics.cpp +++ b/tests/src/unit-diagnostics.cpp @@ -817,8 +817,8 @@ template, struct relocating_map : nlohmann::ordered_map { using base_type = nlohmann::ordered_map; - using typename base_type::iterator; - using typename base_type::Container; + using iterator = typename base_type::iterator; + using Container = typename base_type::Container; using base_type::base_type; template