forked from OSchip/llvm-project
Rewrite and cleanup unique_ptr tests.
This patch almost entirely rewrites the unique_ptr tests. There are a couple of reasons for this: A) Most of the *.fail.cpp tests were either incorrect or could be better written as a *.pass.cpp test that uses <type_traits> to check if certain operations are valid (Ex. Using static_assert(!std::is_copy_constructible_v<T>) instead of writing a failure test). B) [unique.ptr.runtime] has very poor test coverage. Many of the constructors and assignment operators have to tests at all. The special members that have tests have very few test cases and are typically way out of date. C) The tests for [unique.ptr.single] and [unique.ptr.runtime] are largely duplicates of each other. This means common requirements have two different sets of tests in two different test files. This makes the tests harder to maintain than if there was a single copy. To address (A) this patch changes almost all of the *.fail.cpp tests into .pass.cpp tests using type traits; Allowing the *.fail.cpp tests to be removed. The address (B) and (C) the tests for [unique.ptr.single] and [unique.ptr.runtime] have been combined into a single directory, allowing both specializations to share common tests. Tests specific to the single/runtime specializations are given the suffix "*.single.pass.cpp" or "*.runtime.pass.cpp". Finally the unique.ptr test have been moved into the correct directory according to the standard. Specifically they have been removed from "utilities/memory" into "utilities/smartptr". PS. This patch also adds newly written tests for upcoming unique_ptr changes/fixes. However since these tests don't currently pass they are guarded by the macro TEST_WORKAROUND_UPCOMING_UNIQUE_PTR_CHANGES. This allows other STL's to validate the tests before libc++ implements the changes. The relevant libc++ changes should land in the next week. llvm-svn: 300388
This commit is contained in:
parent
73b76bcf2f
commit
2561885f57
|
@ -1,28 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int> s, s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
|
||||
#else
|
||||
s2 = s; // expected-error {{'operator=' is a private member of 'std::__1::unique_ptr}}
|
||||
#endif
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
// test move assignment. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[]> s1(new A[3]);
|
||||
A* p = s1.get();
|
||||
assert(A::count == 3);
|
||||
std::unique_ptr<A[]> s2(new A[2]);
|
||||
assert(A::count == 5);
|
||||
s2 = std::move(s1);
|
||||
assert(A::count == 3);
|
||||
assert(s2.get() == p);
|
||||
assert(s1.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5));
|
||||
A* p = s1.get();
|
||||
assert(A::count == 4);
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]);
|
||||
assert(A::count == 9);
|
||||
s2 = std::move(s1);
|
||||
assert(s2.get() == p);
|
||||
assert(s1.get() == 0);
|
||||
assert(A::count == 4);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s1.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
CDeleter<A[]> d1(5);
|
||||
std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1);
|
||||
A* p = s1.get();
|
||||
assert(A::count == 6);
|
||||
CDeleter<A[]> d2(6);
|
||||
std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2);
|
||||
assert(A::count == 9);
|
||||
s2 = std::move(s1);
|
||||
assert(A::count == 6);
|
||||
assert(s2.get() == p);
|
||||
assert(s1.get() == 0);
|
||||
assert(d1.state() == 5);
|
||||
assert(d2.state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// Can't copy from const lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<A[]> s(new A[3]);
|
||||
std::unique_ptr<A[]> s2;
|
||||
s2 = s;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// Can't copy from lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A, Deleter> s(new A);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, Deleter> s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// test move ctor. Can't copy from const lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<A, Deleter> s(new A);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, Deleter> s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// Can't assign from lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_ptr<B[], Deleter<B> > s(new B);
|
||||
A* p = s.get();
|
||||
boost::unique_ptr<A[], Deleter<A> > s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
Deleter<B> db(5);
|
||||
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
|
||||
A* p = s.get();
|
||||
Deleter<A> da(6);
|
||||
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// Can't assign from const lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const boost::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
boost::unique_ptr<A[]> s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from const lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const boost::unique_ptr<B[], Deleter<B> > s(new B);
|
||||
A* p = s.get();
|
||||
boost::unique_ptr<A[], Deleter<A> > s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from const lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
Deleter<B> db(5);
|
||||
const boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
|
||||
A* p = s.get();
|
||||
Deleter<A> da(6);
|
||||
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
boost::unique_ptr<A[]> s2(new A);
|
||||
assert(A::count == 2);
|
||||
s2 = boost::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
boost::unique_ptr<B[], Deleter<B> > s(new B);
|
||||
A* p = s.get();
|
||||
boost::unique_ptr<A[], Deleter<A> > s2(new A);
|
||||
assert(A::count == 2);
|
||||
s2 = (boost::move(s));
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// test converting move assignment with reference deleters
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
Deleter<B> db(5);
|
||||
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
|
||||
A* p = s.get();
|
||||
Deleter<A> da(6);
|
||||
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
|
||||
s2 = boost::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test assignment from null
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A> s2(new A);
|
||||
assert(A::count == 1);
|
||||
s2 = 0;
|
||||
assert(A::count == 0);
|
||||
assert(s2.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// The deleter is not called if get() == 0
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(0) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(void*) {++state_;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Deleter d;
|
||||
assert(d.state() == 0);
|
||||
{
|
||||
std::unique_ptr<int[], Deleter&> p(nullptr, d);
|
||||
assert(p.get() == 0);
|
||||
assert(&p.get_deleter() == &d);
|
||||
}
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
{
|
||||
// The standard only requires the constructor accept nullptr, but libc++
|
||||
// also supports the literal 0.
|
||||
std::unique_ptr<int[], Deleter&> p(0, d);
|
||||
assert(p.get() == 0);
|
||||
assert(&p.get_deleter() == &d);
|
||||
}
|
||||
#endif
|
||||
assert(d.state() == 0);
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test assignment from null
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[]> s2(new A[3]);
|
||||
assert(A::count == 3);
|
||||
s2 = nullptr;
|
||||
assert(A::count == 0);
|
||||
assert(s2.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr<T[]>::pointer type
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
struct Deleter
|
||||
{
|
||||
struct pointer {};
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::unique_ptr<int[]> P;
|
||||
static_assert((std::is_same<P::pointer, int*>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<int[], Deleter> P;
|
||||
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
// default unique_ptr ctor should only require default Deleter ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "test_macros.h"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11
|
||||
_LIBCPP_SAFE_STATIC std::unique_ptr<int[]> global_static_unique_ptr;
|
||||
#endif
|
||||
|
||||
class Deleter {
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const { return state_; }
|
||||
|
||||
void operator()(void*) {}
|
||||
};
|
||||
|
||||
int main() {
|
||||
{
|
||||
std::unique_ptr<int[]> p;
|
||||
assert(p.get() == 0);
|
||||
}
|
||||
{
|
||||
std::unique_ptr<int[], Deleter> p;
|
||||
assert(p.get() == 0);
|
||||
assert(p.get_deleter().state() == 5);
|
||||
}
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
// default unique_ptr ctor should require default Deleter ctor
|
||||
|
||||
#include <memory>
|
||||
#include "test_macros.h"
|
||||
|
||||
class Deleter {
|
||||
Deleter() {}
|
||||
|
||||
public:
|
||||
Deleter(Deleter&) {}
|
||||
Deleter& operator=(Deleter&) { return *this; }
|
||||
|
||||
void operator()(void*) const {}
|
||||
};
|
||||
|
||||
int main() {
|
||||
#if TEST_STD_VER >= 11
|
||||
// expected-error@memory:* {{call to implicitly-deleted default constructor}}
|
||||
// expected-note@memory:* {{implicitly deleted because base class 'Deleter' has an inaccessible default constructor}}
|
||||
#else
|
||||
// expected-error@memory:* {{base class 'Deleter' has private default constructor}}
|
||||
#endif
|
||||
std::unique_ptr<int[], Deleter> p; // expected-note {{requested here}}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
// default unique_ptr ctor should require non-reference Deleter ctor
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Deleter
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(void*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[], Deleter&> p;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
// default unique_ptr ctor should require non-pointer Deleter
|
||||
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[], void (*)(void*)> p;
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test default unique_ptr<T[]> ctor
|
||||
|
||||
// default unique_ptr<T[]> ctor shouldn't require complete type
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A;
|
||||
|
||||
class Deleter {
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const { return state_; }
|
||||
|
||||
void operator()(A* p);
|
||||
};
|
||||
|
||||
void check(int i);
|
||||
|
||||
template <class D = std::default_delete<A> >
|
||||
struct B {
|
||||
std::unique_ptr<A[], D> a_;
|
||||
B();
|
||||
~B();
|
||||
|
||||
A* get() const { return a_.get(); }
|
||||
D& get_deleter() { return a_.get_deleter(); }
|
||||
};
|
||||
|
||||
int main() {
|
||||
{
|
||||
B<> s;
|
||||
assert(s.get() == 0);
|
||||
}
|
||||
check(0);
|
||||
{
|
||||
B<Deleter> s;
|
||||
assert(s.get() == 0);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
}
|
||||
check(0);
|
||||
}
|
||||
|
||||
struct A {
|
||||
static int count;
|
||||
A() { ++count; }
|
||||
A(const A&) { ++count; }
|
||||
~A() { --count; }
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
void Deleter::operator()(A* p) { delete p; }
|
||||
|
||||
void check(int i) { assert(A::count == i); }
|
||||
|
||||
template <class D>
|
||||
B<D>::B() {}
|
||||
|
||||
template <class D>
|
||||
B<D>::~B() {}
|
|
@ -1,42 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test move ctor. Can't copy from lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[]> s(new A[3]);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
// test move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[]> s(new A[3]);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 3);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5));
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 3);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
NCDeleter<A[]> d;
|
||||
std::unique_ptr<A[], NCDeleter<A[]>&> s(new A[3], d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], NCDeleter<A[]>&> s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 3);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
// test move ctor. Can't copy from const lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<A[]> s(new A[3]);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
// test move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
|
||||
std::unique_ptr<A[]>
|
||||
source1()
|
||||
{
|
||||
return std::unique_ptr<A[]>(new A[3]);
|
||||
}
|
||||
|
||||
void sink1(std::unique_ptr<A[]>)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<A[], Deleter<A[]> >
|
||||
source2()
|
||||
{
|
||||
return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
|
||||
}
|
||||
|
||||
void sink2(std::unique_ptr<A[], Deleter<A[]> >)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<A[], NCDeleter<A[]>&>
|
||||
source3()
|
||||
{
|
||||
static NCDeleter<A[]> d;
|
||||
return std::unique_ptr<A[], NCDeleter<A[]>&>(new A[3], d);
|
||||
}
|
||||
|
||||
void sink3(std::unique_ptr<A[], NCDeleter<A[]>&>)
|
||||
{
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
sink1(source1());
|
||||
sink2(source2());
|
||||
sink3(source3());
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
// test move ctor. Can't copy from lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[], Deleter> s(new A[3]);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
// test move ctor. Can't copy from const lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<A[], Deleter> s(new A[3]);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[], Deleter<B[]> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], CDeleter<A>&> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// implicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Implicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[], Deleter<B[]> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], CDeleter<A>&> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// implicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Implicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2(std::move(s));
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[], Deleter<B[]> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s));
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s));
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// implicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[]> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[]> s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Implicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B[], Deleter<B[]> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// unique_ptr(nullptr_t);
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// default unique_ptr ctor should only require default Deleter ctor
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(void*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int[]> p(nullptr);
|
||||
assert(p.get() == 0);
|
||||
}
|
||||
{
|
||||
std::unique_ptr<int[], Deleter> p(nullptr);
|
||||
assert(p.get() == 0);
|
||||
assert(p.get_deleter().state() == 5);
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr<T[]>(pointer) ctor
|
||||
|
||||
// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Deleter
|
||||
{
|
||||
|
||||
Deleter() {}
|
||||
|
||||
public:
|
||||
|
||||
Deleter(Deleter&) {}
|
||||
Deleter& operator=(Deleter&) {}
|
||||
|
||||
void operator()(void*) const {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[], Deleter> p(new int);
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer) ctor
|
||||
|
||||
// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p = new A[3];
|
||||
assert(A::count == 3);
|
||||
std::unique_ptr<A[]> s(p);
|
||||
assert(s.get() == p);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
A* p = new A[3];
|
||||
assert(A::count == 3);
|
||||
std::unique_ptr<A[], Deleter> s(p);
|
||||
assert(s.get() == p);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr<T[]>(pointer) ctor
|
||||
|
||||
#include <memory>
|
||||
|
||||
// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor
|
||||
class Deleter
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(void*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[], Deleter&> p(new int);
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr<T[]>(pointer) ctor
|
||||
|
||||
// unique_ptr<T[]>(pointer) ctor shouldn't require complete type
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p);
|
||||
};
|
||||
|
||||
void check(int i);
|
||||
|
||||
template <class D = std::default_delete<A[]> >
|
||||
struct B
|
||||
{
|
||||
std::unique_ptr<A[], D> a_;
|
||||
explicit B(A*);
|
||||
~B();
|
||||
|
||||
A* get() const {return a_.get();}
|
||||
D& get_deleter() {return a_.get_deleter();}
|
||||
};
|
||||
|
||||
A* get();
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p = get();
|
||||
check(3);
|
||||
B<> s(p);
|
||||
assert(s.get() == p);
|
||||
}
|
||||
check(0);
|
||||
{
|
||||
A* p = get();
|
||||
check(3);
|
||||
B<Deleter> s(p);
|
||||
assert(s.get() == p);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
}
|
||||
check(0);
|
||||
}
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
A* get() {return new A[3];}
|
||||
|
||||
void Deleter::operator()(A* p) {delete [] p;}
|
||||
|
||||
void check(int i)
|
||||
{
|
||||
assert(A::count == i);
|
||||
}
|
||||
|
||||
template <class D>
|
||||
B<D>::B(A* a) : a_(a) {}
|
||||
|
||||
template <class D>
|
||||
B<D>::~B() {}
|
|
@ -1,23 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr<T[]>(pointer) ctor
|
||||
|
||||
// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter
|
||||
|
||||
#include <memory>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[], void (*)(void*)> p(new int);
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer) ctor
|
||||
|
||||
// unique_ptr(pointer) ctor should not work with derived pointers
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(Deleter&);
|
||||
Deleter& operator=(Deleter&);
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
B* p = new B[3];
|
||||
std::unique_ptr<A[]> s(p);
|
||||
}
|
||||
{
|
||||
B* p = new B[3];
|
||||
std::unique_ptr<A[], Deleter> s(p);
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer, deleter) ctor
|
||||
|
||||
// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p = new A[3];
|
||||
assert(A::count == 3);
|
||||
std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>());
|
||||
assert(s.get() == p);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
|
||||
{ // LWG#2520 says that nullptr is a valid input as well as null
|
||||
#ifdef _LIBCPP_VERSION
|
||||
std::unique_ptr<A[], Deleter<A[]> > s1(NULL, Deleter<A[]>());
|
||||
#endif
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2(nullptr, Deleter<A[]>());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer, deleter) ctor
|
||||
|
||||
// unique_ptr(pointer, d) requires CopyConstructible deleter
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p = new A[3];
|
||||
assert(A::count == 3);
|
||||
Deleter d;
|
||||
std::unique_ptr<A[], Deleter> s(p, d);
|
||||
assert(s.get() == p);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
d.set_state(6);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
Deleter d;
|
||||
std::unique_ptr<A[], Deleter> s(nullptr, d);
|
||||
assert(s.get() == nullptr);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer, deleter) ctor
|
||||
|
||||
// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(const Deleter&);
|
||||
Deleter& operator=(const Deleter&);
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p = new A[3];
|
||||
assert(A::count == 3);
|
||||
Deleter d;
|
||||
std::unique_ptr<A[], Deleter&> s(p, d);
|
||||
assert(s.get() == p);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
d.set_state(6);
|
||||
assert(s.get_deleter().state() == 6);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
Deleter d;
|
||||
std::unique_ptr<A[], Deleter&> s(nullptr, d);
|
||||
assert(s.get() == nullptr);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// XFAIL: c++98, c++03
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer, deleter) ctor
|
||||
|
||||
// unique_ptr<T, const D&>(pointer, D()) should not compile
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Deleter
|
||||
{
|
||||
public:
|
||||
Deleter() {}
|
||||
void operator()(int* p) const {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
int* p = nullptr;
|
||||
std::unique_ptr<int[], const Deleter&> s(p, Deleter()); // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer, deleter) ctor
|
||||
|
||||
// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
Deleter(const Deleter&);
|
||||
Deleter& operator=(const Deleter&);
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(A* p) const {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p = new A[3];
|
||||
assert(A::count == 3);
|
||||
Deleter d;
|
||||
std::unique_ptr<A[], const Deleter&> s(p, d);
|
||||
assert(s.get() == p);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
Deleter d;
|
||||
std::unique_ptr<A[], const Deleter&> s(nullptr, d);
|
||||
assert(s.get() == nullptr);
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer, deleter) ctor
|
||||
|
||||
// unique_ptr(pointer, deleter) should not work with derived pointers
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete [] p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
B* p = new B[3];
|
||||
std::unique_ptr<A[], Deleter> s(p, Deleter());
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test reset
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[]> p(new A[3]);
|
||||
assert(A::count == 3);
|
||||
A* i = p.get();
|
||||
assert(i != nullptr);
|
||||
p.reset();
|
||||
assert(A::count == 0);
|
||||
assert(p.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::unique_ptr<A[]> p(new A[4]);
|
||||
assert(A::count == 4);
|
||||
A* i = p.get();
|
||||
assert(i != nullptr);
|
||||
p.reset(new A[5]);
|
||||
assert(A::count == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test reset
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A[]> p(new A);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 0);
|
||||
A* i = p.get();
|
||||
p.reset(new B);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
{
|
||||
std::unique_ptr<A[]> p(new B);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
A* i = p.get();
|
||||
p.reset(new B);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test swap
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
int state_;
|
||||
static int count;
|
||||
A() : state_(0) {++count;}
|
||||
explicit A(int i) : state_(i) {++count;}
|
||||
A(const A& a) : state_(a.state_) {++count;}
|
||||
A& operator=(const A& a) {state_ = a.state_; return *this;}
|
||||
~A() {--count;}
|
||||
|
||||
friend bool operator==(const A& x, const A& y)
|
||||
{return x.state_ == y.state_;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
A* p1 = new A[3];
|
||||
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
|
||||
A* p2 = new A[3];
|
||||
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
|
||||
assert(s1.get() == p1);
|
||||
assert(s1.get_deleter().state() == 1);
|
||||
assert(s2.get() == p2);
|
||||
assert(s2.get_deleter().state() == 2);
|
||||
s1.swap(s2);
|
||||
assert(s1.get() == p2);
|
||||
assert(s1.get_deleter().state() == 2);
|
||||
assert(s2.get() == p1);
|
||||
assert(s2.get_deleter().state() == 1);
|
||||
assert(A::count == 6);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test op*()
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int[]> p(new int(3));
|
||||
assert(*p == 3);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test get
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
int* p = new int[3];
|
||||
std::unique_ptr<int[]> s(p);
|
||||
assert(s.get() == p);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test get_deleter()
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "test_macros.h"
|
||||
|
||||
struct Deleter {
|
||||
Deleter() {}
|
||||
|
||||
void operator()(void*) const {}
|
||||
|
||||
int test() { return 5; }
|
||||
int test() const { return 6; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
{
|
||||
std::unique_ptr<int[], Deleter> p;
|
||||
assert(p.get_deleter().test() == 5);
|
||||
}
|
||||
{
|
||||
const std::unique_ptr<int[], Deleter> p;
|
||||
assert(p.get_deleter().test() == 6);
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<int[], const Deleter&> UPtr;
|
||||
const Deleter d;
|
||||
UPtr p(nullptr, d);
|
||||
const UPtr& cp = p;
|
||||
ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&);
|
||||
ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&);
|
||||
assert(p.get_deleter().test() == 6);
|
||||
assert(cp.get_deleter().test() == 6);
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<int[], Deleter&> UPtr;
|
||||
Deleter d;
|
||||
UPtr p(nullptr, d);
|
||||
const UPtr& cp = p;
|
||||
ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&);
|
||||
ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&);
|
||||
assert(p.get_deleter().test() == 5);
|
||||
assert(cp.get_deleter().test() == 5);
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// test op[](size_t)
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
class A
|
||||
{
|
||||
int state_;
|
||||
static int next_;
|
||||
public:
|
||||
A() : state_(++next_) {}
|
||||
int get() const {return state_;}
|
||||
|
||||
friend bool operator==(const A& x, int y)
|
||||
{return x.state_ == y;}
|
||||
|
||||
A& operator=(int i) {state_ = i; return *this;}
|
||||
};
|
||||
|
||||
int A::next_ = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<A[]> p(new A[3]);
|
||||
assert(p[0] == 1);
|
||||
assert(p[1] == 2);
|
||||
assert(p[2] == 3);
|
||||
p[0] = 3;
|
||||
p[1] = 2;
|
||||
p[2] = 1;
|
||||
assert(p[0] == 3);
|
||||
assert(p[1] == 2);
|
||||
assert(p[2] == 1);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr::pointer type
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct Deleter
|
||||
{
|
||||
struct pointer {};
|
||||
};
|
||||
|
||||
struct D2 {
|
||||
private:
|
||||
typedef void pointer;
|
||||
};
|
||||
|
||||
struct D3 {
|
||||
static long pointer;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::unique_ptr<int> P;
|
||||
static_assert((std::is_same<P::pointer, int*>::value), "");
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<int, Deleter> P;
|
||||
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
|
||||
}
|
||||
#if TEST_STD_VER >= 11
|
||||
{
|
||||
typedef std::unique_ptr<int, D2> P;
|
||||
static_assert(std::is_same<P::pointer, int*>::value, "");
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<int, D3> P;
|
||||
static_assert(std::is_same<P::pointer, int*>::value, "");
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
// Can't copy from lvalue
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int> s, s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
|
||||
#else
|
||||
s2 = s; // expected-error {{'operator=' is a private member}}
|
||||
#endif
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
// test move assignment. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A> s1(new A);
|
||||
A* p = s1.get();
|
||||
std::unique_ptr<A> s2(new A);
|
||||
assert(A::count == 2);
|
||||
s2 = std::move(s1);
|
||||
assert(A::count == 1);
|
||||
assert(s2.get() == p);
|
||||
assert(s1.get() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5));
|
||||
A* p = s1.get();
|
||||
std::unique_ptr<A, Deleter<A> > s2(new A);
|
||||
assert(A::count == 2);
|
||||
s2 = std::move(s1);
|
||||
assert(s2.get() == p);
|
||||
assert(s1.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s1.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
CDeleter<A> d1(5);
|
||||
std::unique_ptr<A, CDeleter<A>&> s1(new A, d1);
|
||||
A* p = s1.get();
|
||||
CDeleter<A> d2(6);
|
||||
std::unique_ptr<A, CDeleter<A>&> s2(new A, d2);
|
||||
s2 = std::move(s1);
|
||||
assert(s2.get() == p);
|
||||
assert(s1.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(d1.state() == 5);
|
||||
assert(d2.state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
// Can't copy from const lvalue
|
||||
|
||||
int main()
|
||||
{
|
||||
const std::unique_ptr<int> s(new int);
|
||||
std::unique_ptr<int> s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
|
||||
#else
|
||||
// NOTE: The error says "constructor" because the assignment operator takes
|
||||
// 's' by value and attempts to copy construct it.
|
||||
s2 = s; // expected-error {{no matching constructor for initialization}}
|
||||
#endif
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct Deleter {
|
||||
void operator()(int* p) {delete p;}
|
||||
};
|
||||
|
||||
// Can't copy from lvalue
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int, Deleter> s, s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
|
||||
#else
|
||||
s2 = s; // expected-error {{'operator=' is a private member}}
|
||||
#endif
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct Deleter {
|
||||
void operator()(int* p) {delete p;}
|
||||
};
|
||||
|
||||
// Can't copy from a const lvalue
|
||||
int main()
|
||||
{
|
||||
const std::unique_ptr<int, Deleter> s(new int);
|
||||
std::unique_ptr<int, Deleter> s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}}
|
||||
#else
|
||||
// NOTE: The error says "constructor" because the assignment operator takes
|
||||
// 's' by value and attempts to copy construct it.
|
||||
s2 = s; // expected-error {{no matching constructor for initialization}}
|
||||
#endif
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
|
||||
template <class APtr, class BPtr>
|
||||
void testAssign(APtr& aptr, BPtr& bptr) {
|
||||
A* p = bptr.get();
|
||||
assert(A::count == 2);
|
||||
aptr = std::move(bptr);
|
||||
assert(aptr.get() == p);
|
||||
assert(bptr.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
|
||||
template <class LHS, class RHS>
|
||||
void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) {
|
||||
assert(lhs.get_deleter().state() == LHSState);
|
||||
assert(rhs.get_deleter().state() == RHSState);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B> bptr(new B);
|
||||
std::unique_ptr<A> aptr(new A);
|
||||
testAssign(aptr, bptr);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
{
|
||||
Deleter<B> del(42);
|
||||
std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del));
|
||||
std::unique_ptr<A, Deleter<A> > aptr(new A);
|
||||
testAssign(aptr, bptr);
|
||||
checkDeleter(aptr, bptr, 42, 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
{
|
||||
CDeleter<A> adel(6);
|
||||
CDeleter<B> bdel(42);
|
||||
std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel);
|
||||
std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel);
|
||||
testAssign(aptr, bptr);
|
||||
checkDeleter(aptr, bptr, 42, 42);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
A() {}
|
||||
virtual ~A() {}
|
||||
};
|
||||
|
||||
struct B : public A
|
||||
{
|
||||
};
|
||||
|
||||
// Can't assign from lvalue
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<B> s;
|
||||
std::unique_ptr<A> s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{no viable overloaded '='}}
|
||||
#else
|
||||
// NOTE: The move-semantic emulation creates an ambiguous overload set
|
||||
// so that assignment from an lvalue does not compile
|
||||
s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}}
|
||||
#endif
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
A() {}
|
||||
virtual ~A() {}
|
||||
};
|
||||
|
||||
struct B : public A
|
||||
{
|
||||
};
|
||||
|
||||
// Can't assign from lvalue
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<B, Deleter<B> > s;
|
||||
std::unique_ptr<A, Deleter<A> > s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{no viable overloaded '='}}
|
||||
#else
|
||||
// NOTE: The move-semantic emulation creates an ambiguous overload set
|
||||
// so that assignment from an lvalue does not compile
|
||||
s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}}
|
||||
#endif
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from lvalue
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
A() {}
|
||||
virtual ~A() {}
|
||||
};
|
||||
|
||||
struct B : public A
|
||||
{
|
||||
};
|
||||
|
||||
// Can't assign from lvalue
|
||||
int main()
|
||||
{
|
||||
Deleter<B> db;
|
||||
std::unique_ptr<B, Deleter<B>& > s(new B, db);
|
||||
Deleter<A> da;
|
||||
std::unique_ptr<A, Deleter<A> &> s2(new A, da);
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{no viable overloaded '='}}
|
||||
#else
|
||||
// NOTE: The move-semantic emulation creates an ambiguous overload set
|
||||
// so that assignment from an lvalue does not compile
|
||||
s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}}
|
||||
#endif
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
A() {}
|
||||
virtual ~A() {}
|
||||
};
|
||||
|
||||
struct B : public A
|
||||
{
|
||||
};
|
||||
|
||||
// Can't assign from lvalue
|
||||
int main()
|
||||
{
|
||||
const std::unique_ptr<B> s(new B);
|
||||
std::unique_ptr<A> s2;
|
||||
#if TEST_STD_VER >= 11
|
||||
s2 = s; // expected-error {{no viable overloaded '='}}
|
||||
#else
|
||||
// NOTE: The error says "constructor" because the assignment operator takes
|
||||
// 's' by value and attempts to copy construct it.
|
||||
s2 = s; // expected-error {{no matching constructor for initialization}}
|
||||
#endif
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from const lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<B, Deleter<B> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, Deleter<A> > s2;
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Can't assign from const lvalue
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
Deleter<B> db(5);
|
||||
const std::unique_ptr<B, Deleter<B>&> s(new B, db);
|
||||
A* p = s.get();
|
||||
Deleter<A> da(6);
|
||||
std::unique_ptr<A, Deleter<A>&> s2(new A, da);
|
||||
s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move assignment
|
||||
|
||||
// Do not convert from an array unique_ptr
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
struct A
|
||||
{
|
||||
};
|
||||
|
||||
struct Deleter
|
||||
{
|
||||
void operator()(void*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<A[], Deleter> s;
|
||||
std::unique_ptr<A, Deleter> s2;
|
||||
s2 = std::move(s); // expected-error {{no viable overloaded '='}}
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer) ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// template <class U> explicit unique_ptr(auto_ptr<U>&);
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
// : public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
B* p = new B;
|
||||
std::auto_ptr<B> ap(p);
|
||||
std::unique_ptr<A> up(ap);
|
||||
assert(up.get() == p);
|
||||
assert(ap.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
{
|
||||
B* p = new B;
|
||||
std::auto_ptr<B> ap(p);
|
||||
std::unique_ptr<A> up;
|
||||
up = ap;
|
||||
assert(up.get() == p);
|
||||
assert(ap.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr(pointer) ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// template <class U> explicit unique_ptr(auto_ptr<U>&);
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
struct Deleter
|
||||
{
|
||||
template <class T>
|
||||
void operator()(T*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
B* p = new B;
|
||||
std::auto_ptr<B> ap(p);
|
||||
std::unique_ptr<A, Deleter> up(ap);
|
||||
assert(up.get() == p);
|
||||
assert(ap.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
//=============================================================================
|
||||
// TESTING std::unique_ptr::unique_ptr()
|
||||
//
|
||||
// Concerns:
|
||||
// 1 The default constructor works for any default constructible deleter types.
|
||||
// 2 The stored type 'T' is allowed to be incomplete.
|
||||
//
|
||||
// Plan
|
||||
// 1 Default construct unique_ptr's with various deleter types (C-1)
|
||||
// 2 Default construct a unique_ptr with an incomplete element_type and
|
||||
// various deleter types (C-1,2)
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
#include "test_macros.h"
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11
|
||||
_LIBCPP_SAFE_STATIC std::unique_ptr<int> global_static_unique_ptr;
|
||||
#endif
|
||||
|
||||
struct IncompleteT;
|
||||
|
||||
void checkNumIncompleteTypeAlive(int i);
|
||||
|
||||
template <class Del = std::default_delete<IncompleteT> >
|
||||
struct StoresIncomplete {
|
||||
std::unique_ptr<IncompleteT, Del> m_ptr;
|
||||
StoresIncomplete() {}
|
||||
~StoresIncomplete();
|
||||
|
||||
IncompleteT* get() const { return m_ptr.get(); }
|
||||
Del& get_deleter() { return m_ptr.get_deleter(); }
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<int> p;
|
||||
assert(p.get() == 0);
|
||||
}
|
||||
{
|
||||
std::unique_ptr<int, NCDeleter<int> > p;
|
||||
assert(p.get() == 0);
|
||||
assert(p.get_deleter().state() == 0);
|
||||
p.get_deleter().set_state(5);
|
||||
assert(p.get_deleter().state() == 5);
|
||||
}
|
||||
{
|
||||
StoresIncomplete<> s;
|
||||
assert(s.get() == 0);
|
||||
checkNumIncompleteTypeAlive(0);
|
||||
}
|
||||
checkNumIncompleteTypeAlive(0);
|
||||
{
|
||||
StoresIncomplete< Deleter<IncompleteT> > s;
|
||||
assert(s.get() == 0);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
checkNumIncompleteTypeAlive(0);
|
||||
}
|
||||
checkNumIncompleteTypeAlive(0);
|
||||
}
|
||||
|
||||
struct IncompleteT {
|
||||
static int count;
|
||||
IncompleteT() { ++count; }
|
||||
~IncompleteT() {--count; }
|
||||
};
|
||||
|
||||
int IncompleteT::count = 0;
|
||||
|
||||
void checkNumIncompleteTypeAlive(int i) {
|
||||
assert(IncompleteT::count == i);
|
||||
}
|
||||
|
||||
template <class Del>
|
||||
StoresIncomplete<Del>::~StoresIncomplete() { }
|
|
@ -1,35 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
#include <memory>
|
||||
|
||||
// default unique_ptr ctor should require default Deleter ctor
|
||||
class Deleter
|
||||
{
|
||||
|
||||
Deleter() {}
|
||||
|
||||
public:
|
||||
|
||||
Deleter(Deleter&) {}
|
||||
Deleter& operator=(Deleter&) {}
|
||||
|
||||
void operator()(void*) const {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int, Deleter> p;
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
#include <memory>
|
||||
|
||||
// default unique_ptr ctor should require non-reference Deleter ctor
|
||||
class Deleter
|
||||
{
|
||||
public:
|
||||
|
||||
void operator()(void*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int, Deleter&> p;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr default ctor
|
||||
|
||||
#include <memory>
|
||||
|
||||
// default unique_ptr ctor should require non-pointer Deleter
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<int, void (*)(void*)> p;
|
||||
}
|
|
@ -1,140 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
//=============================================================================
|
||||
// TESTING unique_ptr(unique_ptr&&)
|
||||
//
|
||||
// Concerns
|
||||
// 1 The moved from pointer is empty and the new pointer stores the old value.
|
||||
// 2 The only requirement on the deleter is that it is MoveConstructible
|
||||
// or a reference.
|
||||
// 3 The constructor works for explicitly moved values (ie std::move(x))
|
||||
// 4 The constructor works for true temporaries (ie a return value)
|
||||
//
|
||||
// Plan
|
||||
// 1 Explicitly construct unique_ptr<T, D> for various deleter types 'D'.
|
||||
// check that the value and deleter have been properly moved. (C-1,2,3)
|
||||
//
|
||||
// 2 Use the expression 'sink(source())' to move construct a unique_ptr<T, D>
|
||||
// from a temporary. 'source' should return the unique_ptr by value and
|
||||
// 'sink' should accept the unique_ptr by value. (C-1,2,4)
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
template <class Expect>
|
||||
void sinkFunction(Expect)
|
||||
{
|
||||
}
|
||||
|
||||
typedef std::unique_ptr<A> APtrSource1;
|
||||
typedef std::unique_ptr<A, Deleter<A> > APtrSource2;
|
||||
typedef std::unique_ptr<A, NCDeleter<A>& > APtrSource3;
|
||||
|
||||
APtrSource1 source1() {
|
||||
return APtrSource1 (new A);
|
||||
}
|
||||
|
||||
void sink1(APtrSource1 p) {
|
||||
assert(p.get() != nullptr);
|
||||
}
|
||||
|
||||
APtrSource2 source2() {
|
||||
return APtrSource2(new A, Deleter<A>(5));
|
||||
}
|
||||
|
||||
void sink2(APtrSource2 p) {
|
||||
assert(p.get() != nullptr);
|
||||
assert(p.get_deleter().state() == 5);
|
||||
}
|
||||
|
||||
APtrSource3 source3() {
|
||||
static NCDeleter<A> d(5);
|
||||
return APtrSource3(new A, d);
|
||||
}
|
||||
|
||||
void sink3(APtrSource3 p) {
|
||||
assert(p.get() != nullptr);
|
||||
assert(p.get_deleter().state() == 5);
|
||||
assert(&p.get_deleter() == &source3().get_deleter());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::unique_ptr<A> APtr;
|
||||
APtr s(new A);
|
||||
A* p = s.get();
|
||||
APtr s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
typedef Deleter<A> MoveDel;
|
||||
typedef std::unique_ptr<A, MoveDel> APtr;
|
||||
MoveDel d(5);
|
||||
APtr s(new A, std::move(d));
|
||||
assert(d.state() == 0);
|
||||
assert(s.get_deleter().state() == 5);
|
||||
A* p = s.get();
|
||||
APtr s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
typedef NCDeleter<A> NonCopyDel;
|
||||
typedef std::unique_ptr<A, NonCopyDel&> APtr;
|
||||
|
||||
NonCopyDel d;
|
||||
APtr s(new A, d);
|
||||
A* p = s.get();
|
||||
APtr s2 = std::move(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
{
|
||||
sink1(source1());
|
||||
assert(A::count == 0);
|
||||
sink2(source2());
|
||||
assert(A::count == 0);
|
||||
sink3(source3());
|
||||
assert(A::count == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test move ctor. Can't copy from lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A> s(new A);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test move ctor. Can't copy from const lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<A> s(new A);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test move ctor. Can't copy from lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<A, Deleter> s(new A);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, Deleter> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
// test move ctor. Can't copy from const lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
class Deleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
public:
|
||||
|
||||
Deleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
|
||||
void operator()(A* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<A, Deleter> s(new A);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, Deleter> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// NOTE: unique_ptr does not provide converting constructors in c++03
|
||||
// XFAIL: c++98, c++03
|
||||
|
||||
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
|
||||
template <class LHS, class RHS>
|
||||
void checkReferenceDeleter(LHS& lhs, RHS& rhs) {
|
||||
typedef typename LHS::deleter_type NewDel;
|
||||
static_assert(std::is_reference<NewDel>::value, "");
|
||||
rhs.get_deleter().set_state(42);
|
||||
assert(rhs.get_deleter().state() == 42);
|
||||
assert(lhs.get_deleter().state() == 42);
|
||||
lhs.get_deleter().set_state(99);
|
||||
assert(lhs.get_deleter().state() == 99);
|
||||
assert(rhs.get_deleter().state() == 99);
|
||||
}
|
||||
|
||||
template <class LHS, class RHS>
|
||||
void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) {
|
||||
assert(lhs.get_deleter().state() == LHSVal);
|
||||
assert(rhs.get_deleter().state() == RHSVal);
|
||||
}
|
||||
|
||||
template <class LHS, class RHS>
|
||||
void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) {
|
||||
assert(lhs.get() == RHSVal);
|
||||
assert(rhs.get() == nullptr);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
|
||||
void checkNoneAlive() {
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
typedef std::unique_ptr<A> APtr;
|
||||
typedef std::unique_ptr<B> BPtr;
|
||||
{ // explicit
|
||||
BPtr b(new B);
|
||||
A* p = b.get();
|
||||
APtr a(std::move(b));
|
||||
checkCtor(a, b, p);
|
||||
}
|
||||
checkNoneAlive();
|
||||
{ // implicit
|
||||
BPtr b(new B);
|
||||
A* p = b.get();
|
||||
APtr a = std::move(b);
|
||||
checkCtor(a, b, p);
|
||||
}
|
||||
checkNoneAlive();
|
||||
}
|
||||
{ // test with moveable deleters
|
||||
typedef std::unique_ptr<A, Deleter<A> > APtr;
|
||||
typedef std::unique_ptr<B, Deleter<B> > BPtr;
|
||||
{
|
||||
Deleter<B> del(5);
|
||||
BPtr b(new B, std::move(del));
|
||||
A* p = b.get();
|
||||
APtr a(std::move(b));
|
||||
checkCtor(a, b, p);
|
||||
checkDeleter(a, b, 5, 0);
|
||||
}
|
||||
checkNoneAlive();
|
||||
{
|
||||
Deleter<B> del(5);
|
||||
BPtr b(new B, std::move(del));
|
||||
A* p = b.get();
|
||||
APtr a = std::move(b);
|
||||
checkCtor(a, b, p);
|
||||
checkDeleter(a, b, 5, 0);
|
||||
}
|
||||
checkNoneAlive();
|
||||
|
||||
}
|
||||
{ // test with reference deleters
|
||||
typedef std::unique_ptr<A, NCDeleter<A>& > APtr;
|
||||
typedef std::unique_ptr<B, NCDeleter<A>& > BPtr;
|
||||
NCDeleter<A> del(5);
|
||||
{
|
||||
BPtr b(new B, del);
|
||||
A* p = b.get();
|
||||
APtr a(std::move(b));
|
||||
checkCtor(a, b, p);
|
||||
checkReferenceDeleter(a, b);
|
||||
}
|
||||
checkNoneAlive();
|
||||
{
|
||||
BPtr b(new B, del);
|
||||
A* p = b.get();
|
||||
APtr a = std::move(b);
|
||||
checkCtor(a, b, p);
|
||||
checkReferenceDeleter(a, b);
|
||||
}
|
||||
checkNoneAlive();
|
||||
}
|
||||
{
|
||||
typedef std::unique_ptr<A, CDeleter<A> > APtr;
|
||||
typedef std::unique_ptr<B, CDeleter<B>& > BPtr;
|
||||
CDeleter<B> del(5);
|
||||
{
|
||||
BPtr b(new B, del);
|
||||
A* p = b.get();
|
||||
APtr a(std::move(b));
|
||||
checkCtor(a, b, p);
|
||||
checkDeleter(a, b, 5, 5);
|
||||
}
|
||||
checkNoneAlive();
|
||||
{
|
||||
BPtr b(new B, del);
|
||||
A* p = b.get();
|
||||
APtr a = std::move(b);
|
||||
checkCtor(a, b, p);
|
||||
checkDeleter(a, b, 5, 5);
|
||||
}
|
||||
checkNoneAlive();
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// Can't construct from lvalue
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B, Deleter<B> > s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, Deleter<A> > s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
assert(s2.get_deleter().state() == 5);
|
||||
assert(s.get_deleter().state() == 0);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, CDeleter<A>&> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// implicit version
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
std::unique_ptr<B> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "deleter_types.h"
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Implicit version
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::unique_ptr<B, Deleter<B> > s(new B);
|
||||
std::unique_ptr<A, Deleter<A> > s2 = s;
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
template <class T>
|
||||
class CDeleter
|
||||
{
|
||||
int state_;
|
||||
|
||||
CDeleter(CDeleter&);
|
||||
CDeleter& operator=(CDeleter&);
|
||||
public:
|
||||
|
||||
CDeleter() : state_(5) {}
|
||||
|
||||
int state() const {return state_;}
|
||||
void set_state(int s) {state_ = s;}
|
||||
|
||||
void operator()(T* p) {delete p;}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
CDeleter<A> d;
|
||||
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A, CDeleter<A>&> s2 = s;
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
d.set_state(6);
|
||||
assert(s2.get_deleter().state() == d.state());
|
||||
assert(s.get_deleter().state() == d.state());
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <memory>
|
||||
|
||||
// unique_ptr
|
||||
|
||||
// Test unique_ptr converting move ctor
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
// test converting move ctor. Should only require a MoveConstructible deleter, or if
|
||||
// deleter is a reference, not even that.
|
||||
// Explicit version
|
||||
|
||||
struct A
|
||||
{
|
||||
static int count;
|
||||
A() {++count;}
|
||||
A(const A&) {++count;}
|
||||
virtual ~A() {--count;}
|
||||
};
|
||||
|
||||
int A::count = 0;
|
||||
|
||||
struct B
|
||||
: public A
|
||||
{
|
||||
static int count;
|
||||
B() {++count;}
|
||||
B(const B&) {++count;}
|
||||
virtual ~B() {--count;}
|
||||
};
|
||||
|
||||
int B::count = 0;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
const std::unique_ptr<B> s(new B);
|
||||
A* p = s.get();
|
||||
std::unique_ptr<A> s2(s);
|
||||
assert(s2.get() == p);
|
||||
assert(s.get() == 0);
|
||||
assert(A::count == 1);
|
||||
assert(B::count == 1);
|
||||
}
|
||||
assert(A::count == 0);
|
||||
assert(B::count == 0);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue