Skip to content

Commit

Permalink
⏪ remove "fix" that caused #3077
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Oct 13, 2021
1 parent 4b1cb9e commit 9a35702
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3069,7 +3069,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept(
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
{
ValueType ret{};
ValueType ret;
JSONSerializer<ValueType>::from_json(*this, ret);
return ret;
}
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 @@ -20556,7 +20556,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept(
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
{
ValueType ret{};
ValueType ret;
JSONSerializer<ValueType>::from_json(*this, ret);
return ret;
}
Expand Down
34 changes: 34 additions & 0 deletions test/src/unit-regression2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,32 @@ template<class T>
class my_allocator : public std::allocator<T>
{};

/////////////////////////////////////////////////////////////////////
// for #3077
/////////////////////////////////////////////////////////////////////

class FooAlloc
{};

class Foo
{
public:
explicit Foo(const FooAlloc& = FooAlloc()) : value(false) {}

bool value;
};

class FooBar
{
public:
Foo foo;
};

inline void from_json(const nlohmann::json& j, FooBar& fb)
{
j.at("value").get_to(fb.foo.value);
}

TEST_CASE("regression tests 2")
{
SECTION("issue #1001 - Fix memory leak during parser callback")
Expand Down Expand Up @@ -695,6 +721,14 @@ TEST_CASE("regression tests 2")
json k = json::from_cbor(my_vector);
CHECK(j == k);
}

SECTION("issue #3077 - explicit constructor with default does not compile")
{
json j;
j[0]["value"] = true;
std::vector<FooBar> foo;
j.get_to(foo);
}
}

DOCTEST_CLANG_SUPPRESS_WARNING_POP

0 comments on commit 9a35702

Please sign in to comment.