Skip to content

Commit

Permalink
Merge pull request #2069 from nlohmann/issue2064
Browse files Browse the repository at this point in the history
Fix returning reference to local temporary object
  • Loading branch information
nlohmann authored Apr 28, 2020
2 parents d9d1279 + 9e0180b commit b1fe6ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
12 changes: 12 additions & 0 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,18 @@ class basic_json
return is_binary() ? m_value.binary : nullptr;
}

/// get a pointer to the value (binary)
internal_binary_t* get_impl_ptr(internal_binary_t* /*unused*/) noexcept
{
return is_binary() ? m_value.binary : nullptr;
}

/// get a pointer to the value (binary)
constexpr const internal_binary_t* get_impl_ptr(const internal_binary_t* /*unused*/) const noexcept
{
return is_binary() ? m_value.binary : nullptr;
}

/*!
@brief helper function to implement get_ref()
Expand Down
12 changes: 12 additions & 0 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18243,6 +18243,18 @@ class basic_json
return is_binary() ? m_value.binary : nullptr;
}

/// get a pointer to the value (binary)
internal_binary_t* get_impl_ptr(internal_binary_t* /*unused*/) noexcept
{
return is_binary() ? m_value.binary : nullptr;
}

/// get a pointer to the value (binary)
constexpr const internal_binary_t* get_impl_ptr(const internal_binary_t* /*unused*/) const noexcept
{
return is_binary() ? m_value.binary : nullptr;
}

/*!
@brief helper function to implement get_ref()

Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-constructor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ TEST_CASE("constructors")

// check that NaN is serialized to null
CHECK(j.dump() == "null");
}
}

SECTION("infinity")
{
Expand Down

0 comments on commit b1fe6ee

Please sign in to comment.