This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/81190] New: std::optional doesn't compile with containers that have noncopyable types


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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]