1
0
mirror of https://github.com/nlohmann/json synced 2024-11-08 21:50:07 +00:00

Fixed init-list construction when size_type is not int (#4140)

This commit is contained in:
tomalakgeretkal 2023-09-23 16:21:40 +01:00 committed by GitHub
parent e75b94b31e
commit 6e36c721f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -906,7 +906,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
bool is_an_object = std::all_of(init.begin(), init.end(),
[](const detail::json_ref<basic_json>& element_ref)
{
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
// The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int;
// (many string types can be constructed from 0 via its null-pointer guise, so we get a
// broken call to op[key_type], the wrong semantics and a 4804 warning on Windows)
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
});
// adjust type if type deduction is not wanted

View File

@ -20112,7 +20112,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
bool is_an_object = std::all_of(init.begin(), init.end(),
[](const detail::json_ref<basic_json>& element_ref)
{
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
// The cast is to ensure op[size_type] is called, bearing in mind size_type may not be int;
// (many string types can be constructed from 0 via its null-pointer guise, so we get a
// broken call to op[key_type], the wrong semantics and a 4804 warning on Windows)
return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
});
// adjust type if type deduction is not wanted