Fix for LWG Issue 2415: Inconsistency between unique_ptr and shared_ptr

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@236953 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2015-05-10 13:59:45 +00:00
parent 928735abf1
commit 0ad232a882
3 changed files with 37 additions and 11 deletions

View File

@@ -67,7 +67,7 @@ int main()
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
// assert(pB.use_count() == 1); // no longer true due to LWG 2415
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
@@ -101,7 +101,7 @@ int main()
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
// assert(pB.use_count() == 1); // no longer true due to LWG 2415
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}

View File

@@ -58,6 +58,9 @@ int A::count = 0;
void fn ( const std::shared_ptr<int> &) {}
void fn ( const std::shared_ptr<B> &) { assert (false); }
template <typename T>
void assert_deleter ( T * ) { assert(false); }
int main()
{
{
@@ -100,4 +103,13 @@ int main()
throw_next = false;
fn(std::unique_ptr<int>(new int));
}
#if __cplusplus >= 201402L
// LWG 2415
{
std::unique_ptr<int, void (*)(int*)> p(nullptr, assert_deleter<int>);
std::shared_ptr<int> p2(std::move(p)); // should not call deleter when going out of scope
}
#endif
}