https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77727
Bug ID: 77727
Summary: Unwrapping std::optional constructor is not working
for non-transferable object
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: tomaszkam at gmail dot com
Target Milestone: ---
The following code does not compile:
#include <optional>
struct NonTransferable
{
NonTransferable(int) {}
NonTransferable(NonTransferable&&) = delete;
NonTransferable& operator=(NonTransferable&&) = delete;
};
int main()
{
std::optional<int> oi;
std::optional<NonTransferable> ot(std::move(oi));
std::optional<int> oi2(10);
std::optional<NonTransferable> ot2(oi2);
}
Both the construction of the ot and ot2 shall be well-formed according to
specification from http://cplusplus.github.io/LWG/lwg-active.html#2756 and
call:
optional<T>::optional(optional<U>&&);
optional<T>::optional(optional<U> const&);
constructors respectively as:
is_constructible_v<NonTransferable, int>
is_constructible_v<NonTransferable, int const&>
are true, and the NonTransferable class cannot be constructed/converted from
optional<int>.