https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96537

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
>   std::unordered_map<int, std::unique_ptr<A>> m;
>   m.emplace (1, new A(1));

This code isn't exception-safe anyway. If allocating a new node in the map
throws an exception your pointer will be leaked.

This will compile on old C++11 compilers *and* be correct:

  m.emplace (1, std::unique_ptr<A>(new A(1)));

For C++14 you should use std::make_unique<A>(1) instead.

Reply via email to