From dbfc89891cd071be148627641c920dc76ce499a7 Mon Sep 17 00:00:00 2001 From: Muhammad Arif bin Mohamad Ghazaly Date: Sat, 30 Nov 2024 16:54:52 -0500 Subject: [PATCH] partial fix for #4358 --- .../nlohmann/detail/conversions/from_json.hpp | 19 +++++++++++++++---- single_include/nlohmann/json.hpp | 19 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index ecc347d9fd..6b04ce2896 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -203,7 +203,7 @@ inline void from_json(const BasicJsonType& j, std::valarray& l) } template -auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +auto from_json(const BasicJsonType& j, T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) -> decltype(j.template get(), void()) { for (std::size_t i = 0; i < N; ++i) @@ -378,8 +378,19 @@ inline void from_json(const BasicJsonType& j, ArithmeticType& val) val = static_cast(*j.template get_ptr()); break; } - case value_t::boolean: + { + if ((sizeof(ArithmeticType) == 1) && std::is_unsigned::value) + { + val = static_cast(*j.template get_ptr()); + } + else + { + get_arithmetic_value(j, val); + } + break; + } + case value_t::null: case value_t::object: case value_t::array: @@ -400,8 +411,8 @@ std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence< template < typename BasicJsonType, class A1, class A2 > std::pair from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) { - return {std::forward(j).at(0).template get(), - std::forward(j).at(1).template get()}; + return { std::forward(j).at(0).template get(), + std::forward(j).at(1).template get() }; } template diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 36b26baf81..0338896892 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -4876,7 +4876,7 @@ inline void from_json(const BasicJsonType& j, std::valarray& l) } template -auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +auto from_json(const BasicJsonType& j, T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) -> decltype(j.template get(), void()) { for (std::size_t i = 0; i < N; ++i) @@ -5051,8 +5051,19 @@ inline void from_json(const BasicJsonType& j, ArithmeticType& val) val = static_cast(*j.template get_ptr()); break; } - case value_t::boolean: + { + if ((sizeof(ArithmeticType) == 1) && std::is_unsigned::value) + { + val = static_cast(*j.template get_ptr()); + } + else + { + get_arithmetic_value(j, val); + } + break; + } + case value_t::null: case value_t::object: case value_t::array: @@ -5073,8 +5084,8 @@ std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence< template < typename BasicJsonType, class A1, class A2 > std::pair from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) { - return {std::forward(j).at(0).template get(), - std::forward(j).at(1).template get()}; + return { std::forward(j).at(0).template get(), + std::forward(j).at(1).template get() }; } template