This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/77727] New: Unwrapping std::optional constructor is not working for non-transferable object
- From: "tomaszkam at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 24 Sep 2016 20:13:31 +0000
- Subject: [Bug libstdc++/77727] New: Unwrapping std::optional constructor is not working for non-transferable object
- Auto-submitted: auto-generated
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>.