using _Alloc_traits = allocator_traits<_Alloc>;
_Alloc __a;
_Sp_cd_type* __mem = _Alloc_traits::allocate(__a, 1);
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3548. shared_ptr construction from unique_ptr should move
+ // (not copy) the deleter
_Alloc_traits::construct(__a, __mem, __r.release(),
- __r.get_deleter()); // non-throwing
+ std::forward<_Del>(__r.get_deleter()));
_M_pi = __mem;
}
// Constraint for construction from unique_ptr:
template<typename _Yp, typename _Del, typename _Res = void,
typename _Ptr = typename unique_ptr<_Yp, _Del>::pointer>
- using _UniqCompatible = typename enable_if<__and_<
- __sp_compatible_with<_Yp*, _Tp*>, is_convertible<_Ptr, element_type*>
- >::value, _Res>::type;
+ using _UniqCompatible = __enable_if_t<__and_<
+ __sp_compatible_with<_Yp*, _Tp*>,
+ is_convertible<_Ptr, element_type*>,
+ is_move_constructible<_Del>
+ >::value, _Res>;
// Constraint for assignment from unique_ptr:
template<typename _Yp, typename _Del>
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <memory>
+
+// LWG 3548
+// shared_ptr construction from unique_ptr should move (not copy) the deleter
+
+struct D
+{
+ D() { }
+ D(D&&) { }
+ void operator()(int* p) const { delete p; }
+};
+
+std::unique_ptr<int, D> u;
+std::shared_ptr<int> s1(std::move(u));
VERIFY( D::count == 0 ); // LWG 2415
}
+void
+test03()
+{
+ struct D
+ {
+ D() = default;
+ D(const D&) = delete; // not copyable or movable
+ void operator()(int* p) const { delete p; }
+ };
+
+ using namespace std;
+ static_assert( ! is_constructible<shared_ptr<int>, unique_ptr<int, D>>(),
+ "Constraints: is_move_constructible_v<D> is true" );
+}
+
int
main()
{
test01();
test02();
- return 0;
+ test03();
}