Skip to content

Commit

Permalink
🐛 fix returning reference to local temporary object #2064
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Apr 27, 2020
1 parent d9d1279 commit 9e0180b
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 9e0180b

Please sign in to comment.