Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Differential D135548 Diff 468702 libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | int main(int, char**) | ||||
delete pi; | delete pi; | ||||
{ | { | ||||
std::shared_ptr<int> p1(new int); | std::shared_ptr<int> p1(new int); | ||||
std::shared_ptr<int> p2(p1, nullptr); | std::shared_ptr<int> p2(p1, nullptr); | ||||
assert(p2.get() == nullptr); | assert(p2.get() == nullptr); | ||||
} | } | ||||
#if TEST_STD_VER > 17 && defined(_LIBCPP_VERSION) | #if TEST_STD_VER > 17 && defined(_LIBCPP_VERSION) | ||||
// This won't pass when LWG-2996 is implemented. | |||||
{ | { | ||||
std::shared_ptr<A> pA(new A); | std::shared_ptr<A> pA(new A); | ||||
assert(pA.use_count() == 1); | assert(pA.use_count() == 1); | ||||
# if TEST_STD_VER > 20 | |||||
// LWG-2996 is only implemented in c++20 and beyond. | |||||
// We don't backport because it is an evolutionary change. | |||||
{ | |||||
B b; | |||||
std::shared_ptr<B> pB(std::move(pA), &b); | |||||
assert(A::count == 1); | |||||
assert(B::count == 1); | |||||
assert(pA.use_count() == 0); | |||||
assert(pB.use_count() == 1); | |||||
assert(pB.get() == &b); | |||||
} | |||||
# else | |||||
{ | { | ||||
B b; | B b; | ||||
std::shared_ptr<B> pB(std::move(pA), &b); | std::shared_ptr<B> pB(std::move(pA), &b); | ||||
assert(A::count == 1); | assert(A::count == 1); | ||||
assert(B::count == 1); | assert(B::count == 1); | ||||
assert(pA.use_count() == 2); | assert(pA.use_count() == 2); | ||||
assert(pB.use_count() == 2); | assert(pB.use_count() == 2); | ||||
assert(pB.get() == &b); | assert(pB.get() == &b); | ||||
} | } | ||||
assert(pA.use_count() == 1); | assert(pA.use_count() == 1); | ||||
assert(A::count == 1); | assert(A::count == 1); | ||||
assert(B::count == 0); | assert(B::count == 0); | ||||
philnik: I'd just remove this test. I don't really see the point of testing this, since it's… | |||||
# endif // TEST_STD_VER > 20 | |||||
} | } | ||||
assert(A::count == 0); | assert(A::count == 0); | ||||
assert(B::count == 0); | assert(B::count == 0); | ||||
#endif | #endif | ||||
return 0; | return 0; | ||||
} | } |
I'd just remove this test. I don't really see the point of testing this, since it's questionable to rely on this behaviour and it's been changed with an LWG issue which some implementations back-port.