Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp @@ -20,14 +20,43 @@ #include "test_macros.h" +#if TEST_STD_VER > 14 +template> +struct has_less + : std::false_type +{}; + +template +struct has_less() < std::declval())>> + : std::true_type +{}; +#endif + struct A; // purposefully incomplete +struct B +{ + int x; + B() = default; +}; -int main(int, char**) +template +void test() { - static_assert((std::is_same::element_type, A>::value), ""); + ASSERT_SAME_TYPE(typename std::shared_ptr::element_type, T); #if TEST_STD_VER > 14 - static_assert((std::is_same::weak_type, std::weak_ptr>::value), ""); + ASSERT_SAME_TYPE(typename std::shared_ptr::weak_type, std::weak_ptr); + static_assert(std::is_copy_constructible>::value, ""); + static_assert(std::is_copy_assignable>::value, ""); + static_assert(has_less>::value); #endif +} + +int main(int, char**) +{ + test(); + test(); + test(); + test(); - return 0; + return 0; } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp @@ -15,11 +15,21 @@ #include "test_macros.h" -int main(int, char**) +struct A { }; + +template +void test() { - std::shared_ptr p; + std::shared_ptr p; assert(p.use_count() == 0); assert(p.get() == 0); +} + +int main(int, char**) +{ + test(); + test(); + test(); - return 0; + return 0; } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_copy_move.fail.cpp =================================================================== --- /dev/null +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_copy_move.fail.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// + +// shared_ptr + +// template shared_ptr(const shared_ptr& r); + +#include +#include + +struct A { int x = 42; }; + +struct ADel : std::default_delete +{ + typedef A* pointer; +}; + +int main(int, char**) +{ + static_assert(!(std::is_convertible::value), ""); + + { + std::shared_ptr pA; + std::shared_ptr pi(pA); // expected-error {{no matching constructor for initialization of 'std::shared_ptr'}} + } + { + std::shared_ptr pA; + std::shared_ptr pi(std::move(pA)); // expected-error {{no matching constructor for initialization of 'std::shared_ptr'}} + } + { + std::weak_ptr pA; + std::shared_ptr pi(std::move(pA)); // expected-error {{no matching constructor for initialization of 'std::shared_ptr'}} + } + +#if TEST_STD_VER > 14 + { + std::unique_ptr ui; + std::shared_ptr pi(std::move(ui)); // expected-error {{no matching constructor for initialization of 'std::shared_ptr'}} + } +#endif + + return 0; +} Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp @@ -44,6 +44,7 @@ { std::shared_ptr pA(new A); assert(pA.use_count() == 1); + { B b; std::shared_ptr pB(pA, &b); @@ -60,5 +61,38 @@ assert(A::count == 0); assert(B::count == 0); - return 0; + { + std::shared_ptr p1(nullptr); + std::shared_ptr p2(p1, new int); + assert(p2.get() != nullptr); + } + { + std::shared_ptr p1(new int); + std::shared_ptr p2(p1, nullptr); + assert(p2.get() == nullptr); + } + +#if TEST_STD_VER > 17 + { + std::shared_ptr pA(new A); + assert(pA.use_count() == 1); + + { + B b; + std::shared_ptr pB(std::move(pA), &b); + assert(A::count == 1); + assert(B::count == 1); + assert(pA.use_count() == 2); + assert(pB.use_count() == 2); + assert(pB.get() == &b); + } + assert(pA.use_count() == 1); + assert(A::count == 1); + assert(B::count == 0); + } + assert(A::count == 0); + assert(B::count == 0); +#endif + + return 0; } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -49,6 +49,20 @@ template void assert_deleter ( T * ) { assert(false); } +template +struct StatefulDeleter +{ + int state = 0; + + StatefulDeleter(int val = 0) : state(val) {} + StatefulDeleter(StatefulDeleter const&) { assert(false); } + + void operator()(T* ptr) { + assert(state == 42); + delete ptr; + } +}; + int main(int, char**) { { @@ -83,11 +97,29 @@ assert(A::count == 0); assert(B::count == 0); assert(ptr.get() == 0); -#endif +#endif // TEST_STD_VER >= 11 } } #endif + +#if TEST_STD_VER > 14 + { + std::unique_ptr ptr; + std::shared_ptr p(std::move(ptr)); + assert(p.get() == 0); + assert(p.use_count() == 0); + } +#endif + + { + StatefulDeleter d; + std::unique_ptr&> u(new A, d); + std::shared_ptr p(std::move(u)); + d.state = 42; + assert(A::count == 1); + } assert(A::count == 0); + { // LWG 2399 fn(std::unique_ptr(new int)); } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.private.fail.cpp @@ -26,5 +26,5 @@ { std::shared_ptr p = std::make_shared(); - return 0; + return 0; } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.protected.fail.cpp @@ -24,7 +24,7 @@ int main(int, char**) { - std::shared_ptr p = std::make_shared(); // expected-error-re@memory:* {{static_assert failed{{.*}} "Can't construct object in make_shared"}} + std::shared_ptr p = std::make_shared(); // expected-error@memory:* {{static_assert failed due to requirement 'is_constructible::value' "Can't construct object in make_shared"}} return 0; } Index: test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp @@ -17,16 +17,28 @@ #include "test_macros.h" +struct A +{ + int a; + virtual ~A() {}; +}; +struct B : A { }; + int main(int, char**) { { - const std::shared_ptr p(new int(32)); - assert(p); + const std::shared_ptr p(new int(32)); + assert(p); + } + { + const std::shared_ptr p; + assert(!p); } { - const std::shared_ptr p; - assert(!p); + std::shared_ptr basePtr = std::make_shared(); + std::shared_ptr sp = std::dynamic_pointer_cast(basePtr); + assert(sp); } - return 0; + return 0; } Index: test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp @@ -45,6 +45,7 @@ { { const std::shared_ptr pA(new A); + assert(pA.use_count() == 1); { std::weak_ptr pB; pB = pA; Index: test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp =================================================================== --- test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp +++ test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp @@ -107,5 +107,5 @@ assert(B::count == 0); assert(A::count == 0); - return 0; + return 0; }