Hi Viktor,
Thank you for reporting this. This is an omission (a bug) that I will need
to fix. I have created an issue in GitHub to track it:
https://github.com/boostorg/optional/issues/51.
On the other hand, I do not think that the bug is causing an UB any more
than function `value()` in your example. Unless something has changed in
the way temporaries' life is prolonged in C++17. I tested it for `int`s and
all tests work fine. I tested it on `unique_ptr<int>`:
```
#include <memory>
#include <iostream>
#include
Both *value()* and *operator** has an overload to handle if the *optional<T>* object is an r-value. However *get()* does not have the r-value overload.
This leads to undefined behavior using *get()*, but not with *operator** and *value()*, in the following example:
auto func0() { return optional<int>{3}; } auto func1() { const auto& x = func0().get(); // Undefined behavior const auto& y = func0().value(); // Correct const auto& z = *func0(); // Correct }
Is this intended, I can't see any reason why the r-value overload of .get() would be missing? Otherwise, the following overload of .get() should be added:
reference_type_of_temporary_wrapper get() && { BOOST_ASSERT(this->is_initialized()); return boost::move(this->get_impl()); }
/Viktor Sehr, Software Developer at Toppluva
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/ mailman/listinfo.cgi/boost