aboutsummaryrefslogtreecommitdiff
path: root/test/std/utilities/memory
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:54:09 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:54:09 +0000
commitb4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch)
tree13f237c02db4d1894ab06884d1b739344766bede /test/std/utilities/memory
parent61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff)
downloadsrc-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.tar.gz
src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.zip
Vendor import of libc++ trunk r256633:vendor/libc++/r256633
Notes
Notes: svn path=/vendor/libc++/dist/; revision=292928 svn path=/vendor/libc++/r256633/; revision=292930; tag=vendor/libc++/r256633
Diffstat (limited to 'test/std/utilities/memory')
-rw-r--r--test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp4
-rw-r--r--test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp25
-rw-r--r--test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp4
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp15
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp15
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp14
-rw-r--r--test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp14
-rw-r--r--test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp27
-rw-r--r--test/std/utilities/memory/unique.ptr/deleter.h230
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp25
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp22
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp23
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp34
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp25
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp27
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp43
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp48
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp89
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp41
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp56
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp44
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp60
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp47
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp63
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp40
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp2
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp16
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp86
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp46
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp84
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp140
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp142
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp143
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp171
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp58
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp62
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp79
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp58
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp62
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp79
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp63
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp163
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp63
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp95
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp78
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp123
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp99
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp58
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp60
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp43
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp58
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp66
-rw-r--r--test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp39
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp1
-rw-r--r--test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp40
62 files changed, 1231 insertions, 2088 deletions
diff --git a/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp b/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp
index 1fa7291203ed..352c7c8d0caf 100644
--- a/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp
+++ b/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp
@@ -45,12 +45,12 @@ int main()
{
A<int> a;
assert(std::allocator_traits<A<int> >::max_size(a) ==
- std::numeric_limits<std::size_t>::max());
+ std::numeric_limits<std::size_t>::max() / sizeof(int));
}
{
const A<int> a = {};
assert(std::allocator_traits<A<int> >::max_size(a) ==
- std::numeric_limits<std::size_t>::max());
+ std::numeric_limits<std::size_t>::max() / sizeof(int));
}
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
diff --git a/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp
index d0a870e60690..28dadd831514 100644
--- a/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp
+++ b/test/std/utilities/memory/default.allocator/allocator.members/construct.pass.cpp
@@ -15,6 +15,7 @@
#include <memory>
#include <cassert>
+#include "test_macros.h"
#include "count_new.hpp"
int A_constructed = 0;
@@ -34,30 +35,24 @@ struct A
int move_only_constructed = 0;
+#if TEST_STD_VER >= 11
class move_only
{
- int data;
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- move_only(const move_only&);
- move_only& operator=(const move_only&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- move_only(move_only&);
- move_only& operator=(move_only&);
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+ move_only(const move_only&) = delete;
+ move_only& operator=(const move_only&)= delete;
public:
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
move_only(move_only&&) {++move_only_constructed;}
move_only& operator=(move_only&&) {return *this;}
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- operator std::__rv<move_only> () {return std::__rv<move_only>(*this);}
- move_only(std::__rv<move_only>) {++move_only_constructed;}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
move_only() {++move_only_constructed;}
~move_only() {--move_only_constructed;}
+
+public:
+ int data; // unused other than to make sizeof(move_only) == sizeof(int).
+ // but public to suppress "-Wunused-private-field"
};
+#endif // TEST_STD_VER >= 11
int main()
{
@@ -108,6 +103,7 @@ int main()
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(A_constructed == 0);
}
+#if TEST_STD_VER >= 11
{
std::allocator<move_only> a;
assert(globalMemCounter.checkOutstandingNewEq(0));
@@ -139,4 +135,5 @@ int main()
assert(globalMemCounter.checkOutstandingNewEq(0));
assert(move_only_constructed == 0);
}
+#endif
}
diff --git a/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp b/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp
index 6ec9339bc48f..10109383b0c7 100644
--- a/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp
+++ b/test/std/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp
@@ -22,6 +22,6 @@ int new_called = 0;
int main()
{
const std::allocator<int> a;
- std::size_t M = a.max_size() * sizeof(int);
- assert(M > 0xFFFF && M <= std::numeric_limits<std::size_t>::max());
+ std::size_t M = a.max_size();
+ assert(M > 0xFFFF && M <= (std::numeric_limits<std::size_t>::max() / sizeof(int)));
}
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
index f431335db732..8bb818319a37 100644
--- a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template <class InputIterator, class ForwardIterator>
@@ -20,13 +21,15 @@
struct B
{
static int count_;
+ static int population_;
int data_;
- explicit B() : data_(1) {}
- B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
- ~B() {data_ = 0;}
+ explicit B() : data_(1) { ++population_; }
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
+ ~B() {data_ = 0; --population_; }
};
int B::count_ = 0;
+int B::population_ = 0;
struct Nasty
{
@@ -45,6 +48,7 @@ int main()
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
+ assert(B::population_ == N);
try
{
std::uninitialized_copy(b, b+N, bp);
@@ -52,14 +56,15 @@ int main()
}
catch (...)
{
- for (int i = 0; i < N; ++i)
- assert(bp[i].data_ == 0);
+ assert(B::population_ == N);
}
B::count_ = 0;
std::uninitialized_copy(b, b+2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ assert(B::population_ == N + 2);
}
+
{
const int N = 5;
char pool[sizeof(Nasty)*N] = {0};
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
index 3b2007b969c3..ae438ef7d561 100644
--- a/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template <class InputIterator, class Size, class ForwardIterator>
@@ -20,12 +21,14 @@
struct B
{
static int count_;
+ static int population_;
int data_;
- explicit B() : data_(1) {}
- B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
- ~B() {data_ = 0;}
+ explicit B() : data_(1) { ++population_; }
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
+ ~B() {data_ = 0; --population_; }
};
+int B::population_ = 0;
int B::count_ = 0;
struct Nasty
@@ -45,6 +48,7 @@ int main()
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
+ assert(B::population_ == N);
try
{
std::uninitialized_copy_n(b, 5, bp);
@@ -52,14 +56,15 @@ int main()
}
catch (...)
{
- for (int i = 0; i < N; ++i)
- assert(bp[i].data_ == 0);
+ assert(B::population_ == N);
}
B::count_ = 0;
std::uninitialized_copy_n(b, 2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ assert(B::population_ == N + 2);
}
+
{
const int N = 5;
char pool[sizeof(Nasty)*N] = {0};
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
index d2b1dfa28868..22aa8b98b8c9 100644
--- a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template <class ForwardIterator, class Size, class T>
@@ -19,13 +20,15 @@
struct B
{
static int count_;
+ static int population_;
int data_;
- explicit B() : data_(1) {}
- B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
- ~B() {data_ = 0;}
+ explicit B() : data_(1) { ++population_; }
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
+ ~B() {data_ = 0; --population_; }
};
int B::count_ = 0;
+int B::population_ = 0;
struct Nasty
{
@@ -43,6 +46,7 @@ int main()
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
+ assert(B::population_ == 0);
try
{
std::uninitialized_fill_n(bp, 5, B());
@@ -50,14 +54,14 @@ int main()
}
catch (...)
{
- for (int i = 0; i < N; ++i)
- assert(bp[i].data_ == 0);
+ assert(B::population_ == 0);
}
B::count_ = 0;
B* r = std::uninitialized_fill_n(bp, 2, B());
assert(r == bp + 2);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ assert(B::population_ == 2);
}
{
{
diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
index 47cabdfa478a..95c45dd50541 100644
--- a/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
+++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template <class ForwardIterator, class T>
@@ -20,13 +21,15 @@
struct B
{
static int count_;
+ static int population_;
int data_;
- explicit B() : data_(1) {}
- B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
- ~B() {data_ = 0;}
+ explicit B() : data_(1) { ++population_; }
+ B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_; ++population_; }
+ ~B() {data_ = 0; --population_; }
};
int B::count_ = 0;
+int B::population_ = 0;
struct Nasty
{
@@ -44,6 +47,7 @@ int main()
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
+ assert(B::population_ == 0);
try
{
std::uninitialized_fill(bp, bp+N, B());
@@ -51,13 +55,13 @@ int main()
}
catch (...)
{
- for (int i = 0; i < N; ++i)
- assert(bp[i].data_ == 0);
+ assert(B::population_ == 0);
}
B::count_ = 0;
std::uninitialized_fill(bp, bp+2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
+ assert(B::population_ == 2);
}
{
const int N = 5;
diff --git a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp b/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp
index f77d6c75e17a..914802423ce7 100644
--- a/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp
+++ b/test/std/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp
@@ -13,6 +13,8 @@
#include <type_traits>
#include <cassert>
+#include <MoveOnly.h>
+
int A_constructed = 0;
struct A
@@ -29,16 +31,33 @@ public:
int main()
{
- typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
+ {
+ typedef A S;
+ typedef std::aligned_storage<3*sizeof(S), std::alignment_of<S>::value>::type
Storage;
Storage buffer;
- std::raw_storage_iterator<A*, A> it((A*)&buffer);
+ std::raw_storage_iterator<S*, S> it((S*)&buffer);
assert(A_constructed == 0);
for (int i = 0; i < 3; ++i)
{
- *it++ = A(i+1);
- A* ap = (A*)&buffer + i;
+ *it++ = S(i+1);
+ S* ap = (S*)&buffer + i;
assert(*ap == i+1);
assert(A_constructed == i+1);
}
+ }
+#if _LIBCPP_STD_VER >= 14
+ {
+ typedef MoveOnly S;
+ typedef std::aligned_storage<3*sizeof(S), std::alignment_of<S>::value>::type
+ Storage;
+ Storage buffer;
+ std::raw_storage_iterator<S*, S> it((S*)&buffer);
+ S m{1};
+ *it++ = std::move(m);
+ assert(m.get() == 0); // moved from
+ S *ap = (S*) &buffer;
+ assert(ap->get() == 1); // original value
+ }
+#endif
}
diff --git a/test/std/utilities/memory/unique.ptr/deleter.h b/test/std/utilities/memory/unique.ptr/deleter.h
index fb26044d98ff..1d8e19d5bc41 100644
--- a/test/std/utilities/memory/unique.ptr/deleter.h
+++ b/test/std/utilities/memory/unique.ptr/deleter.h
@@ -20,21 +20,19 @@
#include <utility>
#include <cassert>
+#include "test_macros.h"
+
+#if TEST_STD_VER >= 11
+
template <class T>
class Deleter
{
int state_;
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
public:
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
@@ -42,22 +40,12 @@ public:
r.state_ = 0;
return *this;
}
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
- Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
- Deleter& operator=(std::__rv<Deleter> r)
- {
- state_ = r->state_;
- r->state_ = 0;
- return *this;
- }
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
Deleter() : state_(0) {}
explicit Deleter(int s) : state_(s) {}
~Deleter() {assert(state_ >= 0); state_ = -1;}
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class U>
Deleter(Deleter<U>&& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
@@ -67,12 +55,6 @@ private:
template <class U>
Deleter(const Deleter<U>& d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U> d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
@@ -85,16 +67,11 @@ class Deleter<T[]>
{
int state_;
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
public:
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
@@ -102,16 +79,66 @@ public:
r.state_ = 0;
return *this;
}
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
- Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
- Deleter& operator=(std::__rv<Deleter> r)
- {
- state_ = r->state_;
- r->state_ = 0;
+
+ Deleter() : state_(0) {}
+ explicit Deleter(int s) : state_(s) {}
+ ~Deleter() {assert(state_ >= 0); state_ = -1;}
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) {delete [] p;}
+};
+
+#else // TEST_STD_VER < 11
+
+template <class T>
+class Deleter
+{
+ mutable int state_;
+
+public:
+ Deleter() : state_(0) {}
+ explicit Deleter(int s) : state_(s) {}
+
+ Deleter(Deleter const & other) : state_(other.state_) {
+ other.state_ = 0;
+ }
+ Deleter& operator=(Deleter const& other) {
+ state_ = other.state_;
+ other.state_ = 0;
+ return *this;
+ }
+
+ ~Deleter() {assert(state_ >= 0); state_ = -1;}
+
+ template <class U>
+ Deleter(Deleter<U> d,
+ typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
+ : state_(d.state()) {}
+
+public:
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) {delete p;}
+};
+
+template <class T>
+class Deleter<T[]>
+{
+ mutable int state_;
+
+public:
+
+ Deleter(Deleter const& other) : state_(other.state_) {
+ other.state_ = 0;
+ }
+ Deleter& operator=(Deleter const& other) {
+ state_ = other.state_;
+ other.state_ = 0;
return *this;
}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Deleter() : state_(0) {}
explicit Deleter(int s) : state_(s) {}
@@ -123,6 +150,8 @@ public:
void operator()(T* p) {delete [] p;}
};
+#endif
+
template <class T>
void
swap(Deleter<T>& x, Deleter<T>& y)
@@ -132,6 +161,7 @@ swap(Deleter<T>& x, Deleter<T>& y)
y = std::move(t);
}
+
template <class T>
class CDeleter
{
@@ -179,4 +209,130 @@ swap(CDeleter<T>& x, CDeleter<T>& y)
y = std::move(t);
}
+// Non-copyable deleter
+template <class T>
+class NCDeleter
+{
+ int state_;
+ NCDeleter(NCDeleter const&);
+ NCDeleter& operator=(NCDeleter const&);
+public:
+
+ NCDeleter() : state_(0) {}
+ explicit NCDeleter(int s) : state_(s) {}
+ ~NCDeleter() {assert(state_ >= 0); state_ = -1;}
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) {delete p;}
+};
+
+
+template <class T>
+class NCDeleter<T[]>
+{
+ int state_;
+ NCDeleter(NCDeleter const&);
+ NCDeleter& operator=(NCDeleter const&);
+public:
+
+ NCDeleter() : state_(0) {}
+ explicit NCDeleter(int s) : state_(s) {}
+ ~NCDeleter() {assert(state_ >= 0); state_ = -1;}
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) {delete [] p;}
+};
+
+
+// Non-copyable deleter
+template <class T>
+class NCConstDeleter
+{
+ int state_;
+ NCConstDeleter(NCConstDeleter const&);
+ NCConstDeleter& operator=(NCConstDeleter const&);
+public:
+
+ NCConstDeleter() : state_(0) {}
+ explicit NCConstDeleter(int s) : state_(s) {}
+ ~NCConstDeleter() {assert(state_ >= 0); state_ = -1;}
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) const {delete p;}
+};
+
+
+template <class T>
+class NCConstDeleter<T[]>
+{
+ int state_;
+ NCConstDeleter(NCConstDeleter const&);
+ NCConstDeleter& operator=(NCConstDeleter const&);
+public:
+
+ NCConstDeleter() : state_(0) {}
+ explicit NCConstDeleter(int s) : state_(s) {}
+ ~NCConstDeleter() {assert(state_ >= 0); state_ = -1;}
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) const {delete [] p;}
+};
+
+
+// Non-copyable deleter
+template <class T>
+class CopyDeleter
+{
+ int state_;
+public:
+
+ CopyDeleter() : state_(0) {}
+ explicit CopyDeleter(int s) : state_(s) {}
+ ~CopyDeleter() {assert(state_ >= 0); state_ = -1;}
+
+ CopyDeleter(CopyDeleter const& other) : state_(other.state_) {}
+ CopyDeleter& operator=(CopyDeleter const& other) {
+ state_ = other.state_;
+ return *this;
+ }
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) {delete p;}
+};
+
+
+template <class T>
+class CopyDeleter<T[]>
+{
+ int state_;
+
+public:
+
+ CopyDeleter() : state_(0) {}
+ explicit CopyDeleter(int s) : state_(s) {}
+ ~CopyDeleter() {assert(state_ >= 0); state_ = -1;}
+
+ CopyDeleter(CopyDeleter const& other) : state_(other.state_) {}
+ CopyDeleter& operator=(CopyDeleter const& other) {
+ state_ = other.state_;
+ return *this;
+ }
+
+ int state() const {return state_;}
+ void set_state(int i) {state_ = i;}
+
+ void operator()(T* p) {delete [] p;}
+};
+
+
#endif // DELETER_H
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp
index 17375ede00f5..ed94c1a1e470 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp
@@ -14,26 +14,15 @@
// 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;
+#include "test_macros.h"
int main()
{
- {
- std::unique_ptr<A> s(new A);
- std::unique_ptr<A> s2;
- s2 = s;
- }
+ 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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp
index 03747b4f89cf..5088a4410e79 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp
@@ -32,22 +32,6 @@ struct A
int A::count = 0;
-class NCDeleter
-{
- int state_;
-
- NCDeleter(NCDeleter&);
- NCDeleter& operator=(NCDeleter&);
-public:
-
- NCDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(A* p) {delete [] p;}
-};
-
int main()
{
{
@@ -71,10 +55,10 @@ int main()
}
assert(A::count == 0);
{
- NCDeleter d;
- std::unique_ptr<A[], NCDeleter&> s(new A[3], d);
+ NCDeleter<A[]> d;
+ std::unique_ptr<A[], NCDeleter<A[]>&> s(new A[3], d);
A* p = s.get();
- std::unique_ptr<A[], NCDeleter&> s2 = std::move(s);
+ std::unique_ptr<A[], NCDeleter<A[]>&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp
index ef821a915e44..5720d3bd288f 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp
@@ -31,21 +31,6 @@ struct A
int A::count = 0;
-class NCDeleter
-{
- int state_;
-
- NCDeleter(NCDeleter&);
- NCDeleter& operator=(NCDeleter&);
-public:
-
- NCDeleter() : state_(5) {}
-
- int state() const {return state_;}
- void set_state(int s) {state_ = s;}
-
- void operator()(A* p) {delete [] p;}
-};
std::unique_ptr<A[]>
source1()
@@ -67,14 +52,14 @@ void sink2(std::unique_ptr<A[], Deleter<A[]> > p)
{
}
-std::unique_ptr<A[], NCDeleter&>
+std::unique_ptr<A[], NCDeleter<A[]>&>
source3()
{
- static NCDeleter d;
- return std::unique_ptr<A[], NCDeleter&>(new A[3], d);
+ static NCDeleter<A[]> d;
+ return std::unique_ptr<A[], NCDeleter<A[]>&>(new A[3], d);
}
-void sink3(std::unique_ptr<A[], NCDeleter&> p)
+void sink3(std::unique_ptr<A[], NCDeleter<A[]>&> p)
{
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp
index b635d507b2ec..9d3f94098a08 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp
@@ -7,6 +7,8 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: c++98, c++03
+
// <memory>
// unique_ptr
@@ -16,40 +18,16 @@
// unique_ptr<T, const D&>(pointer, D()) should not compile
#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) const {delete [] p;}
+ Deleter() {}
+ void operator()(int* p) const {delete [] p;}
};
int main()
{
- {
- A* p = new A[3];
- assert(A::count == 3);
- std::unique_ptr<A[], const Deleter&> s(p, Deleter());
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
+ int* p = nullptr;
+ std::unique_ptr<int[], const Deleter&> s(p, Deleter()); // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}}
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp
index 57724ae10a70..87cfb72ad6e0 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp
@@ -14,25 +14,16 @@
// Test unique_ptr move assignment
#include <memory>
-#include <cassert>
-// Can't copy from lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
+#include "test_macros.h"
+// Can't copy from lvalue
int main()
{
- {
- std::unique_ptr<A> s(new A);
- std::unique_ptr<A> s2;
- s2 = s;
- }
+ 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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp
index 5046fd8aae6b..9cea12b1249f 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp
@@ -14,25 +14,20 @@
// Test unique_ptr move assignment
#include <memory>
-#include <cassert>
-// Can't copy from const lvalue
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
+#include "test_macros.h"
-int A::count = 0;
+// Can't copy from const lvalue
int main()
{
- {
- const std::unique_ptr<A> s(new A);
- std::unique_ptr<A> s2;
- s2 = s;
- }
+ 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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp
index aa4fdb8a96b1..05a057f9bb32 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp
@@ -14,43 +14,20 @@
// Test unique_ptr move assignment
#include <memory>
-#include <cassert>
-// Can't copy from lvalue
+#include "test_macros.h"
-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;}
+struct Deleter {
+ void operator()(int* p) {delete p;}
};
+// Can't copy from lvalue
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);
+ 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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp
index e0d7c891c80f..24703ec98238 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp
@@ -11,46 +11,26 @@
// unique_ptr
-// Test unique_ptr move ctor
+// Test unique_ptr move assignment
#include <memory>
-#include <cassert>
-// test move ctor. Can't copy from const lvalue
+#include "test_macros.h"
-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;}
+struct Deleter {
+ void operator()(int* p) {delete p;}
};
+// Can't copy from a const lvalue
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);
+ 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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp
new file mode 100644
index 000000000000..4c4a32035641
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp
@@ -0,0 +1,89 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.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);
+}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp
index 3fd2cbc42bd6..816a598d9a23 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp
@@ -14,44 +14,29 @@
// Test unique_ptr converting move assignment
#include <memory>
-#include <utility>
-#include <cassert>
-// Can't assign from lvalue
+#include "test_macros.h"
struct A
{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
+ A() {}
+ virtual ~A() {}
};
-int A::count = 0;
-
-struct B
- : public A
+struct B : public A
{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
};
-int B::count = 0;
-
+// Can't assign from lvalue
int main()
{
- {
- std::unique_ptr<B> s(new B);
- A* p = s.get();
+ std::unique_ptr<B> s;
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);
+#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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp
deleted file mode 100644
index 989f594e38b8..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp
+++ /dev/null
@@ -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()
-{
- {
- std::unique_ptr<B> s(new B);
- A* p = s.get();
- std::unique_ptr<A> s2(new A);
- assert(A::count == 2);
- 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp
index 0f900603e239..1ddf1d811651 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp
@@ -14,48 +14,30 @@
// Test unique_ptr converting move assignment
#include <memory>
-#include <utility>
-#include <cassert>
+#include "test_macros.h"
#include "../../deleter.h"
-// Can't assign from lvalue
-
struct A
{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
+ A() {}
+ virtual ~A() {}
};
-int A::count = 0;
-
-struct B
- : public A
+struct B : public A
{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
};
-int B::count = 0;
-
+// Can't assign from lvalue
int main()
{
- {
- std::unique_ptr<B, Deleter<B> > s(new B);
- A* p = s.get();
+ std::unique_ptr<B, Deleter<B> > s;
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);
+#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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp
deleted file mode 100644
index a448c77a66a7..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp
+++ /dev/null
@@ -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.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, Deleter<B>(5));
- A* p = s.get();
- std::unique_ptr<A, Deleter<A> > s2(new A);
- assert(A::count == 2);
- 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp
index f35af9f453ff..570c1c42f4fe 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp
@@ -16,47 +16,32 @@
// Can't assign from lvalue
#include <memory>
-#include <utility>
-#include <cassert>
+#include "test_macros.h"
#include "../../deleter.h"
struct A
{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
+ A() {}
+ virtual ~A() {}
};
-int A::count = 0;
-
-struct B
- : public A
+struct B : public A
{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
};
-int B::count = 0;
-
+// Can't assign from lvalue
int main()
{
- {
- Deleter<B> db(5);
- 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);
+ 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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp
deleted file mode 100644
index 9aea81a8b144..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp
+++ /dev/null
@@ -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 converting move assignment
-
-// test converting move assignment with reference deleters
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "../../deleter.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()
-{
- {
- CDeleter<B> db(5);
- std::unique_ptr<B, CDeleter<B>&> s(new B, db);
- A* p = s.get();
- CDeleter<A> da(6);
- std::unique_ptr<A, CDeleter<A>&> s2(new A, da);
- s2 = std::move(s);
- assert(s2.get() == p);
- assert(s.get() == 0);
- assert(A::count == 1);
- assert(B::count == 1);
- assert(s.get_deleter().state() == 5);
- assert(s2.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp
index dba901b2ce17..2ebc33d21d81 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp
@@ -14,44 +14,30 @@
// Test unique_ptr converting move assignment
#include <memory>
-#include <utility>
-#include <cassert>
-// Can't assign from const lvalue
+#include "test_macros.h"
+#include "../../deleter.h"
struct A
{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- virtual ~A() {--count;}
+ A() {}
+ virtual ~A() {}
};
-int A::count = 0;
-
-struct B
- : public A
+struct B : public A
{
- static int count;
- B() {++count;}
- B(const B&) {++count;}
- virtual ~B() {--count;}
};
-int B::count = 0;
-
+// Can't assign from lvalue
int main()
{
- {
const 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);
+#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
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp
index 56ab43c7de24..412648420d46 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp
@@ -32,5 +32,5 @@ int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2;
- s2 = std::move(s);
+ s2 = std::move(s); // expected-error {{no viable overloaded '='}}
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp
index 1ce1838afbb7..7c3ac462c287 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp
@@ -7,17 +7,21 @@
//
//===----------------------------------------------------------------------===//
+// libc++ cannot safely provide the auto_ptr constructor without rvalue
+// references.
+// XFAIL: c++98, c++03
+
// <memory>
// unique_ptr
-// Test unique_ptr(pointer) ctor
+// template <class U> unique_ptr(auto_ptr<U>&&) noexcept
#include <memory>
#include <utility>
#include <cassert>
-// template <class U> explicit unique_ptr(auto_ptr<U>&);
+#include "test_macros.h"
struct A
{
@@ -65,4 +69,12 @@ int main()
}
assert(A::count == 0);
assert(B::count == 0);
+#if TEST_STD_VER >= 11
+ {
+ static_assert(std::is_nothrow_constructible<
+ std::unique_ptr<A>,
+ std::auto_ptr<B>&&
+ >::value, "");
+ }
+#endif
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp
new file mode 100644
index 000000000000..2694538145b9
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp
@@ -0,0 +1,86 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 a incomplete element_type and
+// various deleter types (C-1,2)
+
+#include <memory>
+#include <cassert>
+
+#include "../../deleter.h"
+
+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() { } \ No newline at end of file
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp
deleted file mode 100644
index e63db5cb7185..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp
+++ /dev/null
@@ -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
-
-// Test unique_ptr default ctor
-
-#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;
- assert(p.get() == 0);
- }
- {
- std::unique_ptr<int, Deleter> p;
- assert(p.get() == 0);
- assert(p.get_deleter().state() == 5);
- }
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp
deleted file mode 100644
index e9af7e285255..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp
+++ /dev/null
@@ -1,84 +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 ctor
-
-#include <memory>
-#include <cassert>
-
-// default unique_ptr ctor shouldn't require complete type
-
-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() {}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp
new file mode 100644
index 000000000000..4c5cc843a138
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp
@@ -0,0 +1,140 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.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);
+}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp
deleted file mode 100644
index dc16c3115376..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp
+++ /dev/null
@@ -1,142 +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. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-template <class T>
-class Deleter
-{
- int state_;
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-public:
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
- Deleter& operator=(Deleter&& r)
- {
- state_ = r.state_;
- r.state_ = 0;
- return *this;
- }
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
- Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
- Deleter& operator=(std::__rv<Deleter> r)
- {
- state_ = r->state_;
- r->state_ = 0;
- return *this;
- }
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
- Deleter() : state_(5) {}
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U>&& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {d.set_state(0);}
-
-private:
- template <class U>
- Deleter(const Deleter<U>& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U> d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-public:
- int state() const {return state_;}
- void set_state(int i) {state_ = i;}
-
- void operator()(T* p) {delete p;}
-};
-
-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()(A* p) {delete p;}
-};
-
-int main()
-{
- {
- std::unique_ptr<A> s(new A);
- 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(A::count == 0);
- {
- std::unique_ptr<A, Deleter<A> > s(new A);
- 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(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 0);
- }
- assert(A::count == 0);
- {
- CDeleter d;
- std::unique_ptr<A, CDeleter&> s(new A, d);
- A* p = s.get();
- std::unique_ptr<A, CDeleter&> 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp
deleted file mode 100644
index 4b997df95a0b..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp
+++ /dev/null
@@ -1,143 +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. Should only require a MoveConstructible deleter, or if
-// deleter is a reference, not even that.
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-template <class T>
-class Deleter
-{
- int state_;
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-public:
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
- Deleter& operator=(Deleter&& r)
- {
- state_ = r.state_;
- r.state_ = 0;
- return *this;
- }
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
- Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
- Deleter& operator=(std::__rv<Deleter> r)
- {
- state_ = r->state_;
- r->state_ = 0;
- return *this;
- }
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
- Deleter() : state_(5) {}
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U>&& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {d.set_state(0);}
-
-private:
- template <class U>
- Deleter(const Deleter<U>& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U> d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-public:
- int state() const {return state_;}
- void set_state(int i) {state_ = i;}
-
- void operator()(T* p) {delete p;}
-};
-
-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()(A* p) {delete p;}
-};
-
-std::unique_ptr<A>
-source1()
-{
- return std::unique_ptr<A>(new A);
-}
-
-void sink1(std::unique_ptr<A> p)
-{
-}
-
-std::unique_ptr<A, Deleter<A> >
-source2()
-{
- return std::unique_ptr<A, Deleter<A> >(new A);
-}
-
-void sink2(std::unique_ptr<A, Deleter<A> > p)
-{
-}
-
-std::unique_ptr<A, CDeleter&>
-source3()
-{
- static CDeleter d;
- return std::unique_ptr<A, CDeleter&>(new A, d);
-}
-
-void sink3(std::unique_ptr<A, CDeleter&> p)
-{
-}
-
-int main()
-{
- sink1(source1());
- sink2(source2());
- sink3(source3());
- assert(A::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp
new file mode 100644
index 000000000000..f00fcfe15b80
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp
@@ -0,0 +1,171 @@
+//===----------------------------------------------------------------------===//
+//
+// 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.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();
+ }
+}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp
deleted file mode 100644
index b65cf564a925..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp
+++ /dev/null
@@ -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()
-{
- {
- 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp
deleted file mode 100644
index 829e7553acd9..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp
+++ /dev/null
@@ -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
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "../../deleter.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;
-
-int main()
-{
- {
- std::unique_ptr<B, Deleter<B> > s(new B, Deleter<B>(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 == 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp
deleted file mode 100644
index 792076a95245..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp
+++ /dev/null
@@ -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(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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp
deleted file mode 100644
index 12ab17fadcd3..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp
+++ /dev/null
@@ -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 = 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp
deleted file mode 100644
index 8077b0dacb23..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp
+++ /dev/null
@@ -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
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "../../deleter.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, Deleter<B>(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 == 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp
deleted file mode 100644
index 4115107b85f9..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp
+++ /dev/null
@@ -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 = 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp
deleted file mode 100644
index 978cb0e9024b..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp
+++ /dev/null
@@ -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 converting move ctor
-
-#include <memory>
-#include <utility>
-#include <cassert>
-
-#include "../../deleter.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()
-{
- {
- CDeleter<B> b(5);
- std::unique_ptr<B, CDeleter<B>&> s(new B, b);
- 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);
- assert(s2.get_deleter().state() == 5);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp
new file mode 100644
index 000000000000..faa554d8b320
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp
@@ -0,0 +1,163 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 pointer constructor works for any default constructible deleter types.
+// 2 The pointer constructor accepts pointers to derived types.
+// 2 The stored type 'T' is allowed to be incomplete.
+//
+// Plan
+// 1 Construct unique_ptr<T, D>'s with a pointer to 'T' and various deleter
+// types (C-1)
+// 2 Construct unique_ptr<T, D>'s with a pointer to 'D' and various deleter
+// types where 'D' is derived from 'T'. (C-1,2)
+// 3 Construct a unique_ptr<T, D> with a pointer to 'T' and various deleter
+// types where 'T' is an incomplete type (C-1,3)
+
+// Test unique_ptr(pointer) ctor
+
+#include <memory>
+#include <cassert>
+
+#include "../../deleter.h"
+
+// unique_ptr(pointer) ctor should only require default Deleter ctor
+
+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 IncompleteT;
+
+IncompleteT* getIncomplete();
+void checkNumIncompleteTypeAlive(int i);
+
+template <class Del = std::default_delete<IncompleteT> >
+struct StoresIncomplete {
+ std::unique_ptr<IncompleteT, Del> m_ptr;
+ StoresIncomplete() {}
+ explicit StoresIncomplete(IncompleteT* ptr) : m_ptr(ptr) {}
+ ~StoresIncomplete();
+
+ IncompleteT* get() const { return m_ptr.get(); }
+ Del& get_deleter() { return m_ptr.get_deleter(); }
+};
+
+void test_pointer()
+{
+ {
+ A* p = new A;
+ assert(A::count == 1);
+ std::unique_ptr<A> s(p);
+ assert(s.get() == p);
+ }
+ assert(A::count == 0);
+ {
+ A* p = new A;
+ assert(A::count == 1);
+ std::unique_ptr<A, NCDeleter<A> > s(p);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 0);
+ }
+ assert(A::count == 0);
+}
+
+void test_derived()
+{
+ {
+ B* p = new B;
+ assert(A::count == 1);
+ assert(B::count == 1);
+ std::unique_ptr<A> s(p);
+ assert(s.get() == p);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ {
+ B* p = new B;
+ assert(A::count == 1);
+ assert(B::count == 1);
+ std::unique_ptr<A, NCDeleter<A> > s(p);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 0);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+}
+
+void test_incomplete()
+{
+ {
+ IncompleteT* p = getIncomplete();
+ checkNumIncompleteTypeAlive(1);
+ StoresIncomplete<> s(p);
+ assert(s.get() == p);
+ }
+ checkNumIncompleteTypeAlive(0);
+ {
+ IncompleteT* p = getIncomplete();
+ checkNumIncompleteTypeAlive(1);
+ StoresIncomplete< NCDeleter<IncompleteT> > s(p);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 0);
+ }
+ checkNumIncompleteTypeAlive(0);
+}
+
+struct IncompleteT {
+ static int count;
+ IncompleteT() { ++count; }
+ ~IncompleteT() {--count; }
+};
+
+int IncompleteT::count = 0;
+
+IncompleteT* getIncomplete() {
+ return new IncompleteT;
+}
+
+void checkNumIncompleteTypeAlive(int i) {
+ assert(IncompleteT::count == i);
+}
+
+template <class Del>
+StoresIncomplete<Del>::~StoresIncomplete() { }
+
+int main()
+{
+ test_pointer();
+ test_derived();
+ test_incomplete();
+}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp
deleted file mode 100644
index e5fff774b790..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp
+++ /dev/null
@@ -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
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr(pointer) ctor should only require default Deleter ctor
-
-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;
- assert(A::count == 1);
- std::unique_ptr<A> s(p);
- assert(s.get() == p);
- }
- assert(A::count == 0);
- {
- A* p = new A;
- assert(A::count == 1);
- std::unique_ptr<A, Deleter> s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp
deleted file mode 100644
index a226e87d64a4..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp
+++ /dev/null
@@ -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(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr(pointer) ctor shouldn't require complete type
-
-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(1);
- B<> s(p);
- assert(s.get() == p);
- }
- check(0);
- {
- A* p = get();
- check(1);
- 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;}
-
-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() {}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp
deleted file mode 100644
index 42fc09453914..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp
+++ /dev/null
@@ -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(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr(pointer) ctor should work with derived pointers
-
-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;
- assert(A::count == 1);
- assert(B::count == 1);
- std::unique_ptr<A> s(p);
- assert(s.get() == p);
- }
- assert(A::count == 0);
- assert(B::count == 0);
- {
- B* p = new B;
- assert(A::count == 1);
- assert(B::count == 1);
- std::unique_ptr<A, Deleter> s(p);
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp
new file mode 100644
index 000000000000..7ddd16265107
--- /dev/null
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp
@@ -0,0 +1,123 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 unique_ptr(pointer, deleter)
+//
+// Concerns:
+// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter.
+// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter.
+// 3 unique_ptr<T, D&>(pointer, deleter) does not require a CopyConstructible deleter.
+// 4 unique_ptr<T, D const&>(pointer, deleter) does not require a CopyConstructible deleter.
+// 5 unique_ptr(pointer, deleter) should work for derived pointers.
+// 6 unique_ptr(pointer, deleter) should work with function pointers.
+// 7 unique_ptr<void> should work.
+
+
+#include <memory>
+#include <cassert>
+
+#include "../../deleter.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;
+
+bool my_free_called = false;
+
+void my_free(void*) {
+ my_free_called = true;
+}
+
+int main()
+{
+ { // MoveConstructible deleter (C-1)
+ A* p = new A;
+ assert(A::count == 1);
+ std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5));
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ }
+ assert(A::count == 0);
+ { // CopyConstructible deleter (C-2)
+ A* p = new A;
+ assert(A::count == 1);
+ CopyDeleter<A> d(5);
+ std::unique_ptr<A, CopyDeleter<A> > 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);
+ { // Reference deleter (C-3)
+ A* p = new A;
+ assert(A::count == 1);
+ NCDeleter<A> d(5);
+ std::unique_ptr<A, NCDeleter<A>&> s(p, d);
+ assert(s.get() == p);
+ assert(&s.get_deleter() == &d);
+ assert(s.get_deleter().state() == 5);
+ d.set_state(6);
+ assert(s.get_deleter().state() == 6);
+ }
+ assert(A::count == 0);
+ { // Const Reference deleter (C-4)
+ A* p = new A;
+ assert(A::count == 1);
+ NCConstDeleter<A> d(5);
+ std::unique_ptr<A, NCConstDeleter<A> const&> s(p, d);
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ assert(&s.get_deleter() == &d);
+ }
+ assert(A::count == 0);
+ { // Derived pointers (C-5)
+ B* p = new B;
+ assert(A::count == 1);
+ assert(B::count == 1);
+ std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5));
+ assert(s.get() == p);
+ assert(s.get_deleter().state() == 5);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+ { // Void and function pointers (C-6,7)
+ {
+ int i = 0;
+ std::unique_ptr<void, void(*)(void*)> s(&i, my_free);
+ assert(s.get() == &i);
+ assert(s.get_deleter() == my_free);
+ assert(!my_free_called);
+ }
+ assert(my_free_called);
+ }
+}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp
deleted file mode 100644
index 130f91d6216f..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp
+++ /dev/null
@@ -1,99 +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>
-
-// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
-
-struct A
-{
- static int count;
- A() {++count;}
- A(const A&) {++count;}
- ~A() {--count;}
-};
-
-int A::count = 0;
-
-template <class T>
-class Deleter
-{
- int state_;
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(const Deleter&);
- Deleter& operator=(const Deleter&);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&);
- Deleter& operator=(Deleter&);
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
-public:
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
- Deleter& operator=(Deleter&& r)
- {
- state_ = r.state_;
- r.state_ = 0;
- return *this;
- }
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);}
- Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;}
- Deleter& operator=(std::__rv<Deleter> r)
- {
- state_ = r->state_;
- r->state_ = 0;
- return *this;
- }
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-
- Deleter() : state_(5) {}
-
-#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U>&& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {d.set_state(0);}
-
-private:
- template <class U>
- Deleter(const Deleter<U>& d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0);
-#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
- template <class U>
- Deleter(Deleter<U> d,
- typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
- : state_(d.state()) {}
-#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
-public:
- int state() const {return state_;}
- void set_state(int i) {state_ = i;}
-
- void operator()(T* p) {delete p;}
-};
-
-int main()
-{
- {
- A* p = new A;
- assert(A::count == 1);
- std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>());
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp
deleted file mode 100644
index 421bec55f99c..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp
+++ /dev/null
@@ -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) ctor
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr(pointer, d) requires CopyConstructible deleter
-
-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;
- assert(A::count == 1);
- 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp
deleted file mode 100644
index bce79dbb1a97..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp
+++ /dev/null
@@ -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(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr<T, D&>(pointer, d) does not requires CopyConstructible deleter
-
-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;
- assert(A::count == 1);
- 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp
index 7cacd1fda9f3..ad64b5e4ea39 100644
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp
+++ b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp
@@ -7,49 +7,24 @@
//
//===----------------------------------------------------------------------===//
+// Without rvalue references it is impossible to detect when a rvalue deleter
+// is given.
+// XFAIL: c++98, c++03
+
// <memory>
// unique_ptr
-// Test unique_ptr(pointer) ctor
-
-#include <memory>
-#include <cassert>
-
// unique_ptr<T, const D&>(pointer, D()) should not compile
-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;}
+#include <memory>
- void operator()(A* p) const {delete p;}
+struct Deleter {
+ void operator()(int* p) const {delete p;}
};
int main()
{
- {
- A* p = new A;
- assert(A::count == 1);
- std::unique_ptr<A, const Deleter&> s(p, Deleter());
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
+ // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}}
+ std::unique_ptr<int, const Deleter&> s((int*)nullptr, Deleter()); // expected-note {{requested here}}
}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp
deleted file mode 100644
index a7750fcb9f0f..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp
+++ /dev/null
@@ -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) ctor
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr<T, const D&>(pointer, d) does not requires CopyConstructible deleter
-
-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;
- assert(A::count == 1);
- 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);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp
deleted file mode 100644
index 1a83258e1e41..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp
+++ /dev/null
@@ -1,66 +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
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr(pointer, deleter) should work with derived pointers
-
-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;
- assert(A::count == 1);
- assert(B::count == 1);
- std::unique_ptr<A, Deleter> s(p, Deleter());
- assert(s.get() == p);
- assert(s.get_deleter().state() == 5);
- }
- assert(A::count == 0);
- assert(B::count == 0);
-}
diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp
deleted file mode 100644
index ed68052cd3bb..000000000000
--- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp
+++ /dev/null
@@ -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(pointer, deleter) ctor
-
-#include <memory>
-#include <cassert>
-
-// unique_ptr(pointer, deleter) should work with function pointers
-// unique_ptr<void> should work
-
-bool my_free_called = false;
-
-void my_free(void*)
-{
- my_free_called = true;
-}
-
-int main()
-{
- {
- int i = 0;
- std::unique_ptr<void, void (*)(void*)> s(&i, my_free);
- assert(s.get() == &i);
- assert(s.get_deleter() == my_free);
- assert(!my_free_called);
- }
- assert(my_free_called);
-}
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
index b2e61faff5ed..f17485108b92 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp
index ab2c73e0c5f1..41aeb04a5feb 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp
index 97d3f69fb5c4..6a79a8ef60db 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// shared_ptr
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp
index 4220993a5fd1..c72847791778 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
index ead081645671..982313b07499 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// shared_ptr
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
index 041fe9a7853d..2e761d70bba0 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
index 5e09d9a7934c..c62fcd689320 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r);
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
index a9d8aff145a7..35a7d077b424 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+// XFAIL: libcpp-no-exceptions
// <memory>
// shared_ptr
diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp
index d091ae99fc27..bf1719c66ffa 100644
--- a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp
+++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp
@@ -30,9 +30,28 @@
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
+//
+// Added in C++17
+// template<> struct owner_less<void>
+// {
+// template<class T, class U>
+// bool operator()(shared_ptr<T> const&, shared_ptr<U> const&) const;
+// template<class T, class U>
+// bool operator()(shared_ptr<T> const&, weak_ptr<U> const&) const;
+// template<class T, class U>
+// bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const;
+// template<class T, class U>
+// bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const;
+//
+// typedef unspecified is_transparent;
+// };
#include <memory>
#include <cassert>
+#include <set>
+#include "test_macros.h"
+
+struct X {};
int main()
{
@@ -79,4 +98,25 @@ int main()
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
}
+#if TEST_STD_VER > 14
+ {
+ std::shared_ptr<int> sp1;
+ std::shared_ptr<void> sp2;
+ std::shared_ptr<long> sp3;
+ std::weak_ptr<int> wp1;
+
+ std::owner_less<> cmp;
+ cmp(sp1, sp2);
+ cmp(sp1, wp1);
+ cmp(sp1, sp3);
+ cmp(wp1, sp1);
+ cmp(wp1, wp1);
+ }
+ {
+ // test heterogeneous lookups
+ std::set<std::shared_ptr<X>, std::owner_less<>> s;
+ std::shared_ptr<void> vp;
+ s.find(vp);
+ }
+#endif
}