http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60019
Bug ID: 60019 Summary: [C++11] Bogus error: use of deleted function unique_ptr(const unique_ptr&) Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ppluzhnikov at google dot com Google ref: b/12846752 Test: #include <memory> struct S {}; struct T : S {}; std::unique_ptr<T> F(); const std::unique_ptr<S> s = F(); Using recent trunk: g++ (GCC) 4.9.0 20140129 (experimental) t.cc:6:32: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = S; _Dp = std::default_delete<S>]’ const std::unique_ptr<S> s = F(); ^ There is a copy constructor in unique_ptr.h that I believe is supposed to apply here: /** @brief Converting constructor from another type * * Requires that the pointer owned by @p __u is convertible to the * type of pointer owned by this object, @p __u does not own an array, * and @p __u has a compatible deleter type. */ template<typename _Up, typename _Ep, typename = _Require< is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>, __not_<is_array<_Up>>, typename conditional<is_reference<_Dp>::value, is_same<_Ep, _Dp>, is_convertible<_Ep, _Dp>>::type>> unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept : _M_t(__u.release(), std::forward<_Ep>(__u.get_deleter())) { } but for some reason it doesn't kick in. (Code builds fine under Clang.)