// T is move-only
std::optional<T>&& foo() {
T t = MakeT();
// ~T() invoked here
return std::move(std::optional<T>(std::move(t)));
}
void bar() {
auto opt = foo();
// opt.has_value() is false here
}
Using a C++17-compatible compiler, I have a type T
for which the above occurs. I do not understand the properties of T
that cause this to occur, or how to force the move.
It seems like t
is moved into the std::optional
correctly - but moveing the local std::optional
(a) resets the std::optional
, and (b) fails to call T
s move-assignment operator.