|
Boost : |
Subject: Re: [boost] [optional] get() misses optional r-value overload in contrast to operator* and value()
From: Peter Dimov (lists_at_[hidden])
Date: 2018-03-23 16:01:22
Andrzej Krzemienski wrote:
> > const auto& x = func0().value();
...
> I am convinced that you are hitting an UB. Temporary returned by func0()
> is destroyed in the first line.
Interesting question. value() && returns T&&. The auto const& reference
can't bind directly to T&&, because that's not an lvalue. So a temporary
value of type T is created, and the auto const& binds to that, extending its
life. That's of course assuming I read http://eel.is/c++draft/dcl.init.ref
correctly.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk