//===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 // // unique_ptr // Test unique_ptr converting move assignment #include #include #include #include "unique_ptr_test_helper.h" template void testAssign(APtr& aptr, BPtr& bptr) { A* p = bptr.get(); assert(A::count == 2); aptr = std::move(bptr); assert(aptr.get() == p); assert(bptr.get() == 0); assert(A::count == 1); assert(B::count == 1); } template void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { assert(lhs.get_deleter().state() == LHSState); assert(rhs.get_deleter().state() == RHSState); } template struct NCConvertingDeleter { NCConvertingDeleter() = default; NCConvertingDeleter(NCConvertingDeleter const&) = delete; NCConvertingDeleter(NCConvertingDeleter&&) = default; template NCConvertingDeleter(NCConvertingDeleter&&) {} void operator()(T*) const {} }; template struct NCConvertingDeleter { NCConvertingDeleter() = default; NCConvertingDeleter(NCConvertingDeleter const&) = delete; NCConvertingDeleter(NCConvertingDeleter&&) = default; template NCConvertingDeleter(NCConvertingDeleter&&) {} void operator()(T*) const {} }; struct GenericDeleter { void operator()(void*) const; }; struct NCGenericDeleter { NCGenericDeleter() = default; NCGenericDeleter(NCGenericDeleter const&) = delete; NCGenericDeleter(NCGenericDeleter&&) = default; void operator()(void*) const {} }; void test_sfinae() { using DA = NCConvertingDeleter; // non-copyable deleters using DAC = NCConvertingDeleter; // non-copyable deleters using UA = std::unique_ptr; using UAC = std::unique_ptr; using UAD = std::unique_ptr; using UACD = std::unique_ptr; { // cannot move from an lvalue static_assert(std::is_assignable::value, ""); static_assert(!std::is_assignable::value, ""); static_assert(!std::is_assignable::value, ""); } { // cannot move if the deleter-types cannot convert static_assert(std::is_assignable::value, ""); static_assert(!std::is_assignable::value, ""); static_assert(!std::is_assignable::value, ""); } { // cannot move-convert with reference deleters of different types using UA1 = std::unique_ptr; using UA2 = std::unique_ptr; static_assert(!std::is_assignable::value, ""); } { // cannot move-convert with reference deleters of different types using UA1 = std::unique_ptr; using UA2 = std::unique_ptr; static_assert(!std::is_assignable::value, ""); } { // cannot move-convert from unique_ptr using UA1 = std::unique_ptr; using UA2 = std::unique_ptr; static_assert(!std::is_assignable::value, ""); } { // cannot move-convert from unique_ptr using UA1 = std::unique_ptr; using UA2 = std::unique_ptr; static_assert(!std::is_assignable::value, ""); } } int main() { test_sfinae(); // FIXME: add tests }