Topic: [N4529] [optional.object.observe] Is it ok to


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 6 Jun 2015 22:50:29 +0300
Raw View
On 6 June 2015 at 22:16, Kazutoshi Satoda <k_satoda@f2.dion.ne.jp> wrote:
> Rvalue overloads of observer member functions of
> std::experimental::optional are specified to return rvalue reference
> into possibly temporary *this.
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4529.html#optional.object.observe
>> constexpr T&& value() &&;
>> constexpr const T&& value() const &&;
>>
>> Effects:
>>     Equivalent to return bool(*this) ? std::move(*val) : throw bad_optional_access();
>
> That may cause dangling references as shown bellow:

We know.

> Is it ok to have such risk in standard library interface?

Yes.

> (Shouldn't it return a moved value to be safer?)

No, because that disturbs forwarding uses.
https://issues.isocpp.org/show_bug.cgi?id=45

> FYI, I'm considering to propose a change of any_cast to reduce
> unnecessary copy, and looked for what other components do, and came to

I have already reported that issue to LWG. I will file an issue about it soon.

> I think it might be a good library-wide guideline not to return rvalue
> reference except by move-related utilities like std::move().

I don't.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Kazutoshi Satoda <k_satoda@f2.dion.ne.jp>
Date: Sun, 07 Jun 2015 05:47:17 +0900
Raw View
On 2015/06/07 4:50, Ville Voutilainen wrote:
> On 6 June 2015 at 22:16, Kazutoshi Satoda <k_satoda@f2.dion.ne.jp> wrote:
....
>> That may cause dangling references as shown bellow:
>
> We know.
>
>> Is it ok to have such risk in standard library interface?
>
> Yes.
>
>> (Shouldn't it return a moved value to be safer?)
>
> No, because that disturbs forwarding uses.
> https://issues.isocpp.org/show_bug.cgi?id=45

Thank you for the link. And I'm sorry that I couldn't find it and
linked discussions before the post.

Now I understood that forwarding cases got priority over local
reference variable case.

--
k_satoda

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Sat, 6 Jun 2015 23:51:08 +0300
Raw View
On 6 June 2015 at 23:47, Kazutoshi Satoda <k_satoda@f2.dion.ne.jp> wrote:
>> No, because that disturbs forwarding uses.
>> https://issues.isocpp.org/show_bug.cgi?id=45
> Thank you for the link. And I'm sorry that I couldn't find it and
> linked discussions before the post.

No need to apologize, these things aren't always easy to find and I knew
exactly what to look for and where. ;)

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.