-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: returning reference to local temporary object #2064
Comments
More context:
and
and
|
This issue was introduced in #1662. Compared to the other structured types (string, array, object), the binary types do not coincide: using other_string_t = typename BasicJsonType::string_t;
using other_object_t = typename BasicJsonType::object_t;
using other_array_t = typename BasicJsonType::array_t;
using other_binary_t = typename BasicJsonType::internal_binary_t; So the call JSONSerializer<other_binary_t>::to_json(*this, val.template get_ref<const other_binary_t&>()); calls However, we only have overloads for /// get a pointer to the value (binary)
constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept
{
return is_binary() ? m_value.binary : nullptr;
} |
@OmnipotentEntity Any idea on this one? |
Oh dear. So there's two ways to fix this, neither of which I particularly like:
Downsides of (1) are exposing an implementation detail, and the structure of the internally represented type being slightly surprising (but convertible to the expected type, and having the same interface as the expected type.) Downsides of (2) is every json object will have to pay an extra 2 bytes of space + padding. I'm personally for (1), and I can submit a patch to fix it next weekend. But the patch should be reasonably trivial to write if you can't wait (I'm just away from my computer for a while due to a nature vacation). |
Thanks for the quick response! I'm not sure whether it is what you meant with (1), but adding these overloads fixes the warning: /// 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;
} What do you think? |
That's what I meant by (1). I had misgivings about it because it would involve exposing an |
Clang reports the following warning:
Context:
The text was updated successfully, but these errors were encountered: