Fixing whitespace problems
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@111767 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1 +1,94 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
bool throw_next = false;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
if (throw_next)
|
||||
throw std::bad_alloc();
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::auto_ptr<A> ptr(new A);
|
||||
A* raw_ptr = ptr.get();
|
||||
#ifdef _LIBCPP_MOVE
|
||||
std::shared_ptr<B> p(std::move(ptr));
|
||||
#else
|
||||
std::shared_ptr<B> p(ptr);
|
||||
#endif
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == raw_ptr);
|
||||
assert(ptr.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::auto_ptr<A> ptr(new A);
|
||||
A* raw_ptr = ptr.get();
|
||||
throw_next = true;
|
||||
try
|
||||
{
|
||||
#ifdef _LIBCPP_MOVE
|
||||
std::shared_ptr<B> p(std::move(ptr));
|
||||
#else
|
||||
std::shared_ptr<B> p(ptr);
|
||||
#endif
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(ptr.get() == raw_ptr);
|
||||
}
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr();
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::shared_ptr<int> p;
|
||||
assert(p.use_count() == 0);
|
||||
assert(p.get() == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,22 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr(nullptr_t)
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::shared_ptr<int> p(nullptr);
|
||||
assert(p.use_count() == 0);
|
||||
assert(p.get() == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,47 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class D> shared_ptr(nullptr_t, D d);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "../test_deleter.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
|
||||
assert(A::count == 0);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == 0);
|
||||
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
|
||||
assert(test_deleter<A>::count == 1);
|
||||
assert(test_deleter<A>::dealloc_count == 0);
|
||||
assert(d);
|
||||
assert(d->state() == 3);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
}
|
||||
|
||||
@@ -1 +1,50 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "../test_deleter.h"
|
||||
#include "../test_allocator.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
|
||||
assert(A::count == 0);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == 0);
|
||||
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
|
||||
assert(test_deleter<A>::count == 1);
|
||||
assert(test_deleter<A>::dealloc_count == 0);
|
||||
assert(d);
|
||||
assert(d->state() == 3);
|
||||
assert(test_allocator<A>::count == 1);
|
||||
assert(test_allocator<A>::alloc_count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
assert(test_allocator<A>::count == 0);
|
||||
assert(test_allocator<A>::alloc_count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "../test_deleter.h"
|
||||
#include "../test_allocator.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
test_allocator<A>::throw_after = 0;
|
||||
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_alloc&)
|
||||
{
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
assert(test_allocator<A>::count == 0);
|
||||
assert(test_allocator<A>::alloc_count == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class D> shared_ptr(nullptr_t, D d);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include "../test_deleter.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
bool throw_next = false;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
if (throw_next)
|
||||
throw std::bad_alloc();
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
throw_next = true;
|
||||
try
|
||||
{
|
||||
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_alloc&)
|
||||
{
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class Y> explicit shared_ptr(Y* p);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* ptr = new A;
|
||||
std::shared_ptr<A> p(ptr);
|
||||
assert(A::count == 1);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == ptr);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
A* ptr = new A;
|
||||
std::shared_ptr<void> p(ptr);
|
||||
assert(A::count == 1);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == ptr);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,48 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class Y, class D> shared_ptr(Y* p, D d);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "../test_deleter.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* ptr = new A;
|
||||
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
|
||||
assert(A::count == 1);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == ptr);
|
||||
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
|
||||
assert(test_deleter<A>::count == 1);
|
||||
assert(test_deleter<A>::dealloc_count == 0);
|
||||
assert(d);
|
||||
assert(d->state() == 3);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
}
|
||||
|
||||
@@ -1 +1,51 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "../test_deleter.h"
|
||||
#include "../test_allocator.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* ptr = new A;
|
||||
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
|
||||
assert(A::count == 1);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == ptr);
|
||||
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
|
||||
assert(test_deleter<A>::count == 1);
|
||||
assert(test_deleter<A>::dealloc_count == 0);
|
||||
assert(d);
|
||||
assert(d->state() == 3);
|
||||
assert(test_allocator<A>::count == 1);
|
||||
assert(test_allocator<A>::alloc_count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
assert(test_allocator<A>::count == 0);
|
||||
assert(test_allocator<A>::alloc_count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,47 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "../test_deleter.h"
|
||||
#include "../test_allocator.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
A* ptr = new A;
|
||||
try
|
||||
{
|
||||
test_allocator<A>::throw_after = 0;
|
||||
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_alloc&)
|
||||
{
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
assert(test_allocator<A>::count == 0);
|
||||
assert(test_allocator<A>::alloc_count == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class Y, class D> shared_ptr(Y* p, D d);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include "../test_deleter.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
bool throw_next = false;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
if (throw_next)
|
||||
throw std::bad_alloc();
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
A* ptr = new A;
|
||||
throw_next = true;
|
||||
try
|
||||
{
|
||||
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_alloc&)
|
||||
{
|
||||
assert(A::count == 0);
|
||||
assert(test_deleter<A>::count == 0);
|
||||
assert(test_deleter<A>::dealloc_count == 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template<class Y> explicit shared_ptr(Y* p);
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
bool throw_next = false;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
if (throw_next)
|
||||
throw std::bad_alloc();
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* ptr = new A;
|
||||
throw_next = true;
|
||||
assert(A::count == 1);
|
||||
try
|
||||
{
|
||||
std::shared_ptr<A> p(ptr);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_alloc&)
|
||||
{
|
||||
assert(A::count == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// shared_ptr(const shared_ptr& r);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::shared_ptr<A> pA(new A);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(A::count == 1);
|
||||
{
|
||||
std::shared_ptr<A> pA2(pA);
|
||||
assert(A::count == 1);
|
||||
assert(pA.use_count() == 2);
|
||||
assert(pA2.use_count() == 2);
|
||||
assert(pA2.get() == pA.get());
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA2(pA);
|
||||
assert(A::count == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
assert(pA2.use_count() == 0);
|
||||
assert(pA2.get() == pA.get());
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,97 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class Y> shared_ptr(const shared_ptr<Y>& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct C
|
||||
{
|
||||
static int count;
|
||||
|
||||
C() {++count;}
|
||||
C(const C&) {++count;}
|
||||
virtual ~C() {--count;}
|
||||
};
|
||||
|
||||
int C::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
|
||||
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
|
||||
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
|
||||
{
|
||||
const std::shared_ptr<A> pA(new A);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
{
|
||||
std::shared_ptr<B> pB(pA);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
assert(pB.use_count() == 2);
|
||||
assert(pA.use_count() == 2);
|
||||
assert(pA.get() == pB.get());
|
||||
}
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<B> pB(pA);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
assert(pB.use_count() == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
assert(pA.get() == pB.get());
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,109 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class Y> shared_ptr(shared_ptr<Y>&& r);
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct C
|
||||
{
|
||||
static int count;
|
||||
|
||||
C() {++count;}
|
||||
C(const C&) {++count;}
|
||||
virtual ~C() {--count;}
|
||||
};
|
||||
|
||||
int C::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
|
||||
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
|
||||
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
|
||||
{
|
||||
std::shared_ptr<A> pA(new A);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
{
|
||||
B* p = pA.get();
|
||||
std::shared_ptr<B> pB(std::move(pA));
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
#ifdef _LIBCPP_MOVE
|
||||
assert(pB.use_count() == 1);
|
||||
assert(pA.use_count() == 0);
|
||||
#else // _LIBCPP_MOVE
|
||||
assert(pB.use_count() == 2);
|
||||
assert(pA.use_count() == 2);
|
||||
#endif // _LIBCPP_MOVE
|
||||
assert(p == pB.get());
|
||||
}
|
||||
#ifdef _LIBCPP_MOVE
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
#else // _LIBCPP_MOVE
|
||||
assert(pA.use_count() == 1);
|
||||
assert(B::count == 1);
|
||||
assert(A::count == 1);
|
||||
#endif // _LIBCPP_MOVE
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<B> pB(pA);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
assert(pB.use_count() == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
assert(pA.get() == pB.get());
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(B::count == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,61 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::shared_ptr<A> pA(new A);
|
||||
assert(pA.use_count() == 1);
|
||||
{
|
||||
B b;
|
||||
std::shared_ptr<B> pB(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);
|
||||
}
|
||||
|
||||
@@ -1 +1,73 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// shared_ptr(shared_ptr&& r);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::shared_ptr<A> pA(new A);
|
||||
assert(pA.use_count() == 1);
|
||||
assert(A::count == 1);
|
||||
{
|
||||
A* p = pA.get();
|
||||
std::shared_ptr<A> pA2(std::move(pA));
|
||||
assert(A::count == 1);
|
||||
#ifdef _LIBCPP_MOVE
|
||||
assert(pA.use_count() == 0);
|
||||
assert(pA2.use_count() == 1);
|
||||
#else // _LIBCPP_MOVE
|
||||
assert(pA.use_count() == 2);
|
||||
assert(pA2.use_count() == 2);
|
||||
#endif // _LIBCPP_MOVE
|
||||
assert(pA2.get() == p);
|
||||
}
|
||||
#ifdef _LIBCPP_MOVE
|
||||
assert(pA.use_count() == 0);
|
||||
assert(A::count == 0);
|
||||
#else // _LIBCPP_MOVE
|
||||
assert(pA.use_count() == 1);
|
||||
assert(A::count == 1);
|
||||
#endif // _LIBCPP_MOVE
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA;
|
||||
assert(pA.use_count() == 0);
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> pA2(std::move(pA));
|
||||
assert(A::count == 0);
|
||||
assert(pA.use_count() == 0);
|
||||
assert(pA2.use_count() == 0);
|
||||
assert(pA2.get() == pA.get());
|
||||
}
|
||||
assert(pA.use_count() == 0);
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,86 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r);
|
||||
|
||||
#include <memory>
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
bool throw_next = false;
|
||||
|
||||
void* operator new(std::size_t s) throw(std::bad_alloc)
|
||||
{
|
||||
if (throw_next)
|
||||
throw std::bad_alloc();
|
||||
return std::malloc(s);
|
||||
}
|
||||
|
||||
void operator delete(void* p) throw()
|
||||
{
|
||||
std::free(p);
|
||||
}
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A> ptr(new A);
|
||||
A* raw_ptr = ptr.get();
|
||||
std::shared_ptr<B> p(std::move(ptr));
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(p.use_count() == 1);
|
||||
assert(p.get() == raw_ptr);
|
||||
assert(ptr.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::unique_ptr<A> ptr(new A);
|
||||
A* raw_ptr = ptr.get();
|
||||
throw_next = true;
|
||||
try
|
||||
{
|
||||
std::shared_ptr<B> p(std::move(ptr));
|
||||
assert(false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(ptr.get() == raw_ptr);
|
||||
}
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
@@ -1 +1,79 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// shared_ptr
|
||||
|
||||
// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct B
|
||||
{
|
||||
static int count;
|
||||
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct A
|
||||
: public B
|
||||
{
|
||||
static int count;
|
||||
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::weak_ptr<A> wp;
|
||||
try
|
||||
{
|
||||
std::shared_ptr<A> sp(wp);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_weak_ptr&)
|
||||
{
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
{
|
||||
std::shared_ptr<A> sp0(new A);
|
||||
std::weak_ptr<A> wp(sp0);
|
||||
std::shared_ptr<A> sp(wp);
|
||||
assert(sp.use_count() == 2);
|
||||
assert(sp.get() == sp0.get());
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::shared_ptr<A> sp0(new A);
|
||||
std::weak_ptr<A> wp(sp0);
|
||||
sp0.reset();
|
||||
try
|
||||
{
|
||||
std::shared_ptr<A> sp(wp);
|
||||
assert(false);
|
||||
}
|
||||
catch (std::bad_weak_ptr&)
|
||||
{
|
||||
}
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user