https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81190
Bug ID: 81190 Summary: std::optional doesn't compile with containers that have noncopyable types Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: lyberta at lyberta dot net Target Milestone: --- The following code will compile perfectly with std::experimental::optional but will produce compiler errors with std::optional: #include <iostream> #include <optional> #include <memory> #include <map> class Foo { public: Foo(std::unique_ptr<int> a) { m1.emplace(42, std::move(a)); } private: std::map<int, std::unique_ptr<int>> m1; }; int main() { std::optional<Foo> opt; opt.emplace(std::make_unique<int>(42)); opt = std::nullopt; }