diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 6fd0be52d..676b36290 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -650,9 +650,16 @@ class json_sax_dom_parser : public json_sax_dom_error_state /// so that a big object can find the keys it has in a hash table instead of /// searching all of them template - using detect_indexable_keys = decltype(std::declval().emplace_new_key(std::declval(), std::declval()), - std::hash()(std::declval())); - static constexpr bool indexed_keys = is_detected::value; + using detect_emplace_new_key = decltype(std::declval().emplace_new_key(std::declval(), std::declval())); + template + using detect_hash = decltype(std::hash()(std::declval())); + /// (std::hash is only looked at for objects in a vector: the one of VS 2015 + /// fails to compile, instead of being undetectable, for a type it does not hash) + template + struct has_indexable_keys : std::false_type {}; + template + struct has_indexable_keys : is_detected {}; + static constexpr bool indexed_keys = has_indexable_keys::value, string_t>::value; /// what a frame holds for objects that are kept in a vector: the key index /// of an object with many keys, and for an object that is collected on the @@ -774,7 +781,11 @@ class json_sax_dom_parser : public json_sax_dom_error_state { const std::size_t new_capacity = capacity * 2; std::unique_ptr new_heap(new frame[new_capacity]); // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - std::copy(data, data + count, new_heap.get()); + // (a loop, not std::copy: VS 2015 rejects std::copy to a raw pointer, C4996) + for (std::size_t i = 0; i < count; ++i) + { + new_heap[i] = data[i]; + } heap = std::move(new_heap); data = heap.get(); capacity = new_capacity; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a9e40693d..fc4d96ccb 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -15773,9 +15773,16 @@ class json_sax_dom_parser : public json_sax_dom_error_state /// so that a big object can find the keys it has in a hash table instead of /// searching all of them template - using detect_indexable_keys = decltype(std::declval().emplace_new_key(std::declval(), std::declval()), - std::hash()(std::declval())); - static constexpr bool indexed_keys = is_detected::value; + using detect_emplace_new_key = decltype(std::declval().emplace_new_key(std::declval(), std::declval())); + template + using detect_hash = decltype(std::hash()(std::declval())); + /// (std::hash is only looked at for objects in a vector: the one of VS 2015 + /// fails to compile, instead of being undetectable, for a type it does not hash) + template + struct has_indexable_keys : std::false_type {}; + template + struct has_indexable_keys : is_detected {}; + static constexpr bool indexed_keys = has_indexable_keys::value, string_t>::value; /// what a frame holds for objects that are kept in a vector: the key index /// of an object with many keys, and for an object that is collected on the @@ -15897,7 +15904,11 @@ class json_sax_dom_parser : public json_sax_dom_error_state { const std::size_t new_capacity = capacity * 2; std::unique_ptr new_heap(new frame[new_capacity]); // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) - std::copy(data, data + count, new_heap.get()); + // (a loop, not std::copy: VS 2015 rejects std::copy to a raw pointer, C4996) + for (std::size_t i = 0; i < count; ++i) + { + new_heap[i] = data[i]; + } heap = std::move(new_heap); data = heap.get(); capacity = new_capacity;