Skip to content

Commit

Permalink
Fix constraints on from_json(CompatibleArrayType)
Browse files Browse the repository at this point in the history
  • Loading branch information
theodelrieu committed Feb 12, 2018
1 parent 447f542 commit 5a6cc0c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priorit

template<typename BasicJsonType, typename CompatibleArrayType,
enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value and
std::is_convertible<BasicJsonType, typename CompatibleArrayType::value_type>::value and
has_from_json<BasicJsonType, typename CompatibleArrayType::value_type>::value and
not std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value, int> = 0>
void from_json(const BasicJsonType& j, CompatibleArrayType& arr)
{
Expand Down
2 changes: 1 addition & 1 deletion single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ void from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, priorit

template<typename BasicJsonType, typename CompatibleArrayType,
enable_if_t<is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value and
std::is_convertible<BasicJsonType, typename CompatibleArrayType::value_type>::value and
has_from_json<BasicJsonType, typename CompatibleArrayType::value_type>::value and
not std::is_same<typename BasicJsonType::array_t, CompatibleArrayType>::value, int> = 0>
void from_json(const BasicJsonType& j, CompatibleArrayType& arr)
{
Expand Down
4 changes: 2 additions & 2 deletions test/src/unit-inspection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ TEST_CASE("object inspection")
SECTION("round trips")
{
for (const auto& s :
{"3.141592653589793", "1000000000000000010E5"
})
{"3.141592653589793", "1000000000000000010E5"
})
{
json j1 = json::parse(s);
std::string s1 = j1.dump();
Expand Down
22 changes: 22 additions & 0 deletions test/src/unit-udt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,25 @@ TEST_CASE("an incomplete type does not trigger a compiler error in non-evaluated
{
static_assert(not is_constructible_patched<json, incomplete>::value, "");
}

namespace
{
class Evil
{
public:
Evil() = default;
template <typename T>
Evil(T) {}
};

void from_json(const json&, Evil&) {}
}

TEST_CASE("Issue #924")
{
// Prevent get<std::vector<Evil>>() to throw
auto j = json::array();

(void) j.get<Evil>();
(void) j.get<std::vector<Evil>>();
}

0 comments on commit 5a6cc0c

Please sign in to comment.