diff options
Diffstat (limited to 'libcxx/test/utilities/memory/util.smartptr')
71 files changed, 71 insertions, 71 deletions
diff --git a/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index 595d05c28e9..d4618719cfb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// template<class T>
// class enable_shared_from_this
// {
// protected:
// enable_shared_from_this();
// enable_shared_from_this(enable_shared_from_this const&);
// enable_shared_from_this& operator=(enable_shared_from_this const&);
// ~enable_shared_from_this();
// public:
// shared_ptr<T> shared_from_this();
// shared_ptr<T const> shared_from_this() const;
// };
#include <memory>
#include <cassert>
struct T
: public std::enable_shared_from_this<T>
{
};
struct Y : T {};
struct Z : Y {};
int main()
{
{
std::shared_ptr<Y> p(new Z);
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
{
std::shared_ptr<Y> p = std::make_shared<Z>();
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// template<class T>
// class enable_shared_from_this
// {
// protected:
// enable_shared_from_this();
// enable_shared_from_this(enable_shared_from_this const&);
// enable_shared_from_this& operator=(enable_shared_from_this const&);
// ~enable_shared_from_this();
// public:
// shared_ptr<T> shared_from_this();
// shared_ptr<T const> shared_from_this() const;
// };
#include <memory>
#include <cassert>
struct T
: public std::enable_shared_from_this<T>
{
};
struct Y : T {};
struct Z : Y {};
int main()
{
{
std::shared_ptr<Y> p(new Z);
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
{
std::shared_ptr<Y> p = std::make_shared<Z>();
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h index e1cdbbdd236..b9aeeebcd66 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
struct test_deleter_base
{
static int count;
static int dealloc_count;
};
int test_deleter_base::count = 0;
int test_deleter_base::dealloc_count = 0;
template <class T>
class test_deleter
: public test_deleter_base
{
int state_;
public:
test_deleter() : state_(0) {++count;}
explicit test_deleter(int s) : state_(s) {++count;}
test_deleter(const test_deleter& d)
: state_(d.state_) {++count;}
~test_deleter() {assert(state_ >= 0); --count; state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;}
};
template <class T>
void
swap(test_deleter<T>& x, test_deleter<T>& y)
{
test_deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
struct test_deleter_base
{
static int count;
static int dealloc_count;
};
int test_deleter_base::count = 0;
int test_deleter_base::dealloc_count = 0;
template <class T>
class test_deleter
: public test_deleter_base
{
int state_;
public:
test_deleter() : state_(0) {++count;}
explicit test_deleter(int s) : state_(s) {++count;}
test_deleter(const test_deleter& d)
: state_(d.state_) {++count;}
~test_deleter() {assert(state_ >= 0); --count; state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;}
};
template <class T>
void
swap(test_deleter<T>& x, test_deleter<T>& y)
{
test_deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp index 719a6515faa..09aa877d2cd 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class shared_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class shared_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp index 651a922a06c..e12dc2fa6c7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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, class T> D* get_deleter(const shared_ptr<T>& p);
#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));
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);
}
test_deleter<A>::dealloc_count = 0;
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
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);
}
test_deleter<A>::dealloc_count = 0;
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p);
assert(d == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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, class T> D* get_deleter(const shared_ptr<T>& p);
#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));
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);
}
test_deleter<A>::dealloc_count = 0;
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
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);
}
test_deleter<A>::dealloc_count = 0;
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p);
assert(d == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp index 16b9aa2afed..09a95ec2478 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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& operator=(auto_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;
int main()
{
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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& operator=(auto_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;
int main()
{
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp index 3171daa3cd6..8e1bb81afcc 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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& operator=(const shared_ptr& 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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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& operator=(const shared_ptr& 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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp index 83b1ea2ec69..a13b1fd2fef 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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& operator=(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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new 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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new 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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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& operator=(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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new 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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new 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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
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(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp index cb6ea09e139..e4142cda701 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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& operator=(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;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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& operator=(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;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp index d15ddaf7d78..d2691b06700 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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& operator=(shared_ptr&& 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;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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& operator=(shared_ptr&& 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;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp index 98434a380c3..75b20bfd12b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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& operator=(unique_ptr<Y, D>&& 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;
int main()
{
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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& operator=(unique_ptr<Y, D>&& 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;
int main()
{
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp index abf973c225f..0196cf9b26b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& 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;
int main()
{
{
const std::shared_ptr<const A> pA(new A);
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<const A> pA;
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& 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;
int main()
{
{
const std::shared_ptr<const A> pA(new A);
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<const A> pA;
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp index ca4975b48c1..ad2b6a4b72e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& 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;
int main()
{
{
const std::shared_ptr<B> pB(new A);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == pB.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pB(new B);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == 0);
assert(pA.use_count() == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& 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;
int main()
{
{
const std::shared_ptr<B> pB(new A);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == pB.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pB(new B);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == 0);
assert(pA.use_count() == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp index 232d3cae0e8..03146c1c4e2 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& 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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA(new A);
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<A> pA;
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA;
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& 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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA(new A);
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<A> pA;
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA;
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp index 98be66f0416..a8ae78813a8 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b);
// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert(p1 != p2);
assert(p2 == p3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b);
// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert(p1 != p2);
assert(p2 == p3);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp index 07620db5830..e5a94e9324b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert((p1 < p2) == (ptr1 < ptr2));
assert(!(p2 < p3) && !(p3 < p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert((p1 < p2) == (ptr1 < ptr2));
assert(!(p2 < p3) && !(p3 < p2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp index b43c164b02d..eca83722175 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp index 4f63d8140ec..fa55289d9f4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp index ffab43c7716..6853ca698ab 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp index eb498631ba4..6e75c3f2e22 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp index 0bbb8720c95..c27df0e9a37 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp index c4c2201fe54..017fa7aaa95 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp index 19838255763..86e9e7a14d8 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp index caebd4ae700..28a5a57edea 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp index 1e62565cf50..9db6b0c8d68 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp index e6f39ee2b54..e340c76e248 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp index 40d6aa9d1c7..4fd7f6c1396 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp index ac7f603161a..5596cdaec9b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp index b5b217e4a7d..4b47a5c0aa6 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp index 5cdec2b3884..0ee5cca1dc7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp index ef79110ca02..a2bc56202bb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp index 66a7b1b78ea..a7b1b1cff05 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
#endif
assert(p == pB.get());
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
#endif
}
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
#endif
assert(p == pB.get());
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
#endif
}
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp index 39545a3f128..565d77ff71a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp index 2db8fe5a660..f6528b2cb28 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
#endif
assert(pA2.get() == p);
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(A::count == 1);
#endif
}
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
#endif
assert(pA2.get() == p);
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(A::count == 1);
#endif
}
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp index c0a2f766280..9f57052860e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp index 639689c5222..aa9fbf50377 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp index acd08849365..49ad98cd279 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class A, class... Args>
// shared_ptr<T> allocate_shared(const A& a, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
#include "../test_allocator.h"
int new_count = 0;
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
assert(test_allocator<A>::alloc_count == 1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class A, class... Args>
// shared_ptr<T> allocate_shared(const A& a, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
#include "../test_allocator.h"
int new_count = 0;
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
assert(test_allocator<A>::alloc_count == 1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp index 723c9a821f5..2db9c66569e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T, class... Args> shared_ptr<T> make_shared(Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_count = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_count;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
int nc = new_count;
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::make_shared<A>(i, c);
assert(new_count == nc+1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T, class... Args> shared_ptr<T> make_shared(Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_count = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_count;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
int nc = new_count;
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::make_shared<A>(i, c);
assert(new_count == nc+1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp index ae993c2dd24..c39bec74cd7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp index 1d624b2925d..27d9eb93450 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void reset();
#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::shared_ptr<B> p(new B);
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void reset();
#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::shared_ptr<B> p(new B);
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp index 1ee745c8c51..13656f51849 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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> void reset(Y* p);
#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::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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> void reset(Y* p);
#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::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp index 30a19d151fc..b4bdd8654e5 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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> void reset(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
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::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::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);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::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 == 1);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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> void reset(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
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::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::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);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::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 == 1);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp index 67244be1d00..a318f68caf4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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, class A> void reset(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
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::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::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);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::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 == 1);
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 == 2);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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, class A> void reset(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
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::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::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);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::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 == 1);
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 == 2);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp index 55111376859..6f75444e632 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void swap(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()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void swap(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()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp index 1cc04e0cf6d..14646f0392a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T* operator->() const;
#include <memory>
#include <utility>
#include <cassert>
int main()
{
const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4));
assert(p->first == 3);
assert(p->second == 4);
p->first = 5;
p->second = 6;
assert(p->first == 5);
assert(p->second == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T* operator->() const;
#include <memory>
#include <utility>
#include <cassert>
int main()
{
const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4));
assert(p->first == 3);
assert(p->second == 4);
p->first = 5;
p->second = 6;
assert(p->first == 5);
assert(p->second == 6);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp index 55b745eb174..b02af0f1cfb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T& operator*() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(*p == 32);
*p = 3;
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T& operator*() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(*p == 32);
*p = 3;
assert(*p == 3);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp index 2855d5be0f2..f0661fb318c 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// explicit operator bool() const;
#include <memory>
#include <cassert>
int main()
{
{
const std::shared_ptr<int> p(new int(32));
assert(p);
}
{
const std::shared_ptr<int> p;
assert(!p);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// explicit operator bool() const;
#include <memory>
#include <cassert>
int main()
{
{
const std::shared_ptr<int> p(new int(32));
assert(p);
}
{
const std::shared_ptr<int> p;
assert(!p);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp index 1184b3c8823..b5aeff5e818 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 U> bool owner_before(shared_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
assert(!p1.owner_before(p2));
assert(!p2.owner_before(p1));
assert(p1.owner_before(p3) || p3.owner_before(p1));
assert(p3.owner_before(p1) == p3.owner_before(p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 U> bool owner_before(shared_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
assert(!p1.owner_before(p2));
assert(!p2.owner_before(p1));
assert(p1.owner_before(p3) || p3.owner_before(p1));
assert(p3.owner_before(p1) == p3.owner_before(p2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp index 727b5da1645..8e8059b2056 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 U> bool owner_before(weak_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!p1.owner_before(w2));
assert(!p2.owner_before(w1));
assert(p1.owner_before(w3) || p3.owner_before(w1));
assert(p3.owner_before(w1) == p3.owner_before(w2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 U> bool owner_before(weak_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!p1.owner_before(w2));
assert(!p2.owner_before(w1));
assert(p1.owner_before(w3) || p3.owner_before(w1));
assert(p3.owner_before(w1) == p3.owner_before(w2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp index 3e3da51e446..429e7e9d58a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// bool unique() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(p.unique());
{
std::shared_ptr<int> p2 = p;
assert(!p.unique());
}
assert(p.unique());
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// bool unique() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(p.unique());
{
std::shared_ptr<int> p2 = p;
assert(!p.unique());
}
assert(p.unique());
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp index 5f73c6fdbee..850125f8cf2 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚ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 T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// 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 T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp index 051a4408e9b..359bfa7c48a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp index f2f436b7a36..eb16e033d04 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> struct owner_less;
//
// template <class T>
// struct owner_less<shared_ptr<T> >
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
//
// template <class T>
// struct owner_less<weak_ptr<T> >
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
{
typedef std::owner_less<std::shared_ptr<int> > CS;
CS cs;
assert(!cs(p1, p2));
assert(!cs(p2, p1));
assert(cs(p1 ,p3) || cs(p3, p1));
assert(cs(p3, p1) == cs(p3, p2));
assert(!cs(p1, w2));
assert(!cs(p2, w1));
assert(cs(p1, w3) || cs(p3, w1));
assert(cs(p3, w1) == cs(p3, w2));
}
{
typedef std::owner_less<std::weak_ptr<int> > CS;
CS cs;
assert(!cs(w1, w2));
assert(!cs(w2, w1));
assert(cs(w1, w3) || cs(w3, w1));
assert(cs(w3, w1) == cs(w3, w2));
assert(!cs(w1, p2));
assert(!cs(w2, p1));
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> struct owner_less;
//
// template <class T>
// struct owner_less<shared_ptr<T> >
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
//
// template <class T>
// struct owner_less<weak_ptr<T> >
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
{
typedef std::owner_less<std::shared_ptr<int> > CS;
CS cs;
assert(!cs(p1, p2));
assert(!cs(p2, p1));
assert(cs(p1 ,p3) || cs(p3, p1));
assert(cs(p3, p1) == cs(p3, p2));
assert(!cs(p1, w2));
assert(!cs(p2, w1));
assert(cs(p1, w3) || cs(p3, w1));
assert(cs(p3, w1) == cs(p3, w2));
}
{
typedef std::owner_less<std::weak_ptr<int> > CS;
CS cs;
assert(!cs(w1, w2));
assert(!cs(w2, w1));
assert(cs(w1, w3) || cs(w3, w1));
assert(cs(w3, w1) == cs(w3, w2));
assert(!cs(w1, p2));
assert(!cs(w2, p1));
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp index 02dc7e812b8..87569aadb20 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(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;
int main()
{
{
const std::shared_ptr<A> pA(new A);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp index 0e9859bec34..853d43265ea 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr& operator=(const weak_ptr& 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;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr& operator=(const weak_ptr& 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;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp index 1d062145304..85461b90f7e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const weak_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;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const weak_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;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp index 576ec0c98f9..ef62c139a7e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// weak_ptr();
#include <memory>
#include <cassert>
struct A;
int main()
{
std::weak_ptr<A> p;
assert(p.use_count() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// weak_ptr();
#include <memory>
#include <cassert>
struct A;
int main()
{
std::weak_ptr<A> p;
assert(p.use_count() == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp index 15a5c1cacd5..1efdb03774b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_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::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_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::weak_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
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::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_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::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_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::weak_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
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::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp index 2b49b9706fa..fabf4324536 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr(const weak_ptr& 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()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr(const weak_ptr& 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()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp index 415ee71cc85..8b2db201d6d 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const weak_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::weak_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::weak_ptr<A> pA(std::shared_ptr<A>(new A));
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const weak_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::weak_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::weak_ptr<A> pA(std::shared_ptr<A>(new A));
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp index 9fcb90994c8..50aa527232a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_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> p1(new A);
std::weak_ptr<A> w1(p1);
assert(w1.use_count() == 1);
w1.reset();
assert(w1.use_count() == 0);
assert(p1.use_count() == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_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> p1(new A);
std::weak_ptr<A> w1(p1);
assert(w1.use_count() == 1);
w1.reset();
assert(w1.use_count() == 0);
assert(p1.use_count() == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp index 7ee2277e281..1bd3a3f6c50 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_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()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
w1.swap(w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_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()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
w1.swap(w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp index 59f5388719f..3d93fb93e9e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// bool expired() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
assert(wp.use_count() == 1);
assert(wp.expired() == (wp.use_count() == 0));
sp0.reset();
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// bool expired() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
assert(wp.use_count() == 1);
assert(wp.expired() == (wp.use_count() == 0));
sp0.reset();
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp index fc7e338e6b7..c68792058fc 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// shared_ptr<T> lock() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp = wp.lock();
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();
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// shared_ptr<T> lock() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp = wp.lock();
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();
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp index aa3aad73b4a..18bacf4a43a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> class weak_ptr;
//
// not less than comparable
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
bool b = w1 < w2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> class weak_ptr;
//
// not less than comparable
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
bool b = w1 < w2;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp index 307dba53285..e3ad3807ea3 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const shared_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(p2));
assert(!w2.owner_before(p1));
assert(w1.owner_before(p3) || w3.owner_before(p1));
assert(w3.owner_before(p1) == w3.owner_before(p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const shared_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(p2));
assert(!w2.owner_before(p1));
assert(w1.owner_before(p3) || w3.owner_before(p1));
assert(w3.owner_before(p1) == w3.owner_before(p2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp index a2603af6ff2..6f123821233 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const weak_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(w2));
assert(!w2.owner_before(w1));
assert(w1.owner_before(w3) || w3.owner_before(w1));
assert(w3.owner_before(w1) == w3.owner_before(w2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const weak_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(w2));
assert(!w2.owner_before(w1));
assert(w1.owner_before(w3) || w3.owner_before(w1));
assert(w3.owner_before(w1) == w3.owner_before(w2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp index b02f4eaf7c8..c349f90b638 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b)
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
swap(w1, w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b)
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
swap(w1, w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp index d0de482c2d0..ae75b4fe810 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// class bad_weak_ptr
// : public std::exception
// {
// public:
// bad_weak_ptr();
// };
#include <memory>
#include <type_traits>
#include <cassert>
#include <cstring>
int main()
{
static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), "");
std::bad_weak_ptr e;
std::bad_weak_ptr e2 = e;
e2 = e;
assert(std::strcmp(e.what(), "bad_weak_ptr") == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// class bad_weak_ptr
// : public std::exception
// {
// public:
// bad_weak_ptr();
// };
#include <memory>
#include <type_traits>
#include <cassert>
#include <cstring>
int main()
{
static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), "");
std::bad_weak_ptr e;
std::bad_weak_ptr e2 = e;
e2 = e;
assert(std::strcmp(e.what(), "bad_weak_ptr") == 0);
}
\ No newline at end of file |