diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 21:36:01 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 21:36:01 +0000 |
commit | 5b08a8a43254ed30bd953e869b0fd9fc1e8b82d0 (patch) | |
tree | 9e474cfa73c5c4fc9ceafa2f9bb651c8492a3204 /libcxx/test/utilities/memory | |
parent | 0547ad38e334146599521e455d0d6f83a117a60e (diff) | |
download | bcm5719-llvm-5b08a8a43254ed30bd953e869b0fd9fc1e8b82d0.tar.gz bcm5719-llvm-5b08a8a43254ed30bd953e869b0fd9fc1e8b82d0.zip |
Wiped out some non-ascii characters that snuck into the copyright.
llvm-svn: 103516
Diffstat (limited to 'libcxx/test/utilities/memory')
305 files changed, 305 insertions, 305 deletions
diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp index 9f37e7fc55b..cee773472cc 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/allocs.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp index de8e3ffc03c..5cb097d94c6 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_copy.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp index 533c01c83eb..19b8ebdd39a 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/converting_move.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp index 02397ce0ec2..3fe3f4e3998 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/copy.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp index 770f68ad8da..49dafc198b8 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.cnstr/default.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp index c413df66807..87b8a43284d 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp index 711d6df9993..23bafc34c6f 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/allocate_size_hint.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp index f66da6be809..20fd0359d2a 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/construct.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp index 6a8b2da55f0..488d475d36d 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/deallocate.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp index d3af8b6bc87..c27b6dff414 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/destroy.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp index 5c66dde759c..06dd728329a 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/inner_allocator.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp index 033c6cd82db..903819625b4 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/max_size.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp index 94ffd877180..c4039f37466 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/outer_allocator.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp index aa731f97db1..6b3c4c37119 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.members/select_on_container_copy_construction.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp index fd5c7cffcc3..569c05da8eb 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/inner_allocator_type.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp index 2fb1ee1ce95..b067f14da75 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_copy_assignment.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp index b52e281d4c2..3c2aaf50aab 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_move_assignment.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp index 98773a4c9d8..8ef79907da3 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocator.adaptor.types/propagate_on_container_swap.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp index ebac49a667e..64457fd8d32 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp b/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp index ad19abbd046..fb0b9f69aa5 100644 --- a/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.tag/allocator_arg.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// struct allocator_arg_t { };
// const allocator_arg_t allocator_arg = allocator_arg_t();
#include <memory>
void test(std::allocator_arg_t) {}
int main()
{
test(std::allocator_arg);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// struct allocator_arg_t { };
// const allocator_arg_t allocator_arg = allocator_arg_t();
#include <memory>
void test(std::allocator_arg_t) {}
int main()
{
test(std::allocator_arg);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp index 2fb633b8b09..c797b1020bc 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static pointer allocate(allocator_type& a, size_type n);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 10);
return (value_type*)0xDEADBEEF;
}
};
int main()
{
A<int> a;
assert(std::allocator_traits<A<int> >::allocate(a, 10) == (int*)0xDEADBEEF);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static pointer allocate(allocator_type& a, size_type n);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 10);
return (value_type*)0xDEADBEEF;
}
};
int main()
{
A<int> a;
assert(std::allocator_traits<A<int> >::allocate(a, 10) == (int*)0xDEADBEEF);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp index 4613b608df6..9847c2a6053 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 10);
return (value_type*)0xDEADBEEF;
}
};
template <class T>
struct B
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 12);
return (value_type*)0xEEADBEEF;
}
value_type* allocate(std::size_t n, const void* p)
{
assert(n == 11);
assert(p == 0);
return (value_type*)0xFEADBEEF;
}
};
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
A<int> a;
assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF);
#endif
B<int> b;
assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 10);
return (value_type*)0xDEADBEEF;
}
};
template <class T>
struct B
{
typedef T value_type;
value_type* allocate(std::size_t n)
{
assert(n == 12);
return (value_type*)0xEEADBEEF;
}
value_type* allocate(std::size_t n, const void* p)
{
assert(n == 11);
assert(p == 0);
return (value_type*)0xFEADBEEF;
}
};
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
A<int> a;
assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF);
#endif
B<int> b;
assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp index 4a662550307..4dda58f8c7a 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class Ptr, class... Args>
// static void construct(allocator_type& a, Ptr p, Args&&... args);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
int b_construct = 0;
template <class T>
struct B
{
typedef T value_type;
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class U, class ...Args>
void construct(U* p, Args&& ...args)
{
++b_construct;
::new ((void*)p) U(std::forward<Args>(args)...);
}
#endif
};
struct A0
{
static int count;
A0() {++count;}
};
int A0::count = 0;
struct A1
{
static int count;
A1(char c)
{
assert(c == 'c');
++count;
}
};
int A1::count = 0;
struct A2
{
static int count;
A2(char c, int i)
{
assert(c == 'd');
assert(i == 5);
++count;
}
};
int A2::count = 0;
int main()
{
{
A0::count = 0;
A<int> a;
std::aligned_storage<sizeof(A0)>::type a0;
assert(A0::count == 0);
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
assert(A0::count == 1);
}
{
A1::count = 0;
A<int> a;
std::aligned_storage<sizeof(A1)>::type a1;
assert(A1::count == 0);
std::allocator_traits<A<int> >::construct(a, (A1*)&a1, 'c');
assert(A1::count == 1);
}
{
A2::count = 0;
A<int> a;
std::aligned_storage<sizeof(A2)>::type a2;
assert(A2::count == 0);
std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5);
assert(A2::count == 1);
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
A0::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A0)>::type a0;
assert(A0::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
assert(A0::count == 1);
assert(b_construct == 1);
}
{
A1::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A1)>::type a1;
assert(A1::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A1*)&a1, 'c');
assert(A1::count == 1);
assert(b_construct == 1);
}
{
A2::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A2)>::type a2;
assert(A2::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A2*)&a2, 'd', 5);
assert(A2::count == 1);
assert(b_construct == 1);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class Ptr, class... Args>
// static void construct(allocator_type& a, Ptr p, Args&&... args);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
int b_construct = 0;
template <class T>
struct B
{
typedef T value_type;
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class U, class ...Args>
void construct(U* p, Args&& ...args)
{
++b_construct;
::new ((void*)p) U(std::forward<Args>(args)...);
}
#endif
};
struct A0
{
static int count;
A0() {++count;}
};
int A0::count = 0;
struct A1
{
static int count;
A1(char c)
{
assert(c == 'c');
++count;
}
};
int A1::count = 0;
struct A2
{
static int count;
A2(char c, int i)
{
assert(c == 'd');
assert(i == 5);
++count;
}
};
int A2::count = 0;
int main()
{
{
A0::count = 0;
A<int> a;
std::aligned_storage<sizeof(A0)>::type a0;
assert(A0::count == 0);
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
assert(A0::count == 1);
}
{
A1::count = 0;
A<int> a;
std::aligned_storage<sizeof(A1)>::type a1;
assert(A1::count == 0);
std::allocator_traits<A<int> >::construct(a, (A1*)&a1, 'c');
assert(A1::count == 1);
}
{
A2::count = 0;
A<int> a;
std::aligned_storage<sizeof(A2)>::type a2;
assert(A2::count == 0);
std::allocator_traits<A<int> >::construct(a, (A2*)&a2, 'd', 5);
assert(A2::count == 1);
}
#ifndef _LIBCPP_HAS_NO_VARIADICS
{
A0::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A0)>::type a0;
assert(A0::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
assert(A0::count == 1);
assert(b_construct == 1);
}
{
A1::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A1)>::type a1;
assert(A1::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A1*)&a1, 'c');
assert(A1::count == 1);
assert(b_construct == 1);
}
{
A2::count = 0;
b_construct = 0;
B<int> b;
std::aligned_storage<sizeof(A2)>::type a2;
assert(A2::count == 0);
assert(b_construct == 0);
std::allocator_traits<B<int> >::construct(b, (A2*)&a2, 'd', 5);
assert(A2::count == 1);
assert(b_construct == 1);
}
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp index 4c648e11980..b4bd79a96e3 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static void deallocate(allocator_type& a, pointer p, size_type n);
// ...
// };
#include <memory>
#include <cassert>
int called = 0;
template <class T>
struct A
{
typedef T value_type;
void deallocate(value_type* p, std::size_t n)
{
assert(p == (value_type*)0xDEADBEEF);
assert(n == 10);
++called;
}
};
int main()
{
A<int> a;
std::allocator_traits<A<int> >::deallocate(a, (int*)0xDEADBEEF, 10);
assert(called == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static void deallocate(allocator_type& a, pointer p, size_type n);
// ...
// };
#include <memory>
#include <cassert>
int called = 0;
template <class T>
struct A
{
typedef T value_type;
void deallocate(value_type* p, std::size_t n)
{
assert(p == (value_type*)0xDEADBEEF);
assert(n == 10);
++called;
}
};
int main()
{
A<int> a;
std::allocator_traits<A<int> >::deallocate(a, (int*)0xDEADBEEF, 10);
assert(called == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp index 282c70886c6..7996ea42033 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class Ptr>
// static void destroy(allocator_type& a, Ptr p);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
int b_destroy = 0;
template <class T>
struct B
{
typedef T value_type;
template <class U>
void destroy(U* p)
{
++b_destroy;
p->~U();
}
};
struct A0
{
static int count;
~A0() {++count;}
};
int A0::count = 0;
int main()
{
{
A0::count = 0;
A<int> a;
std::aligned_storage<sizeof(A0)>::type a0;
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
assert(A0::count == 0);
std::allocator_traits<A<int> >::destroy(a, (A0*)&a0);
assert(A0::count == 1);
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
A0::count = 0;
b_destroy = 0;
B<int> b;
std::aligned_storage<sizeof(A0)>::type a0;
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
assert(A0::count == 0);
assert(b_destroy == 0);
std::allocator_traits<B<int> >::destroy(b, (A0*)&a0);
assert(A0::count == 1);
assert(b_destroy == 1);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class Ptr>
// static void destroy(allocator_type& a, Ptr p);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
int b_destroy = 0;
template <class T>
struct B
{
typedef T value_type;
template <class U>
void destroy(U* p)
{
++b_destroy;
p->~U();
}
};
struct A0
{
static int count;
~A0() {++count;}
};
int A0::count = 0;
int main()
{
{
A0::count = 0;
A<int> a;
std::aligned_storage<sizeof(A0)>::type a0;
std::allocator_traits<A<int> >::construct(a, (A0*)&a0);
assert(A0::count == 0);
std::allocator_traits<A<int> >::destroy(a, (A0*)&a0);
assert(A0::count == 1);
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
A0::count = 0;
b_destroy = 0;
B<int> b;
std::aligned_storage<sizeof(A0)>::type a0;
std::allocator_traits<B<int> >::construct(b, (A0*)&a0);
assert(A0::count == 0);
assert(b_destroy == 0);
std::allocator_traits<B<int> >::destroy(b, (A0*)&a0);
assert(A0::count == 1);
assert(b_destroy == 1);
}
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp index 1f85bd20da2..c021ea8c108 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static size_type max_size(const allocator_type& a);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
template <class T>
struct B
{
typedef T value_type;
size_t max_size() const
{
return 100;
}
};
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
A<int> a;
assert(std::allocator_traits<A<int> >::max_size(a) ==
std::numeric_limits<std::size_t>::max());
}
{
const A<int> a = {};
assert(std::allocator_traits<A<int> >::max_size(a) ==
std::numeric_limits<std::size_t>::max());
}
#endif
{
B<int> b;
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
{
const B<int> b = {};
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static size_type max_size(const allocator_type& a);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
};
template <class T>
struct B
{
typedef T value_type;
size_t max_size() const
{
return 100;
}
};
int main()
{
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
A<int> a;
assert(std::allocator_traits<A<int> >::max_size(a) ==
std::numeric_limits<std::size_t>::max());
}
{
const A<int> a = {};
assert(std::allocator_traits<A<int> >::max_size(a) ==
std::numeric_limits<std::size_t>::max());
}
#endif
{
B<int> b;
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
{
const B<int> b = {};
assert(std::allocator_traits<B<int> >::max_size(b) == 100);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp index 5a7df84f5a9..8fe2365bc10 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static allocator_type
// select_on_container_copy_construction(const allocator_type& a);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
int id;
explicit A(int i = 0) : id(i) {}
};
template <class T>
struct B
{
typedef T value_type;
int id;
explicit B(int i = 0) : id(i) {}
B select_on_container_copy_construction() const
{
return B(100);
}
};
int main()
{
{
A<int> a;
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
}
{
const A<int> a(0);
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
B<int> b;
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
}
{
const B<int> b(0);
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
}
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// static allocator_type
// select_on_container_copy_construction(const allocator_type& a);
// ...
// };
#include <memory>
#include <new>
#include <type_traits>
#include <cassert>
template <class T>
struct A
{
typedef T value_type;
int id;
explicit A(int i = 0) : id(i) {}
};
template <class T>
struct B
{
typedef T value_type;
int id;
explicit B(int i = 0) : id(i) {}
B select_on_container_copy_construction() const
{
return B(100);
}
};
int main()
{
{
A<int> a;
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
}
{
const A<int> a(0);
assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
}
#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
{
B<int> b;
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
}
{
const B<int> b(0);
assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
}
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp index cab032cb9a9..680583ac3a8 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::const_pointer
// | pointer_traits<pointer>::rebind<const value_type>
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<T> pointer;
typedef CPtr<const T> const_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::const_pointer
// | pointer_traits<pointer>::rebind<const value_type>
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<T> pointer;
typedef CPtr<const T> const_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::const_pointer, Ptr<const char> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::const_pointer, CPtr<const char> >::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp index 0fcc13cc2b8..afa0cf29d1e 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/const_void_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::const_void_pointer
// | pointer_traits<pointer>::rebind<const void>
// const_void_pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<const void> const_void_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::const_void_pointer, Ptr<const void> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::const_void_pointer, const void*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::const_void_pointer, CPtr<const void> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::const_void_pointer
// | pointer_traits<pointer>::rebind<const void>
// const_void_pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<const void> const_void_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::const_void_pointer, Ptr<const void> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::const_void_pointer, const void*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::const_void_pointer, CPtr<const void> >::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp index 20cc70f326a..7eab2fc5af5 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/difference_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::difference_type
// | ptrdiff_t difference_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef short difference_type;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::difference_type
// | ptrdiff_t difference_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef short difference_type;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp index bd2ddc418ca..6b479cee2a7 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::pointer | value_type* pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::pointer, Ptr<char> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::pointer, char*>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::pointer | value_type* pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::pointer, Ptr<char> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::pointer, char*>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp index 83be6e3583a..8340b582373 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_copy_assignment.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_copy_assignment
// | false_type propagate_on_container_copy_assignment;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_copy_assignment;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_copy_assignment, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_copy_assignment, std::false_type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_copy_assignment
// | false_type propagate_on_container_copy_assignment;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_copy_assignment;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_copy_assignment, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_copy_assignment, std::false_type>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp index 1c25b7fd9f2..827201625cd 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_move_assignment.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_move_assignment
// | false_type propagate_on_container_move_assignment;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_move_assignment;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_move_assignment, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_move_assignment, std::false_type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_move_assignment
// | false_type propagate_on_container_move_assignment;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_move_assignment;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_move_assignment, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_move_assignment, std::false_type>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp index 6abc1cd9e48..7c4d36afe0a 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/propagate_on_container_swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_swap
// | false_type propagate_on_container_swap;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_swap;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_swap, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_swap, std::false_type>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::propagate_on_container_swap
// | false_type propagate_on_container_swap;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef std::true_type propagate_on_container_swap;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::propagate_on_container_swap, std::true_type>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::propagate_on_container_swap, std::false_type>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp index c342835d147..443ce269725 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/rebind_alloc.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct ReboundA {};
template <class T>
struct A
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> other;};
};
template <class T, class U>
struct ReboundB {};
template <class T, class U>
struct B
{
typedef T value_type;
template <class V> struct rebind {typedef ReboundB<V, U> other;};
};
template <class T>
struct C
{
typedef T value_type;
};
template <class T, class U>
struct D
{
typedef T value_type;
};
template <class T>
struct E
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> otter;};
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
#else
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct ReboundA {};
template <class T>
struct A
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> other;};
};
template <class T, class U>
struct ReboundB {};
template <class T, class U>
struct B
{
typedef T value_type;
template <class V> struct rebind {typedef ReboundB<V, U> other;};
};
template <class T>
struct C
{
typedef T value_type;
};
template <class T, class U>
struct D
{
typedef T value_type;
};
template <class T>
struct E
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> otter;};
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>, ReboundA<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>, ReboundB<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>, C<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>, D<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>, E<double> >::value), "");
#else
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_alloc<double>::other, ReboundA<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_alloc<double>::other, ReboundB<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_alloc<double>::other, C<double> >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_alloc<double>::other, D<double, char> >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_alloc<double>::other, E<double> >::value), "");
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp index a0bb3d1fa1c..2eef5d435c7 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/size_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::size_type | size_t size_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef unsigned short size_type;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, std::size_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::size_type | size_t size_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
typedef unsigned short size_type;
};
template <class T>
struct B
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, std::size_t>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp index 4efa5ab8061..e08dd388b4f 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator.traits.types/void_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::void_pointer
// | pointer_traits<pointer>::rebind<void>
// void_pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<void> void_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc::void_pointer
// | pointer_traits<pointer>::rebind<void>
// void_pointer;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct Ptr {};
template <class T>
struct A
{
typedef T value_type;
typedef Ptr<T> pointer;
};
template <class T>
struct B
{
typedef T value_type;
};
template <class T>
struct CPtr {};
template <class T>
struct C
{
typedef T value_type;
typedef CPtr<void> void_pointer;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::void_pointer, Ptr<void> >::value), "");
static_assert((std::is_same<std::allocator_traits<B<char> >::void_pointer, void*>::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::void_pointer, CPtr<void> >::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp index 0c8a21e95c0..df2539a3a33 100644 --- a/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/allocator_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc allocator_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::allocator_type, A<char> >::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef Alloc allocator_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::allocator_type, A<char> >::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp index 9605a12faa6..6a4dd13df80 100644 --- a/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/rebind_traits.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct ReboundA {};
template <class T>
struct A
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> other;};
};
template <class T, class U>
struct ReboundB {};
template <class T, class U>
struct B
{
typedef T value_type;
template <class V> struct rebind {typedef ReboundB<V, U> other;};
};
template <class T>
struct C
{
typedef T value_type;
};
template <class T, class U>
struct D
{
typedef T value_type;
};
template <class T>
struct E
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> otter;};
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), "");
#else
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct ReboundA {};
template <class T>
struct A
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> other;};
};
template <class T, class U>
struct ReboundB {};
template <class T, class U>
struct B
{
typedef T value_type;
template <class V> struct rebind {typedef ReboundB<V, U> other;};
};
template <class T>
struct C
{
typedef T value_type;
};
template <class T, class U>
struct D
{
typedef T value_type;
};
template <class T>
struct E
{
typedef T value_type;
template <class U> struct rebind {typedef ReboundA<U> otter;};
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>, std::allocator_traits<ReboundA<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>, std::allocator_traits<ReboundB<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>, std::allocator_traits<C<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>, std::allocator_traits<D<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>, std::allocator_traits<E<double> > >::value), "");
#else
static_assert((std::is_same<std::allocator_traits<A<char> >::rebind_traits<double>::other, std::allocator_traits<ReboundA<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<B<int, char> >::rebind_traits<double>::other, std::allocator_traits<ReboundB<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<C<char> >::rebind_traits<double>::other, std::allocator_traits<C<double> > >::value), "");
static_assert((std::is_same<std::allocator_traits<D<int, char> >::rebind_traits<double>::other, std::allocator_traits<D<double, char> > >::value), "");
static_assert((std::is_same<std::allocator_traits<E<char> >::rebind_traits<double>::other, std::allocator_traits<E<double> > >::value), "");
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp b/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp index 9070ed2aa88..20015088451 100644 --- a/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.traits/value_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef typename Alloc::value_type value_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::value_type, char>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Alloc>
// struct allocator_traits
// {
// typedef typename Alloc::value_type value_type;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
typedef T value_type;
};
int main()
{
static_assert((std::is_same<std::allocator_traits<A<char> >::value_type, char>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.construction/tested_elsewhere.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp index 12b140604de..23aa45e31bb 100644 --- a/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.uses/allocator.uses.trait/uses_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T, class Alloc> struct uses_allocator;
#include <memory>
#include <vector>
struct A
{
};
struct B
{
typedef int allocator_type;
};
int main()
{
static_assert((!std::uses_allocator<int, std::allocator<int> >::value), "");
static_assert(( std::uses_allocator<std::vector<int>, std::allocator<int> >::value), "");
static_assert((!std::uses_allocator<A, std::allocator<int> >::value), "");
static_assert((!std::uses_allocator<B, std::allocator<int> >::value), "");
static_assert(( std::uses_allocator<B, double>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T, class Alloc> struct uses_allocator;
#include <memory>
#include <vector>
struct A
{
};
struct B
{
typedef int allocator_type;
};
int main()
{
static_assert((!std::uses_allocator<int, std::allocator<int> >::value), "");
static_assert(( std::uses_allocator<std::vector<int>, std::allocator<int> >::value), "");
static_assert((!std::uses_allocator<A, std::allocator<int> >::value), "");
static_assert((!std::uses_allocator<B, std::allocator<int> >::value), "");
static_assert(( std::uses_allocator<B, double>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.uses/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp index 4c1f61cab18..27846cf94e6 100644 --- a/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/c.malloc/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <cstdlib> and <cstring> are already tested elsewhere
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <cstdlib> and <cstring> are already tested elsewhere
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp index fd462640f83..49d39da4034 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.globals/eq.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// template <class T1, class T2>
// bool
// operator==(const allocator<T1>&, const allocator<T2>&) throw();
//
// template <class T1, class T2>
// bool
// operator!=(const allocator<T1>&, const allocator<T2>&) throw();
#include <memory>
#include <cassert>
int main()
{
std::allocator<int> a1;
std::allocator<int> a2;
assert(a1 == a2);
assert(!(a1 != a2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// template <class T1, class T2>
// bool
// operator==(const allocator<T1>&, const allocator<T2>&) throw();
//
// template <class T1, class T2>
// bool
// operator!=(const allocator<T1>&, const allocator<T2>&) throw();
#include <memory>
#include <cassert>
int main()
{
std::allocator<int> a1;
std::allocator<int> a2;
assert(a1 == a2);
assert(!(a1 != a2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp index a434c7e5b56..c14607f6cfb 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/address.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// pointer address(reference x) const;
// const_pointer address(const_reference x) const;
#include <memory>
#include <cassert>
template <class T>
void test_address()
{
T* tp = new T();
const T* ctp = tp;
const std::allocator<T> a;
assert(a.address(*tp) == tp);
assert(a.address(*ctp) == tp);
delete tp;
}
struct A
{
void operator&() const {}
};
int main()
{
test_address<int>();
test_address<A>();
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// pointer address(reference x) const;
// const_pointer address(const_reference x) const;
#include <memory>
#include <cassert>
template <class T>
void test_address()
{
T* tp = new T();
const T* ctp = tp;
const std::allocator<T> a;
assert(a.address(*tp) == tp);
assert(a.address(*ctp) == tp);
delete tp;
}
struct A
{
void operator&() const {}
};
int main()
{
test_address<int>();
test_address<A>();
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp index 9856770a5f0..161d3835b3f 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/allocate.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
assert(s == 3 * sizeof(int));
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
int A_constructed = 0;
struct A
{
int data;
A() {++A_constructed;}
A(const A&) {++A_constructed;}
~A() {--A_constructed;}
};
int main()
{
std::allocator<A> a;
assert(new_called == 0);
assert(A_constructed == 0);
A* ap = a.allocate(3);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(A_constructed == 0);
A* ap2 = a.allocate(3, (const void*)5);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap2, 3);
assert(new_called == 0);
assert(A_constructed == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// pointer allocate(size_type n, allocator<void>::const_pointer hint=0);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
assert(s == 3 * sizeof(int));
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
int A_constructed = 0;
struct A
{
int data;
A() {++A_constructed;}
A(const A&) {++A_constructed;}
~A() {--A_constructed;}
};
int main()
{
std::allocator<A> a;
assert(new_called == 0);
assert(A_constructed == 0);
A* ap = a.allocate(3);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(A_constructed == 0);
A* ap2 = a.allocate(3, (const void*)5);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap2, 3);
assert(new_called == 0);
assert(A_constructed == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp index 6718d10b1f6..bf6e20ab1f6 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/construct.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// template <class... Args> void construct(pointer p, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
assert(s == 3 * sizeof(int));
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
int A_constructed = 0;
struct A
{
int data;
A() {++A_constructed;}
A(const A&) {++A_constructed;}
explicit A(int) {++A_constructed;}
A(int, int*) {++A_constructed;}
~A() {--A_constructed;}
};
int move_only_constructed = 0;
class move_only
{
int data;
#ifdef _LIBCPP_MOVE
move_only(const move_only&);
move_only& operator=(const move_only&);
#else
move_only(move_only&);
move_only& operator=(move_only&);
#endif
public:
#ifdef _LIBCPP_MOVE
move_only(move_only&&) {++move_only_constructed;}
move_only& operator=(move_only&&) {}
#else
operator std::__rv<move_only> () {return std::__rv<move_only>(*this);}
move_only(std::__rv<move_only>) {++move_only_constructed;}
#endif
move_only() {++move_only_constructed;}
~move_only() {--move_only_constructed;}
};
int main()
{
{
std::allocator<A> a;
assert(new_called == 0);
assert(A_constructed == 0);
A* ap = a.allocate(3);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, A());
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, 5);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, 5, (int*)0);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(A_constructed == 0);
}
{
std::allocator<move_only> a;
assert(new_called == 0);
assert(move_only_constructed == 0);
move_only* ap = a.allocate(3);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.construct(ap);
assert(new_called == 1);
assert(move_only_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.construct(ap, move_only());
assert(new_called == 1);
assert(move_only_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(move_only_constructed == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// template <class... Args> void construct(pointer p, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_called = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_called;
assert(s == 3 * sizeof(int));
return std::malloc(s);
}
void operator delete(void* p) throw()
{
--new_called;
std::free(p);
}
int A_constructed = 0;
struct A
{
int data;
A() {++A_constructed;}
A(const A&) {++A_constructed;}
explicit A(int) {++A_constructed;}
A(int, int*) {++A_constructed;}
~A() {--A_constructed;}
};
int move_only_constructed = 0;
class move_only
{
int data;
#ifdef _LIBCPP_MOVE
move_only(const move_only&);
move_only& operator=(const move_only&);
#else
move_only(move_only&);
move_only& operator=(move_only&);
#endif
public:
#ifdef _LIBCPP_MOVE
move_only(move_only&&) {++move_only_constructed;}
move_only& operator=(move_only&&) {}
#else
operator std::__rv<move_only> () {return std::__rv<move_only>(*this);}
move_only(std::__rv<move_only>) {++move_only_constructed;}
#endif
move_only() {++move_only_constructed;}
~move_only() {--move_only_constructed;}
};
int main()
{
{
std::allocator<A> a;
assert(new_called == 0);
assert(A_constructed == 0);
A* ap = a.allocate(3);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, A());
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, 5);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.construct(ap, 5, (int*)0);
assert(new_called == 1);
assert(A_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(A_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(A_constructed == 0);
}
{
std::allocator<move_only> a;
assert(new_called == 0);
assert(move_only_constructed == 0);
move_only* ap = a.allocate(3);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.construct(ap);
assert(new_called == 1);
assert(move_only_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.construct(ap, move_only());
assert(new_called == 1);
assert(move_only_constructed == 1);
a.destroy(ap);
assert(new_called == 1);
assert(move_only_constructed == 0);
a.deallocate(ap, 3);
assert(new_called == 0);
assert(move_only_constructed == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp index b6736ec3530..eb596f42f2c 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator.members/max_size.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// size_type max_size() const throw();
#include <memory>
#include <limits>
#include <cstddef>
#include <cassert>
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());
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// allocator:
// size_type max_size() const throw();
#include <memory>
#include <limits>
#include <cstddef>
#include <cassert>
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());
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp index e3ac76514a7..7ee46ff06fc 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator_types.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// check nested types:
// template <class T>
// class allocator
// {
// public:
// typedef size_t size_type;
// typedef ptrdiff_t difference_type;
// typedef T* pointer;
// typedef const T* const_pointer;
// typedef typename add_lvalue_reference<T>::type reference;
// typedef typename add_lvalue_reference<const T>::type const_reference;
// typedef T value_type;
//
// template <class U> struct rebind {typedef allocator<U> other;};
// ...
// };
#include <memory>
#include <type_traits>
#include <cstddef>
int main()
{
static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), "");
static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), "");
static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::allocator<char>::value_type, char>::value), "");
static_assert((std::is_same<std::allocator<char>::reference, char&>::value), "");
static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), "");
static_assert((std::is_same<std::allocator<char>::rebind<int>::other,
std::allocator<int> >::value), "");
std::allocator<char> a;
std::allocator<char> a2 = a;
a2 = a;
std::allocator<int> a3 = a2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// check nested types:
// template <class T>
// class allocator
// {
// public:
// typedef size_t size_type;
// typedef ptrdiff_t difference_type;
// typedef T* pointer;
// typedef const T* const_pointer;
// typedef typename add_lvalue_reference<T>::type reference;
// typedef typename add_lvalue_reference<const T>::type const_reference;
// typedef T value_type;
//
// template <class U> struct rebind {typedef allocator<U> other;};
// ...
// };
#include <memory>
#include <type_traits>
#include <cstddef>
int main()
{
static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), "");
static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), "");
static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::allocator<char>::value_type, char>::value), "");
static_assert((std::is_same<std::allocator<char>::reference, char&>::value), "");
static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), "");
static_assert((std::is_same<std::allocator<char>::rebind<int>::other,
std::allocator<int> >::value), "");
std::allocator<char> a;
std::allocator<char> a2 = a;
a2 = a;
std::allocator<int> a3 = a2;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp b/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp index 9d948fbb82d..79b0690f3a9 100644 --- a/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp +++ b/libcxx/test/utilities/memory/default.allocator/allocator_void.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <>
// class allocator<void>
// {
// public:
// typedef void* pointer;
// typedef const void* const_pointer;
// typedef void value_type;
//
// template <class _Up> struct rebind {typedef allocator<_Up> other;};
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
static_assert((std::is_same<std::allocator<void>::rebind<int>::other,
std::allocator<int> >::value), "");
std::allocator<void> a;
std::allocator<void> a2 = a;
a2 = a;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <>
// class allocator<void>
// {
// public:
// typedef void* pointer;
// typedef const void* const_pointer;
// typedef void value_type;
//
// template <class _Up> struct rebind {typedef allocator<_Up> other;};
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::allocator<void>::pointer, void*>::value), "");
static_assert((std::is_same<std::allocator<void>::const_pointer, const void*>::value), "");
static_assert((std::is_same<std::allocator<void>::value_type, void>::value), "");
static_assert((std::is_same<std::allocator<void>::rebind<int>::other,
std::allocator<int> >::value), "");
std::allocator<void> a;
std::allocator<void> a2 = a;
a2 = a;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp index 23a5b47d6ac..f28e42f28bd 100644 --- a/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/difference_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// typedef ptrdiff_t difference_type;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::pointer_traits<double*>::difference_type, std::ptrdiff_t>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// typedef ptrdiff_t difference_type;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::pointer_traits<double*>::difference_type, std::ptrdiff_t>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp index e329842e917..e944dc8ff35 100644 --- a/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/element_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// typedef T element_type;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::pointer_traits<const short*>::element_type, const short>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// typedef T element_type;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
static_assert((std::is_same<std::pointer_traits<const short*>::element_type, const short>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp index 898a54a64e3..34fa69454ab 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef Ptr pointer;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef short element_type;
typedef char difference_type;
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::pointer, A>::value), "");
static_assert((std::is_same<std::pointer_traits<int*>::pointer, int*>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef Ptr pointer;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef short element_type;
typedef char difference_type;
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::pointer, A>::value), "");
static_assert((std::is_same<std::pointer_traits<int*>::pointer, int*>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp index c43fbf6eb21..8ed66297f31 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.functions/pointer_to.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// static pointer pointer_to(<details>);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
private:
struct nat {};
public:
typedef T element_type;
element_type* t_;
A(element_type* t) : t_(t) {}
static A pointer_to(typename std::conditional<std::is_void<element_type>::value,
nat, element_type>::type& et)
{return A(&et);}
};
int main()
{
{
int i = 0;
A<int> a = std::pointer_traits<A<int> >::pointer_to(i);
assert(a.t_ = &i);
}
{
(std::pointer_traits<A<void> >::element_type)0;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// static pointer pointer_to(<details>);
// ...
// };
#include <memory>
#include <cassert>
template <class T>
struct A
{
private:
struct nat {};
public:
typedef T element_type;
element_type* t_;
A(element_type* t) : t_(t) {}
static A pointer_to(typename std::conditional<std::is_void<element_type>::value,
nat, element_type>::type& et)
{return A(&et);}
};
int main()
{
{
int i = 0;
A<int> a = std::pointer_traits<A<int> >::pointer_to(i);
assert(a.t_ = &i);
}
{
(std::pointer_traits<A<void> >::element_type)0;
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp index baa3538c366..e2a78d1ddfa 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/difference_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef <details> difference_type;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef short element_type;
typedef char difference_type;
};
struct B
{
typedef short element_type;
};
template <class T>
struct C {};
template <class T>
struct D
{
typedef char difference_type;
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::difference_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<B>::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::pointer_traits<C<double> >::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::pointer_traits<D<int> >::difference_type, char>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef <details> difference_type;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef short element_type;
typedef char difference_type;
};
struct B
{
typedef short element_type;
};
template <class T>
struct C {};
template <class T>
struct D
{
typedef char difference_type;
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::difference_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<B>::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::pointer_traits<C<double> >::difference_type, std::ptrdiff_t>::value), "");
static_assert((std::is_same<std::pointer_traits<D<int> >::difference_type, char>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp index defdb996243..ca464370c6e 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/element_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef <details> element_type;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef char element_type;
};
template <class T>
struct B
{
typedef char element_type;
};
template <class T>
struct C
{
};
template <class T, class U>
struct D
{
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::element_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::element_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<C<int> >::element_type, int>::value), "");
static_assert((std::is_same<std::pointer_traits<D<double, int> >::element_type, double>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// typedef <details> element_type;
// ...
// };
#include <memory>
#include <type_traits>
struct A
{
typedef char element_type;
};
template <class T>
struct B
{
typedef char element_type;
};
template <class T>
struct C
{
};
template <class T, class U>
struct D
{
};
int main()
{
static_assert((std::is_same<std::pointer_traits<A>::element_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::element_type, char>::value), "");
static_assert((std::is_same<std::pointer_traits<C<int> >::element_type, int>::value), "");
static_assert((std::is_same<std::pointer_traits<D<double, int> >::element_type, double>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp index 19178c53330..ca8a3a27629 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.traits.types/rebind.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// template <class U> using rebind = <details>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
};
template <class T> struct B1 {};
template <class T>
struct B
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class U> using rebind = B1<U>;
#else
template <class U> struct rebind {typedef B1<U> other;};
#endif
};
template <class T, class U>
struct C
{
};
template <class T, class U> struct D1 {};
template <class T, class U>
struct D
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class V> using rebind = D1<V, U>;
#else
template <class V> struct rebind {typedef D1<V, U> other;};
#endif
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>, A<double*> >::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>, B1<double> >::value), "");
static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>, C<double, int> >::value), "");
static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>, D1<double, int> >::value), "");
#else
static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>::other, A<double*> >::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>::other, B1<double> >::value), "");
static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>::other, C<double, int> >::value), "");
static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>::other, D1<double, int> >::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Ptr>
// struct pointer_traits
// {
// template <class U> using rebind = <details>;
// ...
// };
#include <memory>
#include <type_traits>
template <class T>
struct A
{
};
template <class T> struct B1 {};
template <class T>
struct B
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class U> using rebind = B1<U>;
#else
template <class U> struct rebind {typedef B1<U> other;};
#endif
};
template <class T, class U>
struct C
{
};
template <class T, class U> struct D1 {};
template <class T, class U>
struct D
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
template <class V> using rebind = D1<V, U>;
#else
template <class V> struct rebind {typedef D1<V, U> other;};
#endif
};
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>, A<double*> >::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>, B1<double> >::value), "");
static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>, C<double, int> >::value), "");
static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>, D1<double, int> >::value), "");
#else
static_assert((std::is_same<std::pointer_traits<A<int*> >::rebind<double*>::other, A<double*> >::value), "");
static_assert((std::is_same<std::pointer_traits<B<int> >::rebind<double>::other, B1<double> >::value), "");
static_assert((std::is_same<std::pointer_traits<C<char, int> >::rebind<double>::other, C<double, int> >::value), "");
static_assert((std::is_same<std::pointer_traits<D<char, int> >::rebind<double>::other, D1<double, int> >::value), "");
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp index 28dc3f2c33a..42fd9300b7d 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer_to.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// static pointer pointer_to(<details>);
// ...
// };
#include <memory>
#include <cassert>
int main()
{
{
int i = 0;
int* a = std::pointer_traits<int*>::pointer_to(i);
assert(a = &i);
}
{
(std::pointer_traits<void*>::element_type)0;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// static pointer pointer_to(<details>);
// ...
// };
#include <memory>
#include <cassert>
int main()
{
{
int i = 0;
int* a = std::pointer_traits<int*>::pointer_to(i);
assert(a = &i);
}
{
(std::pointer_traits<void*>::element_type)0;
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp index c60cbd4ff59..f63c03521a0 100644 --- a/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// template <class U> using rebind = U*;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>, double*>::value), "");
#else
static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>::other, double*>::value), "");
#endif
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// struct pointer_traits<T*>
// {
// template <class U> using rebind = U*;
// ...
// };
#include <memory>
#include <type_traits>
int main()
{
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>, double*>::value), "");
#else
static_assert((std::is_same<std::pointer_traits<int*>::rebind<double>::other, double*>::value), "");
#endif
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/ptr.align/align.pass.cpp b/libcxx/test/utilities/memory/ptr.align/align.pass.cpp index 85558dafe1e..5c847c15b97 100644 --- a/libcxx/test/utilities/memory/ptr.align/align.pass.cpp +++ b/libcxx/test/utilities/memory/ptr.align/align.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp index 3eb092820e9..c4b14d3160c 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/specialized.addressof/addressof.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <ObjectType T> T* addressof(T& r);
#include <memory>
#include <cassert>
struct A
{
void operator&() const {}
};
int main()
{
int i;
double d;
assert(std::addressof(i) == &i);
assert(std::addressof(d) == &d);
A* tp = new A;
const A* ctp = tp;
assert(std::addressof(*tp) == tp);
assert(std::addressof(*ctp) == tp);
delete tp;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <ObjectType T> T* addressof(T& r);
#include <memory>
#include <cassert>
struct A
{
void operator&() const {}
};
int main()
{
int i;
double d;
assert(std::addressof(i) == &i);
assert(std::addressof(d) == &d);
A* tp = new A;
const A* ctp = tp;
assert(std::addressof(*tp) == tp);
assert(std::addressof(*ctp) == tp);
delete tp;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp index dd94c51e71d..d592386557a 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class InputIterator, class ForwardIterator>
// ForwardIterator
// uninitialized_copy(InputIterator first, InputIterator last,
// ForwardIterator result);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
try
{
std::uninitialized_copy(b, b+N, bp);
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_copy(b, b+2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class InputIterator, class ForwardIterator>
// ForwardIterator
// uninitialized_copy(InputIterator first, InputIterator last,
// ForwardIterator result);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
try
{
std::uninitialized_copy(b, b+N, bp);
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_copy(b, b+2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp index 0bc3e25061f..0971c61b402 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.copy/uninitialized_copy_n.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class InputIterator, class Size, class ForwardIterator>
// ForwardIterator
// uninitialized_copy_n(InputIterator first, Size n,
// ForwardIterator result);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
try
{
std::uninitialized_copy_n(b, 5, bp);
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_copy_n(b, 2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class InputIterator, class Size, class ForwardIterator>
// ForwardIterator
// uninitialized_copy_n(InputIterator first, Size n,
// ForwardIterator result);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
B b[N];
try
{
std::uninitialized_copy_n(b, 5, bp);
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_copy_n(b, 2, bp);
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp index 03578593b07..15518e00f71 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill.n/uninitialized_fill_n.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class ForwardIterator, class Size, class T>
// void
// uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
try
{
std::uninitialized_fill_n(bp, 5, B());
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_fill_n(bp, 2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class ForwardIterator, class Size, class T>
// void
// uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
try
{
std::uninitialized_fill_n(bp, 5, B());
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_fill_n(bp, 2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp index 843eece33e4..eaaa6ca8188 100644 --- a/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp +++ b/libcxx/test/utilities/memory/specialized.algorithms/uninitialized.fill/uninitialized_fill.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class ForwardIterator, class T>
// void
// uninitialized_fill(ForwardIterator first, ForwardIterator last,
// const T& x);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
try
{
std::uninitialized_fill(bp, bp+N, B());
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_fill(bp, bp+2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class ForwardIterator, class T>
// void
// uninitialized_fill(ForwardIterator first, ForwardIterator last,
// const T& x);
#include <memory>
#include <cassert>
struct B
{
static int count_;
int data_;
explicit B() : data_(1) {}
B(const B& b) {if (++count_ == 3) throw 1; data_ = b.data_;}
~B() {data_ = 0;}
};
int B::count_ = 0;
int main()
{
const int N = 5;
char pool[sizeof(B)*N] = {0};
B* bp = (B*)pool;
try
{
std::uninitialized_fill(bp, bp+N, B());
assert(false);
}
catch (...)
{
for (int i = 0; i < N; ++i)
assert(bp[i].data_ == 0);
}
B::count_ = 0;
std::uninitialized_fill(bp, bp+2, B());
for (int i = 0; i < 2; ++i)
assert(bp[i].data_ == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp b/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp index 8e3f14509f2..3f356890915 100644 --- a/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp +++ b/libcxx/test/utilities/memory/storage.iterator/raw_storag_iterator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// raw_storage_iterator
#include <memory>
#include <type_traits>
#include <cassert>
int A_constructed = 0;
struct A
{
int data_;
public:
explicit A(int i) : data_(i) {++A_constructed;}
A(const A& a) : data_(a.data_) {++A_constructed;}
~A() {--A_constructed; data_ = 0;}
bool operator==(int i) const {return data_ == i;}
};
int main()
{
typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
Storage;
Storage buffer;
std::raw_storage_iterator<A*, A> it((A*)&buffer);
assert(A_constructed == 0);
for (int i = 0; i < 3; ++i)
{
*it++ = A(i+1);
A* ap = (A*)&buffer + i;
assert(*ap == i+1);
assert(A_constructed == i+1);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// raw_storage_iterator
#include <memory>
#include <type_traits>
#include <cassert>
int A_constructed = 0;
struct A
{
int data_;
public:
explicit A(int i) : data_(i) {++A_constructed;}
A(const A& a) : data_(a.data_) {++A_constructed;}
~A() {--A_constructed; data_ = 0;}
bool operator==(int i) const {return data_ == i;}
};
int main()
{
typedef std::aligned_storage<3*sizeof(A), std::alignment_of<A>::value>::type
Storage;
Storage buffer;
std::raw_storage_iterator<A*, A> it((A*)&buffer);
assert(A_constructed == 0);
for (int i = 0; i < 3; ++i)
{
*it++ = A(i+1);
A* ap = (A*)&buffer + i;
assert(*ap == i+1);
assert(A_constructed == i+1);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp b/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp index 40beea8ff42..129bae834b9 100644 --- a/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp +++ b/libcxx/test/utilities/memory/temporary.buffer/temporary_buffer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// pair<T*, ptrdiff_t>
// get_temporary_buffer(ptrdiff_t n);
//
// template <class T>
// void
// return_temporary_buffer(T* p);
#include <memory>
#include <cassert>
int main()
{
std::pair<int*, std::ptrdiff_t> ip = std::get_temporary_buffer<int>(5);
assert(ip.first);
assert(ip.second == 5);
std::return_temporary_buffer(ip.first);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T>
// pair<T*, ptrdiff_t>
// get_temporary_buffer(ptrdiff_t n);
//
// template <class T>
// void
// return_temporary_buffer(T* p);
#include <memory>
#include <cassert>
int main()
{
std::pair<int*, std::ptrdiff_t> ip = std::get_temporary_buffer<int>(5);
assert(ip.first);
assert(ip.second == 5);
std::return_temporary_buffer(ip.first);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/deleter.h b/libcxx/test/utilities/memory/unique.ptr/deleter.h index 6c5c9a4b1f4..df8b894e1e2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/deleter.h +++ b/libcxx/test/utilities/memory/unique.ptr/deleter.h @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(0) {}
explicit Deleter(int s) : state_(s) {}
~Deleter() {assert(state_ >= 0); state_ = -1;}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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[]>
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
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;}
};
template <class T>
void
swap(Deleter<T>& x, Deleter<T>& y)
{
Deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
template <class T>
class CDeleter
{
int state_;
public:
CDeleter() : state_(0) {}
explicit CDeleter(int s) : state_(s) {}
~CDeleter() {assert(state_ >= 0); state_ = -1;}
template <class U>
CDeleter(const CDeleter<U>& d)
: state_(d.state()) {}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
template <class T>
class CDeleter<T[]>
{
int state_;
public:
CDeleter() : state_(0) {}
explicit CDeleter(int s) : state_(s) {}
~CDeleter() {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>
void
swap(CDeleter<T>& x, CDeleter<T>& y)
{
CDeleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(0) {}
explicit Deleter(int s) : state_(s) {}
~Deleter() {assert(state_ >= 0); state_ = -1;}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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[]>
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
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;}
};
template <class T>
void
swap(Deleter<T>& x, Deleter<T>& y)
{
Deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
template <class T>
class CDeleter
{
int state_;
public:
CDeleter() : state_(0) {}
explicit CDeleter(int s) : state_(s) {}
~CDeleter() {assert(state_ >= 0); state_ = -1;}
template <class U>
CDeleter(const CDeleter<U>& d)
: state_(d.state()) {}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
template <class T>
class CDeleter<T[]>
{
int state_;
public:
CDeleter() : state_(0) {}
explicit CDeleter(int s) : state_(s) {}
~CDeleter() {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>
void
swap(CDeleter<T>& x, CDeleter<T>& y)
{
CDeleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp index 4fe3a66cbdb..c96b5b980ba 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
std::default_delete<B> d2;
std::default_delete<A> d1 = d2;
A* p = new B;
assert(A::count == 1);
assert(B::count == 1);
d1(p);
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
std::default_delete<B> d2;
std::default_delete<A> d1 = d2;
A* p = new B;
assert(A::count == 1);
assert(B::count == 1);
d1(p);
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp index 26bd82a5320..5f033a36893 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
std::default_delete<A> d;
A* p = new A;
assert(A::count == 1);
d(p);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
std::default_delete<A> d;
A* p = new A;
assert(A::count == 1);
d(p);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp index f259c7cb568..a1662526860 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete's operator() requires a complete type
#include <memory>
#include <cassert>
struct A;
int main()
{
std::default_delete<A> d;
A* p = 0;
d(p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete's operator() requires a complete type
#include <memory>
#include <cassert>
struct A;
int main()
{
std::default_delete<A> d;
A* p = 0;
d(p);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp index 7084e3403a0..e1248de8712 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]> does not have a working converting constructor
#include <memory>
#include <cassert>
struct A
{
};
struct B
: public A
{
};
int main()
{
std::default_delete<B[]> d2;
std::default_delete<A[]> d1 = d2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]> does not have a working converting constructor
#include <memory>
#include <cassert>
struct A
{
};
struct B
: public A
{
};
int main()
{
std::default_delete<B[]> d2;
std::default_delete<A[]> d1 = d2;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp index e83346e288b..1b41e961912 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]> has a working default constructor
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
std::default_delete<A[]> d;
A* p = new A[3];
assert(A::count == 3);
d(p);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]> has a working default constructor
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
std::default_delete<A[]> d;
A* p = new A[3];
assert(A::count == 3);
d(p);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp index 120306fb877..6fcb94c5637 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]>'s operator() requires a complete type
#include <memory>
#include <cassert>
struct A;
int main()
{
std::default_delete<A[]> d;
A* p = 0;
d(p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// default_delete
// Test that default_delete<T[]>'s operator() requires a complete type
#include <memory>
#include <cassert>
struct A;
int main()
{
std::default_delete<A[]> d;
A* p = 0;
d(p);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp index cd29056f142..6360686f745 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
int main()
{
{
std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
int main()
{
{
std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp index 2524f3b3311..dfd6a7136ae 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
// test move assignment. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s1(new A[3]);
A* p = s1.get();
assert(A::count == 3);
std::unique_ptr<A[]> s2(new A[2]);
assert(A::count == 5);
s2 = std::move(s1);
assert(A::count == 3);
assert(s2.get() == p);
assert(s1.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5));
A* p = s1.get();
assert(A::count == 4);
std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]);
assert(A::count == 9);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 4);
assert(s2.get_deleter().state() == 5);
assert(s1.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter<A[]> d1(5);
std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1);
A* p = s1.get();
assert(A::count == 6);
CDeleter<A[]> d2(6);
std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2);
assert(A::count == 9);
s2 = std::move(s1);
assert(A::count == 6);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(d1.state() == 5);
assert(d2.state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
// test move assignment. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s1(new A[3]);
A* p = s1.get();
assert(A::count == 3);
std::unique_ptr<A[]> s2(new A[2]);
assert(A::count == 5);
s2 = std::move(s1);
assert(A::count == 3);
assert(s2.get() == p);
assert(s1.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A[], Deleter<A[]> > s1(new A[4], Deleter<A[]>(5));
A* p = s1.get();
assert(A::count == 4);
std::unique_ptr<A[], Deleter<A[]> > s2(new A[5]);
assert(A::count == 9);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 4);
assert(s2.get_deleter().state() == 5);
assert(s1.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter<A[]> d1(5);
std::unique_ptr<A[], CDeleter<A[]>&> s1(new A[6], d1);
A* p = s1.get();
assert(A::count == 6);
CDeleter<A[]> d2(6);
std::unique_ptr<A[], CDeleter<A[]>&> s2(new A[3], d2);
assert(A::count == 9);
s2 = std::move(s1);
assert(A::count == 6);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(d1.state() == 5);
assert(d2.state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp index 030a53c4bfd..5e1e5f81483 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A[]> s(new A[3]);
std::unique_ptr<A[]> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A[]> s(new A[3]);
std::unique_ptr<A[]> s2;
s2 = s;
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp index 2c2fdd96e82..594704f2a83 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp index dc0b46eedf1..89267738d13 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp index 0d7cfe8bfcb..45196b630fb 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp index 7a741375f64..9831ab2283b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#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;
int main()
{
{
boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#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;
int main()
{
{
boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp index 84faeb3ed31..67e5f36435d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#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;
int main()
{
{
Deleter<B> db(5);
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#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;
int main()
{
{
Deleter<B> db(5);
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp index 81d7e498d1d..64aff20ef4a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const boost::unique_ptr<B[]> s(new B);
A* p = s.get();
boost::unique_ptr<A[]> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const boost::unique_ptr<B[]> s(new B);
A* p = s.get();
boost::unique_ptr<A[]> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp index 704314663f6..96ef756e099 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
const boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
const boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp index 7ade7c8200e..5ecec761ae4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
Deleter<B> db(5);
const boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
Deleter<B> db(5);
const boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp index cf5c6d11ac6..5e959134c66 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
boost::unique_ptr<B[]> s(new B);
A* p = s.get();
boost::unique_ptr<A[]> s2(new A);
assert(A::count == 2);
s2 = boost::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
boost::unique_ptr<B[]> s(new B);
A* p = s.get();
boost::unique_ptr<A[]> s2(new A);
assert(A::count == 2);
s2 = boost::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp index 2337053d66d..e408aae3f9d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#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;
int main()
{
{
boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = (boost::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#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;
int main()
{
{
boost::unique_ptr<B[], Deleter<B> > s(new B);
A* p = s.get();
boost::unique_ptr<A[], Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = (boost::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp index a21e545aa87..a1328d62a6f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// test converting move assignment with reference deleters
#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;
int main()
{
{
Deleter<B> db(5);
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = boost::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// test converting move assignment with reference deleters
#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;
int main()
{
{
Deleter<B> db(5);
boost::unique_ptr<B[], Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
boost::unique_ptr<A[], Deleter<A>&> s2(new A, da);
s2 = boost::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp index be3292a41c4..da5d287e4c7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = 0;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = 0;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp index d1331522458..31248d50912 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// The deleter is not called if get() == 0
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(0) {}
int state() const {return state_;}
void operator()(void*) {++state_;}
};
int main()
{
Deleter d;
assert(d.state() == 0);
{
std::unique_ptr<int[], Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
}
assert(d.state() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// The deleter is not called if get() == 0
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(0) {}
int state() const {return state_;}
void operator()(void*) {++state_;}
};
int main()
{
Deleter d;
assert(d.state() == 0);
{
std::unique_ptr<int[], Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
}
assert(d.state() == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp index a4f5540f706..a168fdc01ca 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s2(new A[3]);
assert(A::count == 3);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s2(new A[3]);
assert(A::count == 3);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp index 9d0e40f2873..690237e5833 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>::pointer type
#include <memory>
#include <type_traits>
struct Deleter
{
struct pointer {};
};
int main()
{
{
typedef std::unique_ptr<int[]> P;
static_assert((std::is_same<P::pointer, int*>::value), "");
}
{
typedef std::unique_ptr<int[], Deleter> P;
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>::pointer type
#include <memory>
#include <type_traits>
struct Deleter
{
struct pointer {};
};
int main()
{
{
typedef std::unique_ptr<int[]> P;
static_assert((std::is_same<P::pointer, int*>::value), "");
}
{
typedef std::unique_ptr<int[], Deleter> P;
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp index ae9a0154a8f..4a8c0915405 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require default Deleter ctor
#include <memory>
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int[], Deleter> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require default Deleter ctor
#include <memory>
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int[], Deleter> p;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp index bf375a5cda5..280cfd235d6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should only require default Deleter ctor
#include <memory>
#include <cassert>
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);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should only require default Deleter ctor
#include <memory>
#include <cassert>
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);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp index 5edf3f8ee91..b94f9b9c24d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require non-reference Deleter ctor
#include <memory>
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int[], Deleter&> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require non-reference Deleter ctor
#include <memory>
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int[], Deleter&> p;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp index 5229a900515..41d143996af 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test default unique_ptr<T[]> ctor
// default unique_ptr<T[]> ctor shouldn't require complete type
#include <memory>
#include <cassert>
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A> >
struct B
{
std::unique_ptr<A[], D> a_;
B();
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
int main()
{
{
B<> s;
assert(s.get() == 0);
}
check(0);
{
B<Deleter> s;
assert(s.get() == 0);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
void Deleter::operator()(A* p) {delete p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B() {}
template <class D>
B<D>::~B() {}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test default unique_ptr<T[]> ctor
// default unique_ptr<T[]> ctor shouldn't require complete type
#include <memory>
#include <cassert>
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A> >
struct B
{
std::unique_ptr<A[], D> a_;
B();
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
int main()
{
{
B<> s;
assert(s.get() == 0);
}
check(0);
{
B<Deleter> s;
assert(s.get() == 0);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
void Deleter::operator()(A* p) {delete p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B() {}
template <class D>
B<D>::~B() {}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp index 7f8cc0f07bc..dfa0434ee70 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require non-pointer Deleter
#include <memory>
int main()
{
std::unique_ptr<int[], void (*)(void*)> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
// default unique_ptr ctor should require non-pointer Deleter
#include <memory>
int main()
{
std::unique_ptr<int[], void (*)(void*)> p;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp index 72a7449c949..b9c23628c79 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp index 94363206583..f58b18f90dd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
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()
{
{
std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
}
assert(A::count == 0);
{
std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5));
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
{
NCDeleter d;
std::unique_ptr<A[], NCDeleter&> s(new A[3], d);
A* p = s.get();
std::unique_ptr<A[], NCDeleter&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
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()
{
{
std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
}
assert(A::count == 0);
{
std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5));
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
{
NCDeleter d;
std::unique_ptr<A[], NCDeleter&> s(new A[3], d);
A* p = s.get();
std::unique_ptr<A[], NCDeleter&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 3);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp index 8c11b517cfd..9d387d97a01 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from const lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from const lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A[]> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp index 4b0a5fd4ad7..0cf6da30b3f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
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()
{
return std::unique_ptr<A[]>(new A[3]);
}
void sink1(std::unique_ptr<A[]> p)
{
}
std::unique_ptr<A[], Deleter<A[]> >
source2()
{
return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
}
void sink2(std::unique_ptr<A[], Deleter<A[]> > p)
{
}
std::unique_ptr<A[], NCDeleter&>
source3()
{
static NCDeleter d;
return std::unique_ptr<A[], NCDeleter&>(new A[3], d);
}
void sink3(std::unique_ptr<A[], NCDeleter&> p)
{
}
int main()
{
sink1(source1());
sink2(source2());
sink3(source3());
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
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()
{
return std::unique_ptr<A[]>(new A[3]);
}
void sink1(std::unique_ptr<A[]> p)
{
}
std::unique_ptr<A[], Deleter<A[]> >
source2()
{
return std::unique_ptr<A[], Deleter<A[]> >(new A[3]);
}
void sink2(std::unique_ptr<A[], Deleter<A[]> > p)
{
}
std::unique_ptr<A[], NCDeleter&>
source3()
{
static NCDeleter d;
return std::unique_ptr<A[], NCDeleter&>(new A[3], d);
}
void sink3(std::unique_ptr<A[], NCDeleter&> p)
{
}
int main()
{
sink1(source1());
sink2(source2());
sink3(source3());
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp index f2a8263b0d1..d3df6146625 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
std::unique_ptr<A[], Deleter> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[], Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
std::unique_ptr<A[], Deleter> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[], Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp index 8c77d475190..6d11937f567 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from const lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
const std::unique_ptr<A[], Deleter> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[], Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
// test move ctor. Can't copy from const lvalue
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
const std::unique_ptr<A[], Deleter> s(new A[3]);
A* p = s.get();
std::unique_ptr<A[], Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp index 9f07dec9813..9a580449fdd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp index 5217a866b87..86a2cf68ed6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp index 2e562d81c4c..9822dc2b3ba 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp index e2d24222949..b0a9bc71075 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp index d7d5e16c97b..983d6c8c51d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp index 6765031800d..ae87cfe2f56 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp index 136857df3d7..ce5883a9ad6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp index b65ad1fb3d0..3203f29e82f 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp index dabe4ac5e54..d2c5eb92224 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp index 780c392fc8c..ec576470bc1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp index f16ea7b365f..f3c299c0bab 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp index 7b0a42cfb23..26b925da4a8 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
const std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp index 5a5d9177374..a6040720ef6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp index 96ae4bd7333..2b5b27c68c4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp index abf31eb836f..ddcdb453a6b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2(std::move(s));
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp index 0e4e64f046d..d9f4d99ad7e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[]> s(new B);
A* p = s.get();
std::unique_ptr<A[]> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp index ab772bdc285..96ebb838013 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Implicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B[], Deleter<B[]> > s(new B);
A* p = s.get();
std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp index c54882bbbaa..2852c472e6d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B[], CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A[], CDeleter<A>&> s2 = std::move(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp index e291d98258f..d0fdb9a2d9d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// unique_ptr(nullptr_t);
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int[]> p(nullptr);
assert(p.get() == 0);
}
{
std::unique_ptr<int[], Deleter> p(nullptr);
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// unique_ptr(nullptr_t);
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int[]> p(nullptr);
assert(p.get() == 0);
}
{
std::unique_ptr<int[], Deleter> p(nullptr);
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp index 1aabf2124b9..bdcd371b5be 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor
#include <memory>
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int[], Deleter> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor
#include <memory>
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int[], Deleter> p(new int);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp index de0cd262dcf..25e41cace94 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[]> s(p);
assert(s.get() == p);
}
assert(A::count == 0);
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should only require default Deleter ctor
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[]> s(p);
assert(s.get() == p);
}
assert(A::count == 0);
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp index aa01ffd51d5..8f3767dc5f7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
#include <memory>
// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int[], Deleter&> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
#include <memory>
// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int[], Deleter&> p(new int);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp index 4146d5684cb..f70f9851e10 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor shouldn't require complete type
#include <memory>
#include <cassert>
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A[]> >
struct B
{
std::unique_ptr<A[], D> a_;
explicit B(A*);
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
A* get();
int main()
{
{
A* p = get();
check(3);
B<> s(p);
assert(s.get() == p);
}
check(0);
{
A* p = get();
check(3);
B<Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
A* get() {return new A[3];}
void Deleter::operator()(A* p) {delete [] p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B(A* a) : a_(a) {}
template <class D>
B<D>::~B() {}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor shouldn't require complete type
#include <memory>
#include <cassert>
struct A;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p);
};
void check(int i);
template <class D = std::default_delete<A[]> >
struct B
{
std::unique_ptr<A[], D> a_;
explicit B(A*);
~B();
A* get() const {return a_.get();}
D& get_deleter() {return a_.get_deleter();}
};
A* get();
int main()
{
{
A* p = get();
check(3);
B<> s(p);
assert(s.get() == p);
}
check(0);
{
A* p = get();
check(3);
B<Deleter> s(p);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
check(0);
}
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
A* get() {return new A[3];}
void Deleter::operator()(A* p) {delete [] p;}
void check(int i)
{
assert(A::count == i);
}
template <class D>
B<D>::B(A* a) : a_(a) {}
template <class D>
B<D>::~B() {}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp index e826b997df9..35c1c764e46 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter
#include <memory>
int main()
{
std::unique_ptr<int[], void (*)(void*)> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr<T[]>(pointer) ctor
// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter
#include <memory>
int main()
{
std::unique_ptr<int[], void (*)(void*)> p(new int);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp index 6db86df129a..507610bb2ab 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
// unique_ptr(pointer) ctor should not work with derived pointers
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
B* p = new B[3];
std::unique_ptr<A[]> s(p);
}
{
B* p = new B[3];
std::unique_ptr<A[], Deleter> s(p);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
// unique_ptr(pointer) ctor should not work with derived pointers
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
B* p = new B[3];
std::unique_ptr<A[]> s(p);
}
{
B* p = new B[3];
std::unique_ptr<A[], Deleter> s(p);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp index ab3899e04bd..4d27319f3ba 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>());
assert(s.get() == p);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>());
assert(s.get() == p);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp index 6bb16db0344..e25c5b1f8ea 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, d) requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], Deleter> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, d) requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], Deleter> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp index a5e7b93aaab..8f4594c5f78 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
d.set_state(6);
assert(s.get_deleter().state() == 6);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp index 8350829f7d5..42b84c174c5 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// 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;}
};
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// 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;}
};
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp index b9c8f83fe30..34b426e16d9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) const {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], const Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(A* p) const {delete [] p;}
};
int main()
{
{
A* p = new A[3];
assert(A::count == 3);
Deleter d;
std::unique_ptr<A[], const Deleter&> s(p, d);
assert(s.get() == p);
assert(s.get_deleter().state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp index 7c09b169107..66a314ae656 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, deleter) should not work with derived pointers
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
B* p = new B[3];
std::unique_ptr<A[], Deleter> s(p, Deleter());
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer, deleter) ctor
// unique_ptr(pointer, deleter) should not work with derived pointers
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete [] p;}
};
int main()
{
B* p = new B[3];
std::unique_ptr<A[], Deleter> s(p, Deleter());
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp index d3cc0bfd4cf..1f80c9e5a1a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test release
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int[]> p(new int[3]);
int* i = p.get();
int* j = p.release();
assert(p.get() == 0);
assert(i == j);
delete [] j;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test release
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int[]> p(new int[3]);
int* i = p.get();
int* j = p.release();
assert(p.get() == 0);
assert(i == j);
delete [] j;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp index 4753b027f86..1cbea933a87 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> p(new A[3]);
assert(A::count == 3);
A* i = p.get();
p.reset();
assert(A::count == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A[]> p(new A[4]);
assert(A::count == 4);
A* i = p.get();
p.reset(new A[5]);
assert(A::count == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A[]> p(new A[3]);
assert(A::count == 3);
A* i = p.get();
p.reset();
assert(A::count == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A[]> p(new A[4]);
assert(A::count == 4);
A* i = p.get();
p.reset(new A[5]);
assert(A::count == 5);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp index 8466a6c0a5d..43bb562e7f4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<A[]> p(new A);
assert(A::count == 1);
assert(B::count == 0);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
std::unique_ptr<A[]> p(new B);
assert(A::count == 1);
assert(B::count == 1);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<A[]> p(new A);
assert(A::count == 1);
assert(B::count == 0);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
std::unique_ptr<A[]> p(new B);
assert(A::count == 1);
assert(B::count == 1);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp index 0c70ce79471..07eac0228b3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test swap
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
int state_;
static int count;
A() : state_(0) {++count;}
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
A* p2 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
assert(s1.get() == p1);
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(s2.get_deleter().state() == 2);
s1.swap(s2);
assert(s1.get() == p2);
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(s2.get_deleter().state() == 1);
assert(A::count == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test swap
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
int state_;
static int count;
A() : state_(0) {++count;}
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
A* p2 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
assert(s1.get() == p1);
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(s2.get_deleter().state() == 2);
s1.swap(s2);
assert(s1.get() == p2);
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(s2.get_deleter().state() == 1);
assert(A::count == 6);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp index 51747d1fdbf..5bfb4de49d0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int[]> p(new int(3));
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int[]> p(new int(3));
assert(*p == 3);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp index 23253858338..f3b7f01d829 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
{
std::unique_ptr<int[]> p(new int [3]);
if (p)
;
else
assert(false);
if (!p)
assert(false);
}
{
std::unique_ptr<int[]> p;
if (!p)
;
else
assert(false);
if (p)
assert(false);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
{
std::unique_ptr<int[]> p(new int [3]);
if (p)
;
else
assert(false);
if (!p)
assert(false);
}
{
std::unique_ptr<int[]> p;
if (!p)
;
else
assert(false);
if (p)
assert(false);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp index 74967938d3e..5ed1a201a3e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get
#include <memory>
#include <cassert>
int main()
{
int* p = new int[3];
std::unique_ptr<int[]> s(p);
assert(s.get() == p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get
#include <memory>
#include <cassert>
int main()
{
int* p = new int[3];
std::unique_ptr<int[]> s(p);
assert(s.get() == p);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp index 3f4ab3f078d..0d58c7ac2ce 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get_deleter()
#include <memory>
#include <cassert>
struct Deleter
{
void operator()(void*) {}
int test() {return 5;}
int test() const {return 6;}
};
int main()
{
{
std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
const std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 6);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get_deleter()
#include <memory>
#include <cassert>
struct Deleter
{
void operator()(void*) {}
int test() {return 5;}
int test() const {return 6;}
};
int main()
{
{
std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
const std::unique_ptr<int[], Deleter> p;
assert(p.get_deleter().test() == 6);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp index f8af29a2549..95ad2f26fb3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op[](size_t)
#include <memory>
#include <cassert>
class A
{
int state_;
static int next_;
public:
A() : state_(++next_) {}
int get() const {return state_;}
friend bool operator==(const A& x, int y)
{return x.state_ == y;}
A& operator=(int i) {state_ = i; return *this;}
};
int A::next_ = 0;
int main()
{
std::unique_ptr<A[]> p(new A[3]);
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 3);
p[0] = 3;
p[1] = 2;
p[2] = 1;
assert(p[0] == 3);
assert(p[1] == 2);
assert(p[2] == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op[](size_t)
#include <memory>
#include <cassert>
class A
{
int state_;
static int next_;
public:
A() : state_(++next_) {}
int get() const {return state_;}
friend bool operator==(const A& x, int y)
{return x.state_ == y;}
A& operator=(int i) {state_ = i; return *this;}
};
int A::next_ = 0;
int main()
{
std::unique_ptr<A[]> p(new A[3]);
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 3);
p[0] = 3;
p[1] = 2;
p[2] = 1;
assert(p[0] == 3);
assert(p[1] == 2);
assert(p[2] == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp index 1defbc6b80a..f8973e17504 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op->()
#include <memory>
#include <cassert>
struct A
{
int i_;
A() : i_(7) {}
};
int main()
{
std::unique_ptr<A[]> p(new A);
assert(p->i_ == 7);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op->()
#include <memory>
#include <cassert>
struct A
{
int i_;
A() : i_(7) {}
};
int main()
{
std::unique_ptr<A[]> p(new A);
assert(p->i_ == 7);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp index d00f5b820d9..daa83841cd7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr::pointer type
#include <memory>
#include <type_traits>
struct Deleter
{
struct pointer {};
};
int main()
{
{
typedef std::unique_ptr<int> P;
static_assert((std::is_same<P::pointer, int*>::value), "");
}
{
typedef std::unique_ptr<int, Deleter> P;
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr::pointer type
#include <memory>
#include <type_traits>
struct Deleter
{
struct pointer {};
};
int main()
{
{
typedef std::unique_ptr<int> P;
static_assert((std::is_same<P::pointer, int*>::value), "");
}
{
typedef std::unique_ptr<int, Deleter> P;
static_assert((std::is_same<P::pointer, Deleter::pointer>::value), "");
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp index cd29056f142..6360686f745 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
int main()
{
{
std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
int main()
{
{
std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp index 99b7c5e5dd1..94c8b5b1581 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
// test move assignment. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s1(new A);
A* p = s1.get();
std::unique_ptr<A> s2(new A);
assert(A::count == 2);
s2 = std::move(s1);
assert(A::count == 1);
assert(s2.get() == p);
assert(s1.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5));
A* p = s1.get();
std::unique_ptr<A, Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s1.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter<A> d1(5);
std::unique_ptr<A, CDeleter<A>&> s1(new A, d1);
A* p = s1.get();
CDeleter<A> d2(6);
std::unique_ptr<A, CDeleter<A>&> s2(new A, d2);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 1);
assert(d1.state() == 5);
assert(d2.state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
// test move assignment. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s1(new A);
A* p = s1.get();
std::unique_ptr<A> s2(new A);
assert(A::count == 2);
s2 = std::move(s1);
assert(A::count == 1);
assert(s2.get() == p);
assert(s1.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A, Deleter<A> > s1(new A, Deleter<A>(5));
A* p = s1.get();
std::unique_ptr<A, Deleter<A> > s2(new A);
assert(A::count == 2);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s1.get_deleter().state() == 0);
}
assert(A::count == 0);
{
CDeleter<A> d1(5);
std::unique_ptr<A, CDeleter<A>&> s1(new A, d1);
A* p = s1.get();
CDeleter<A> d2(6);
std::unique_ptr<A, CDeleter<A>&> s2(new A, d2);
s2 = std::move(s1);
assert(s2.get() == p);
assert(s1.get() == 0);
assert(A::count == 1);
assert(d1.state() == 5);
assert(d2.state() == 5);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp index 0d47e023805..e245105ae40 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A> s(new A);
std::unique_ptr<A> s2;
s2 = s;
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp index 2c2fdd96e82..594704f2a83 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// 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;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp index dc0b46eedf1..89267738d13 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp index 4a7a278033c..dc9e6cc731e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp index 9319ff880c2..68aa7be4f8d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp index c42dbf6db39..01cdc5754b2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
#include "../../deleter.h"
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
#include "../../deleter.h"
// Can't assign from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp index c2336e87993..97217d0ac42 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#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;
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#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;
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp index b9f49330a15..e5b5cb25418 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#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;
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from lvalue
#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;
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp index cfdf15de8f8..2c421dfe3e6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// test converting move assignment with reference deleters
#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;
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// test converting move assignment with reference deleters
#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;
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp index 79225233508..eef44ceb783 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
#include <memory>
#include <cassert>
// Can't assign from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp index 3853b3f757b..d796ba36cf3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2;
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp index 780e46d1d9c..0400cbdb7dd 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
Deleter<B> db(5);
const std::unique_ptr<B, Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
std::unique_ptr<A, Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Can't assign from const lvalue
#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;
int main()
{
{
Deleter<B> db(5);
const std::unique_ptr<B, Deleter<B>&> s(new B, db);
A* p = s.get();
Deleter<A> da(6);
std::unique_ptr<A, Deleter<A>&> s2(new A, da);
s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp index 35b91f578b5..7ec9e00ef79 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Do not convert from an array unique_ptr
#include <memory>
#include <cassert>
struct A
{
};
struct Deleter
{
void operator()(void*) {}
};
int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2;
s2 = std::move(s);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move assignment
// Do not convert from an array unique_ptr
#include <memory>
#include <cassert>
struct A
{
};
struct Deleter
{
void operator()(void*) {}
};
int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2;
s2 = std::move(s);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp index be3292a41c4..da5d287e4c7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = 0;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = 0;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp index b405b1a33d4..3000f7448db 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move assignment
#include <memory>
#include <cassert>
// test assignment from null
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s2(new A);
assert(A::count == 1);
s2 = nullptr;
assert(A::count == 0);
assert(s2.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp index 8b7e4975142..24a0d221003 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = ap;
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = std::move(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = ap;
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = std::move(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp index 4ca2a08f1be..a13af5b9d0b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
// : public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = ap;
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
// : public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A> up;
up = ap;
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp index c3f955bcba9..9580723069b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct Deleter
{
template <class T>
void operator()(T*) {}
};
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A, Deleter> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
#include <cassert>
// template <class U> explicit unique_ptr(auto_ptr<U>&);
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct Deleter
{
template <class T>
void operator()(T*) {}
};
int main()
{
{
B* p = new B;
std::auto_ptr<B> ap(p);
std::unique_ptr<A, Deleter> up(ap);
assert(up.get() == p);
assert(ap.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp index c2b6a36b7a7..d9e9d479f52 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require default Deleter ctor
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int, Deleter> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require default Deleter ctor
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int, Deleter> p;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp index e78f6523844..e0178ba2f5d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp index d6ae0d742eb..1255c5c0c03 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int, Deleter&> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int, Deleter&> p;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp index 2542d8da135..90cf3752937 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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() {}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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() {}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp index ea99a337232..f8de7af2fb2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require non-pointer Deleter
int main()
{
std::unique_ptr<int, void (*)(void*)> p;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr default ctor
#include <memory>
// default unique_ptr ctor should require non-pointer Deleter
int main()
{
std::unique_ptr<int, void (*)(void*)> p;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp index d6cfe08bdc4..5d7b6232203 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp index 24cc1483f6a..7d3484d54e3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp index 9b78d9548b2..84470c9e4f2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::unique_ptr<A> s(new A);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp index a20111ad494..5abbb7776a2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp index 99e0d7a73a5..d6bffbec699 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp index a9644236e25..876b5899349 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr move ctor
#include <memory>
#include <cassert>
// test move ctor. Can't copy from const lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
class Deleter
{
int state_;
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(A* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<A, Deleter> s(new A);
A* p = s.get();
std::unique_ptr<A, Deleter> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp index 23fa3fbd651..7454a2cc543 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// Can't construct from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// Can't construct from lvalue
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp index 2c885a2a88b..a82e3f8f1b9 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp index 18089d809f8..85388db4d5a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp index 604485b8adc..091e3fbee97 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp index b9a60d7125d..0fb4a4cd058 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp index d860d6cc995..ecda031dbf6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp index 324e4db7b0e..58a911a6dd2 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// implicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp index 9eca5e5176e..79b616139e3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp index 08ca2082c2d..591bc79bc47 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
std::unique_ptr<A, Deleter<A> > s2 = s;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
std::unique_ptr<A, Deleter<A> > s2 = s;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp index 0793933c6c6..e4faba25b6e 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp index 3188e7c3e4e..9fd6649dbd4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
template <class T>
class CDeleter
{
int state_;
CDeleter(CDeleter&);
CDeleter& operator=(CDeleter&);
public:
CDeleter() : state_(5) {}
int state() const {return state_;}
void set_state(int s) {state_ = s;}
void operator()(T* p) {delete p;}
};
int main()
{
{
CDeleter<A> d;
std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp index 13c1b1a8233..4961a53a669 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp index 8cdb6a44000..d05e81e45e7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#include <cassert>
// test converting move ctor. Should only require a MoveConstructible deleter, or if
// deleter is a reference, not even that.
// Explicit version
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp index 36ceb4ecbd2..3ef4da00c71 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp index 6f46575be9c..cdd0fd7f0eb 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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 Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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 Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp index a5c0f95a1ae..18a7b07e0d4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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;
const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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;
const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2(s);
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp index 8fba31414da..0bed30c2c26 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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()
{
{
const std::unique_ptr<B> s(new B);
A* p = s.get();
std::unique_ptr<A> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp index 46417de5ac8..3b7d5f81672 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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;
template <class T>
class Deleter
{
int state_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
public:
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {delete p;}
};
int main()
{
{
const std::unique_ptr<B, Deleter<B> > s(new B);
A* p = s.get();
std::unique_ptr<A, Deleter<A> > s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
assert(s2.get_deleter().state() == 5);
assert(s.get_deleter().state() == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp index 063792ec496..42d7a189a11 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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;
const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
#include <memory>
#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;
const std::unique_ptr<B, CDeleter<A>&> s(new B, d);
A* p = s.get();
std::unique_ptr<A, CDeleter<A>&> s2 = s;
assert(s2.get() == p);
assert(s.get() == 0);
assert(A::count == 1);
assert(B::count == 1);
d.set_state(6);
assert(s2.get_deleter().state() == d.state());
assert(s.get_deleter().state() == d.state());
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp index e428e861d5c..e5b666e581b 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// Do not convert from an array unique_ptr
#include <memory>
#include <cassert>
struct A
{
};
struct Deleter
{
void operator()(void*) {}
};
int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2(std::move(s));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr converting move ctor
// Do not convert from an array unique_ptr
#include <memory>
#include <cassert>
struct A
{
};
struct Deleter
{
void operator()(void*) {}
};
int main()
{
std::unique_ptr<A[], Deleter> s;
std::unique_ptr<A, Deleter> s2(std::move(s));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp index d76a61cb9a7..c49c9c8deca 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// unique_ptr(nullptr_t);
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int> p(nullptr);
assert(p.get() == 0);
}
{
std::unique_ptr<int, Deleter> p(nullptr);
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// unique_ptr(nullptr_t);
#include <memory>
#include <cassert>
// default unique_ptr ctor should only require default Deleter ctor
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(5) {}
int state() const {return state_;}
void operator()(void*) {}
};
int main()
{
{
std::unique_ptr<int> p(nullptr);
assert(p.get() == 0);
}
{
std::unique_ptr<int, Deleter> p(nullptr);
assert(p.get() == 0);
assert(p.get_deleter().state() == 5);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp index 6b50b82f050..eaffc6dc2a6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require default Deleter ctor
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int, Deleter> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require default Deleter ctor
class Deleter
{
Deleter() {}
public:
Deleter(Deleter&) {}
Deleter& operator=(Deleter&) {}
void operator()(void*) const {}
};
int main()
{
std::unique_ptr<int, Deleter> p(new int);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp index bf4c3df942d..74f4f7fbfa7 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp index 0effe06412f..7780932a4b5 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int, Deleter&> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require non-reference Deleter ctor
class Deleter
{
public:
void operator()(void*) {}
};
int main()
{
std::unique_ptr<int, Deleter&> p(new int);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp index abfdcdb9467..f8ff88d2e86 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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() {}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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() {}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp index 1e8e56a6dfc..f3f09535b33 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require non-pointer Deleter
int main()
{
std::unique_ptr<int, void (*)(void*)> p(new int);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test unique_ptr(pointer) ctor
#include <memory>
// unique_ptr(pointer) ctor should require non-pointer Deleter
int main()
{
std::unique_ptr<int, void (*)(void*)> p(new int);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp index 0f31fd53f3c..ef4542564e0 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp index 318015d31b6..8305a399a3c 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter01.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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_;
#ifdef _LIBCPP_MOVE
Deleter(const Deleter&);
Deleter& operator=(const Deleter&);
#else
Deleter(Deleter&);
Deleter& operator=(Deleter&);
#endif
public:
#ifdef _LIBCPP_MOVE
Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;}
Deleter& operator=(Deleter&& r)
{
state_ = r.state_;
r.state_ = 0;
return *this;
}
#else
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
Deleter() : state_(5) {}
#ifdef _LIBCPP_MOVE
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
template <class U>
Deleter(Deleter<U> d,
typename std::enable_if<!std::is_same<U, T>::value>::type* = 0)
: state_(d.state()) {}
#endif
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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp index c6489a41072..e5c9e24a72d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter02.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp index 2a28bcd0f10..d94eaaf2f29 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter03.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp index 8cb622dee3c..0912ba9aa3a 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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;}
void operator()(A* 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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;}
void operator()(A* 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp index d68b89bd2dc..b5ff2702579 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp index a0a6bab975e..93d324285c4 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter05.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp index 6691c24a7ce..527666fa4df 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter06.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// 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);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp index c5c5e7a2eec..20f3d00f4aa 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// The deleter is not called if get() == 0
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(0) {}
int state() const {return state_;}
void operator()(void*) {++state_;}
};
int main()
{
Deleter d;
assert(d.state() == 0);
{
std::unique_ptr<int, Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
}
assert(d.state() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// The deleter is not called if get() == 0
#include <memory>
#include <cassert>
class Deleter
{
int state_;
Deleter(Deleter&);
Deleter& operator=(Deleter&);
public:
Deleter() : state_(0) {}
int state() const {return state_;}
void operator()(void*) {++state_;}
};
int main()
{
Deleter d;
assert(d.state() == 0);
{
std::unique_ptr<int, Deleter&> p(0, d);
assert(p.get() == 0);
assert(&p.get_deleter() == &d);
}
assert(d.state() == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp index 3dd0834fe8c..da593d124be 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test release
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int> p(new int(3));
int* i = p.get();
int* j = p.release();
assert(p.get() == 0);
assert(i == j);
delete j;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test release
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int> p(new int(3));
int* i = p.get();
int* j = p.release();
assert(p.get() == 0);
assert(i == j);
delete j;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp index 9b40ffbe4a1..806b5d787e6 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
A* i = p.get();
p.reset();
assert(A::count == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
A* i = p.get();
p.reset(new A);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
A* i = p.get();
p.reset();
assert(A::count == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
A* i = p.get();
p.reset(new A);
assert(A::count == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp index e0fbcfabbdf..78da880bc22 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
assert(B::count == 0);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
std::unique_ptr<A> p(new B);
assert(A::count == 1);
assert(B::count == 1);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
virtual ~A() {--count;}
};
int A::count = 0;
struct B
: public A
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
int main()
{
{
std::unique_ptr<A> p(new A);
assert(A::count == 1);
assert(B::count == 0);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
{
std::unique_ptr<A> p(new B);
assert(A::count == 1);
assert(B::count == 1);
A* i = p.get();
p.reset(new B);
assert(A::count == 1);
assert(B::count == 1);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp index dc4b35524b6..c31c56fa127 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset against resetting self
#include <memory>
struct A
{
std::unique_ptr<A> ptr_;
A() : ptr_(this) {}
void reset() {ptr_.reset();}
};
int main()
{
(new A)->reset();
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test reset against resetting self
#include <memory>
struct A
{
std::unique_ptr<A> ptr_;
A() : ptr_(this) {}
void reset() {ptr_.reset();}
};
int main()
{
(new A)->reset();
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp index 326ef2e7e4d..853273aef2d 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test swap
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
int state_;
static int count;
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A(1);
std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
A* p2 = new A(2);
std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
assert(s1.get() == p1);
assert(*s1 == A(1));
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(*s2 == A(2));
assert(s2.get_deleter().state() == 2);
s1.swap(s2);
assert(s1.get() == p2);
assert(*s1 == A(2));
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(*s2 == A(1));
assert(s2.get_deleter().state() == 1);
assert(A::count == 2);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test swap
#include <memory>
#include <cassert>
#include "../../deleter.h"
struct A
{
int state_;
static int count;
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A(1);
std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
A* p2 = new A(2);
std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
assert(s1.get() == p1);
assert(*s1 == A(1));
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(*s2 == A(2));
assert(s2.get_deleter().state() == 2);
s1.swap(s2);
assert(s1.get() == p2);
assert(*s1 == A(2));
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(*s2 == A(1));
assert(s2.get_deleter().state() == 1);
assert(A::count == 2);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp index 2be9e4685a7..08092ec2ab1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int> p(new int(3));
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
std::unique_ptr<int> p(new int(3));
assert(*p == 3);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp index 01a1c06d5c8..3fbfb3826a5 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
{
std::unique_ptr<int> p(new int(3));
if (p)
;
else
assert(false);
if (!p)
assert(false);
}
{
std::unique_ptr<int> p;
if (!p)
;
else
assert(false);
if (p)
assert(false);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op*()
#include <memory>
#include <cassert>
int main()
{
{
std::unique_ptr<int> p(new int(3));
if (p)
;
else
assert(false);
if (!p)
assert(false);
}
{
std::unique_ptr<int> p;
if (!p)
;
else
assert(false);
if (p)
assert(false);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp index 3a3d0de265c..d453724c0e8 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get
#include <memory>
#include <cassert>
int main()
{
int* p = new int;
std::unique_ptr<int> s(p);
assert(s.get() == p);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get
#include <memory>
#include <cassert>
int main()
{
int* p = new int;
std::unique_ptr<int> s(p);
assert(s.get() == p);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp index 2f231364b3c..8cefe172f38 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get_deleter()
#include <memory>
#include <cassert>
struct Deleter
{
void operator()(void*) {}
int test() {return 5;}
int test() const {return 6;}
};
int main()
{
{
std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
const std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 6);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test get_deleter()
#include <memory>
#include <cassert>
struct Deleter
{
void operator()(void*) {}
int test() {return 5;}
int test() const {return 6;}
};
int main()
{
{
std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 5);
}
{
const std::unique_ptr<int, Deleter> p;
assert(p.get_deleter().test() == 6);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp index f542bb99eed..4e9657067ed 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op[](size_t)
#include <memory>
#include <cassert>
class A
{
int state_;
static int next_;
public:
A() : state_(++next_) {}
int get() const {return state_;}
friend bool operator==(const A& x, int y)
{return x.state_ == y;}
A& operator=(int i) {state_ = i; return *this;}
};
int A::next_ = 0;
int main()
{
std::unique_ptr<A> p(new A[3]);
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 3);
p[0] = 3;
p[1] = 2;
p[2] = 1;
assert(p[0] == 3);
assert(p[1] == 2);
assert(p[2] == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op[](size_t)
#include <memory>
#include <cassert>
class A
{
int state_;
static int next_;
public:
A() : state_(++next_) {}
int get() const {return state_;}
friend bool operator==(const A& x, int y)
{return x.state_ == y;}
A& operator=(int i) {state_ = i; return *this;}
};
int A::next_ = 0;
int main()
{
std::unique_ptr<A> p(new A[3]);
assert(p[0] == 1);
assert(p[1] == 2);
assert(p[2] == 3);
p[0] = 3;
p[1] = 2;
p[2] = 1;
assert(p[0] == 3);
assert(p[1] == 2);
assert(p[2] == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp index dfae3c334df..4a00ea233e5 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op->()
#include <memory>
#include <cassert>
struct A
{
int i_;
A() : i_(7) {}
};
int main()
{
std::unique_ptr<A> p(new A);
assert(p->i_ == 7);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// test op->()
#include <memory>
#include <cassert>
struct A
{
int i_;
A() : i_(7) {}
};
int main()
{
std::unique_ptr<A> p(new A);
assert(p->i_ == 7);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp index daff8bf2c17..683378ec140 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// template <class T1, class D1, class T2, class D2>
// bool
// operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
#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;
int main()
{
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<A, Deleter<A> > p2(new A);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<B, Deleter<B> > p2(new B);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<A, Deleter<A> > p2;
assert(p1 == p2);
assert(!(p1 != p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<B, Deleter<B> > p2;
assert(p1 == p2);
assert(!(p1 != p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// template <class T1, class D1, class T2, class D2>
// bool
// operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
#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;
int main()
{
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<A, Deleter<A> > p2(new A);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<B, Deleter<B> > p2(new B);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
assert(!(p1 == p2));
assert(p1 != p2);
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<A, Deleter<A> > p2;
assert(p1 == p2);
assert(!(p1 != p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<B, Deleter<B> > p2;
assert(p1 == p2);
assert(!(p1 != p2));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp index 21c495b9feb..93052283ae3 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// template <class T1, class D1, class T2, class D2>
// bool
// operator< (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator> (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
#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;
int main()
{
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<A, Deleter<A> > p2(new A);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<B, Deleter<B> > p2(new B);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<A, Deleter<A> > p2;
assert((p1 < p2) == (p1 > p2));
assert((p1 < p2) == !(p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<B, Deleter<B> > p2;
assert((p1 < p2) == (p1 > p2));
assert((p1 < p2) == !(p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// template <class T1, class D1, class T2, class D2>
// bool
// operator< (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator> (const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
// template <class T1, class D1, class T2, class D2>
// bool
// operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
#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;
int main()
{
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<A, Deleter<A> > p2(new A);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1(new A);
const std::unique_ptr<B, Deleter<B> > p2(new B);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<A[], Deleter<A[]> > p2(new A[3]);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A[], Deleter<A[]> > p1(new A[3]);
const std::unique_ptr<B[], Deleter<B[]> > p2(new B[3]);
assert((p1 < p2) == !(p1 > p2));
assert((p1 < p2) == (p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<A, Deleter<A> > p2;
assert((p1 < p2) == (p1 > p2));
assert((p1 < p2) == !(p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
{
const std::unique_ptr<A, Deleter<A> > p1;
const std::unique_ptr<B, Deleter<B> > p2;
assert((p1 < p2) == (p1 > p2));
assert((p1 < p2) == !(p1 <= p2));
assert((p1 < p2) == !(p1 >= p2));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp index d92bc3f1a40..c0bdfea88ca 100644 --- a/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp +++ b/libcxx/test/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test swap
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
int state_;
static int count;
A() : state_(0) {++count;}
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A(1);
std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
A* p2 = new A(2);
std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
assert(s1.get() == p1);
assert(*s1 == A(1));
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(*s2 == A(2));
assert(s2.get_deleter().state() == 2);
swap(s1, s2);
assert(s1.get() == p2);
assert(*s1 == A(2));
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(*s2 == A(1));
assert(s2.get_deleter().state() == 1);
assert(A::count == 2);
}
assert(A::count == 0);
{
A* p1 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
A* p2 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
assert(s1.get() == p1);
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(s2.get_deleter().state() == 2);
swap(s1, s2);
assert(s1.get() == p2);
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(s2.get_deleter().state() == 1);
assert(A::count == 6);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// unique_ptr
// Test swap
#include <memory>
#include <cassert>
#include "../deleter.h"
struct A
{
int state_;
static int count;
A() : state_(0) {++count;}
explicit A(int i) : state_(i) {++count;}
A(const A& a) : state_(a.state_) {++count;}
A& operator=(const A& a) {state_ = a.state_; return *this;}
~A() {--count;}
friend bool operator==(const A& x, const A& y)
{return x.state_ == y.state_;}
};
int A::count = 0;
int main()
{
{
A* p1 = new A(1);
std::unique_ptr<A, Deleter<A> > s1(p1, Deleter<A>(1));
A* p2 = new A(2);
std::unique_ptr<A, Deleter<A> > s2(p2, Deleter<A>(2));
assert(s1.get() == p1);
assert(*s1 == A(1));
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(*s2 == A(2));
assert(s2.get_deleter().state() == 2);
swap(s1, s2);
assert(s1.get() == p2);
assert(*s1 == A(2));
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(*s2 == A(1));
assert(s2.get_deleter().state() == 1);
assert(A::count == 2);
}
assert(A::count == 0);
{
A* p1 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s1(p1, Deleter<A[]>(1));
A* p2 = new A[3];
std::unique_ptr<A[], Deleter<A[]> > s2(p2, Deleter<A[]>(2));
assert(s1.get() == p1);
assert(s1.get_deleter().state() == 1);
assert(s2.get() == p2);
assert(s2.get_deleter().state() == 2);
swap(s1, s2);
assert(s1.get() == p2);
assert(s1.get_deleter().state() == 2);
assert(s2.get() == p1);
assert(s2.get_deleter().state() == 1);
assert(A::count == 6);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp b/libcxx/test/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp index a85659cbdf7..51c132b65fc 100644 --- a/libcxx/test/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp +++ b/libcxx/test/utilities/memory/util.dynamic.safety/declare_no_pointers.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp b/libcxx/test/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp index 3f2381f8ed6..54f3bdf32cc 100644 --- a/libcxx/test/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp +++ b/libcxx/test/utilities/memory/util.dynamic.safety/declare_reachable.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp b/libcxx/test/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp index 868b7e99aed..9ef4a1e7dcf 100644 --- a/libcxx/test/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp +++ b/libcxx/test/utilities/memory/util.dynamic.safety/get_pointer_safety.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/nothing_to_do.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index 595d05c28e9..d4618719cfb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// template<class T>
// class enable_shared_from_this
// {
// protected:
// enable_shared_from_this();
// enable_shared_from_this(enable_shared_from_this const&);
// enable_shared_from_this& operator=(enable_shared_from_this const&);
// ~enable_shared_from_this();
// public:
// shared_ptr<T> shared_from_this();
// shared_ptr<T const> shared_from_this() const;
// };
#include <memory>
#include <cassert>
struct T
: public std::enable_shared_from_this<T>
{
};
struct Y : T {};
struct Z : Y {};
int main()
{
{
std::shared_ptr<Y> p(new Z);
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
{
std::shared_ptr<Y> p = std::make_shared<Z>();
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// template<class T>
// class enable_shared_from_this
// {
// protected:
// enable_shared_from_this();
// enable_shared_from_this(enable_shared_from_this const&);
// enable_shared_from_this& operator=(enable_shared_from_this const&);
// ~enable_shared_from_this();
// public:
// shared_ptr<T> shared_from_this();
// shared_ptr<T const> shared_from_this() const;
// };
#include <memory>
#include <cassert>
struct T
: public std::enable_shared_from_this<T>
{
};
struct Y : T {};
struct Z : Y {};
int main()
{
{
std::shared_ptr<Y> p(new Z);
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
{
std::shared_ptr<Y> p = std::make_shared<Z>();
std::shared_ptr<T> q = p->shared_from_this();
assert(p == q);
assert(!p.owner_before(q) && !q.owner_before(p)); // p and q share ownership
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h index e1cdbbdd236..b9aeeebcd66 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
struct test_deleter_base
{
static int count;
static int dealloc_count;
};
int test_deleter_base::count = 0;
int test_deleter_base::dealloc_count = 0;
template <class T>
class test_deleter
: public test_deleter_base
{
int state_;
public:
test_deleter() : state_(0) {++count;}
explicit test_deleter(int s) : state_(s) {++count;}
test_deleter(const test_deleter& d)
: state_(d.state_) {++count;}
~test_deleter() {assert(state_ >= 0); --count; state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;}
};
template <class T>
void
swap(test_deleter<T>& x, test_deleter<T>& y)
{
test_deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// Example move-only deleter
#ifndef DELETER_H
#define DELETER_H
#include <type_traits>
#include <cassert>
struct test_deleter_base
{
static int count;
static int dealloc_count;
};
int test_deleter_base::count = 0;
int test_deleter_base::dealloc_count = 0;
template <class T>
class test_deleter
: public test_deleter_base
{
int state_;
public:
test_deleter() : state_(0) {++count;}
explicit test_deleter(int s) : state_(s) {++count;}
test_deleter(const test_deleter& d)
: state_(d.state_) {++count;}
~test_deleter() {assert(state_ >= 0); --count; state_ = -1;}
int state() const {return state_;}
void set_state(int i) {state_ = i;}
void operator()(T* p) {assert(state_ >= 0); ++dealloc_count; delete p;}
};
template <class T>
void
swap(test_deleter<T>& x, test_deleter<T>& y)
{
test_deleter<T> t(std::move(x));
x = std::move(y);
y = std::move(t);
}
#endif
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp index 719a6515faa..09aa877d2cd 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/types.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class shared_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class shared_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::shared_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp index 651a922a06c..e12dc2fa6c7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D, class T> D* get_deleter(const shared_ptr<T>& p);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
test_deleter<A>::dealloc_count = 0;
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
test_deleter<A>::dealloc_count = 0;
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p);
assert(d == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D, class T> D* get_deleter(const shared_ptr<T>& p);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
test_deleter<A>::dealloc_count = 0;
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
test_deleter<A>::dealloc_count = 0;
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
std::default_delete<A>* d = std::get_deleter<std::default_delete<A> >(p);
assert(d == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp index 16b9aa2afed..09a95ec2478 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::auto_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp index 3171daa3cd6..8e1bb81afcc 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(const shared_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(const shared_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp index 83b1ea2ec69..a13b1fd2fef 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
const std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = pA;
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp index cb6ea09e139..e4142cda701 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_Y_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp index d15ddaf7d78..d2691b06700 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/shared_ptr_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(shared_ptr&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr& operator=(shared_ptr&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB(new A);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<A> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp index 98434a380c3..75b20bfd12b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/unique_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB(new B);
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA(new A);
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::unique_ptr<A> pA;
A* ptrA = pA.get();
{
std::shared_ptr<B> pB;
pB = std::move(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 1);
assert(pA.get() == 0);
assert(pB.get() == ptrA);
}
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp index abf973c225f..0196cf9b26b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/const_pointer_cast.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<const A> pA(new A);
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<const A> pA;
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<const A> pA(new A);
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<const A> pA;
std::shared_ptr<A> pB = std::const_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp index ca4975b48c1..ad2b6a4b72e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/dynamic_pointer_cast.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<B> pB(new A);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == pB.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pB(new B);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == 0);
assert(pA.use_count() == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<B> pB(new A);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == pB.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pB(new B);
std::shared_ptr<A> pA = std::dynamic_pointer_cast<A>(pB);
assert(pA.get() == 0);
assert(pA.use_count() == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp index 232d3cae0e8..03146c1c4e2 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cast/static_pointer_cast.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA(new A);
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<A> pA;
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA;
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA(new A);
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<A> pA;
std::shared_ptr<B> pB = std::static_pointer_cast<B>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
{
const std::shared_ptr<B> pA;
std::shared_ptr<A> pB = std::static_pointer_cast<A>(pA);
assert(pB.get() == pA.get());
assert(!pB.owner_before(pA) && !pA.owner_before(pB));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp index 98be66f0416..a8ae78813a8 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/eq.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b);
// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert(p1 != p2);
assert(p2 == p3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b);
// template<class T, class U> bool operator!=(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert(p1 != p2);
assert(p2 == p3);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp index 07620db5830..e5a94e9324b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.cmp/lt.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert((p1 < p2) == (ptr1 < ptr2));
assert(!(p2 < p3) && !(p3 < p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class U> bool operator<(const shared_ptr<T>& a, const shared_ptr<U>& b);
#include <memory>
#include <cassert>
void do_nothing(int*) {}
int main()
{
int* ptr1(new int);
int* ptr2(new int);
const std::shared_ptr<int> p1(ptr1);
const std::shared_ptr<int> p2(ptr2);
const std::shared_ptr<int> p3(ptr2, do_nothing);
assert((p1 < p2) == (ptr1 < ptr2));
assert(!(p2 < p3) && !(p3 < p2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp index b43c164b02d..eca83722175 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp index 4f63d8140ec..fa55289d9f4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/default.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr();
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p;
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr();
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p;
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp index ffab43c7716..6853ca698ab 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr(nullptr_t)
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p(nullptr);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr(nullptr_t)
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p(nullptr);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp index eb498631ba4..6e75c3f2e22 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp index 0bbb8720c95..c27df0e9a37 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp index c4c2201fe54..017fa7aaa95 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp index 19838255763..86e9e7a14d8 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
throw_next = true;
try
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
throw_next = true;
try
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp index caebd4ae700..28a5a57edea 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
A* ptr = new A;
std::shared_ptr<void> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
A* ptr = new A;
std::shared_ptr<void> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp index 1e62565cf50..9db6b0c8d68 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp index e6f39ee2b54..e340c76e248 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp index 40d6aa9d1c7..4fd7f6c1396 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
A* ptr = new A;
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
A* ptr = new A;
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp index ac7f603161a..5596cdaec9b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
A* ptr = new A;
throw_next = true;
try
{
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
A* ptr = new A;
throw_next = true;
try
{
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp index b5b217e4a7d..4b47a5c0aa6 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_throw.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
{
A* ptr = new A;
throw_next = true;
assert(A::count == 1);
try
{
std::shared_ptr<A> p(ptr);
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
}
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
{
A* ptr = new A;
throw_next = true;
assert(A::count == 1);
try
{
std::shared_ptr<A> p(ptr);
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
}
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp index 5cdec2b3884..0ee5cca1dc7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(const shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 1);
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 1);
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(const shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 1);
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 1);
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp index ef79110ca02..a2bc56202bb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp index 66a7b1b78ea..a7b1b1cff05 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_Y_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
B* p = pA.get();
std::shared_ptr<B> pB(std::move(pA));
assert(B::count == 1);
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
#else
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
#endif
assert(p == pB.get());
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
#endif
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
B* p = pA.get();
std::shared_ptr<B> pB(std::move(pA));
assert(B::count == 1);
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
#else
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
#endif
assert(p == pB.get());
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
#endif
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp index 39545a3f128..565d77ff71a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
~B() {--count;}
};
int B::count = 0;
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
{
B b;
std::shared_ptr<B> pB(pA, &b);
assert(A::count == 1);
assert(B::count == 1);
assert(pA.use_count() == 2);
assert(pB.use_count() == 2);
assert(pB.get() == &b);
}
assert(pA.use_count() == 1);
assert(A::count == 1);
assert(B::count == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
~B() {--count;}
};
int B::count = 0;
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
{
B b;
std::shared_ptr<B> pB(pA, &b);
assert(A::count == 1);
assert(B::count == 1);
assert(pA.use_count() == 2);
assert(pB.use_count() == 2);
assert(pB.get() == &b);
}
assert(pA.use_count() == 1);
assert(A::count == 1);
assert(B::count == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp index 2db8fe5a660..f6528b2cb28 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/shared_ptr_rv.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(shared_ptr&& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
A* p = pA.get();
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(pA2.use_count() == 1);
#else
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
#endif
assert(pA2.get() == p);
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(A::count == 1);
#endif
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(shared_ptr&& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
A* p = pA.get();
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(pA2.use_count() == 1);
#else
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
#endif
assert(pA2.get() == p);
}
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(A::count == 0);
#else
assert(pA.use_count() == 1);
assert(A::count == 1);
#endif
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp index c0a2f766280..9f57052860e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
std::shared_ptr<B> p(std::move(ptr));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
std::shared_ptr<B> p(std::move(ptr));
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
std::shared_ptr<B> p(std::move(ptr));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
std::shared_ptr<B> p(std::move(ptr));
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp index 639689c5222..aa9fbf50377 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp(wp);
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp(wp);
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp index acd08849365..49ad98cd279 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/allocate_shared.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class A, class... Args>
// shared_ptr<T> allocate_shared(const A& a, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
#include "../test_allocator.h"
int new_count = 0;
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
assert(test_allocator<A>::alloc_count == 1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class A, class... Args>
// shared_ptr<T> allocate_shared(const A& a, Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
#include "../test_allocator.h"
int new_count = 0;
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
assert(test_allocator<A>::alloc_count == 1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp index 723c9a821f5..2db9c66569e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_count = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_count;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
int nc = new_count;
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::make_shared<A>(i, c);
assert(new_count == nc+1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
int new_count = 0;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
++new_count;
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct A
{
static int count;
A(int i, char c) : int_(i), char_(c) {++count;}
A(const A& a)
: int_(a.int_), char_(a.char_)
{++count;}
~A() {--count;}
int get_int() const {return int_;}
char get_char() const {return char_;}
private:
int int_;
char char_;
};
int A::count = 0;
int main()
{
int nc = new_count;
{
int i = 67;
char c = 'e';
std::shared_ptr<A> p = std::make_shared<A>(i, c);
assert(new_count == nc+1);
assert(A::count == 1);
assert(p->get_int() == 67);
assert(p->get_char() == 'e');
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.dest/tested_elsewhere.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp index ae993c2dd24..c39bec74cd7 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.io/io.pass.cpp @@ -1,6 +1,6 @@ //===----------------------------------------------------------------------===// // -// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp index 1d624b2925d..27d9eb93450 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void reset();
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void reset();
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
p.reset();
assert(A::count == 0);
assert(B::count == 0);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp index 1ee745c8c51..13656f51849 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> void reset(Y* p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> void reset(Y* p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr);
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp index 30a19d151fc..b4bdd8654e5 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> void reset(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> void reset(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp index 67244be1d00..a318f68caf4 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D, class A> void reset(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D, class A> void reset(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<B> p(new B);
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
{
std::shared_ptr<B> p;
A* ptr = new A;
p.reset(ptr, test_deleter<A>(3), test_allocator<A>(4));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 1);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 2);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp index 55111376859..6f75444e632 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void swap(shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// void swap(shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
p1.swap(p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
p1.swap(p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp index 1cc04e0cf6d..14646f0392a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/arrow.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T* operator->() const;
#include <memory>
#include <utility>
#include <cassert>
int main()
{
const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4));
assert(p->first == 3);
assert(p->second == 4);
p->first = 5;
p->second = 6;
assert(p->first == 5);
assert(p->second == 6);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T* operator->() const;
#include <memory>
#include <utility>
#include <cassert>
int main()
{
const std::shared_ptr<std::pair<int, int> > p(new std::pair<int, int>(3, 4));
assert(p->first == 3);
assert(p->second == 4);
p->first = 5;
p->second = 6;
assert(p->first == 5);
assert(p->second == 6);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp index 55b745eb174..b02af0f1cfb 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/dereference.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T& operator*() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(*p == 32);
*p = 3;
assert(*p == 3);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// T& operator*() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(*p == 32);
*p = 3;
assert(*p == 3);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp index 2855d5be0f2..f0661fb318c 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/op_bool.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// explicit operator bool() const;
#include <memory>
#include <cassert>
int main()
{
{
const std::shared_ptr<int> p(new int(32));
assert(p);
}
{
const std::shared_ptr<int> p;
assert(!p);
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// explicit operator bool() const;
#include <memory>
#include <cassert>
int main()
{
{
const std::shared_ptr<int> p(new int(32));
assert(p);
}
{
const std::shared_ptr<int> p;
assert(!p);
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp index 1184b3c8823..b5aeff5e818 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class U> bool owner_before(shared_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
assert(!p1.owner_before(p2));
assert(!p2.owner_before(p1));
assert(p1.owner_before(p3) || p3.owner_before(p1));
assert(p3.owner_before(p1) == p3.owner_before(p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class U> bool owner_before(shared_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
assert(!p1.owner_before(p2));
assert(!p2.owner_before(p1));
assert(p1.owner_before(p3) || p3.owner_before(p1));
assert(p3.owner_before(p1) == p3.owner_before(p2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp index 727b5da1645..8e8059b2056 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class U> bool owner_before(weak_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!p1.owner_before(w2));
assert(!p2.owner_before(w1));
assert(p1.owner_before(w3) || p3.owner_before(w1));
assert(p3.owner_before(w1) == p3.owner_before(w2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template <class U> bool owner_before(weak_ptr<U> const& b) const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!p1.owner_before(w2));
assert(!p2.owner_before(w1));
assert(p1.owner_before(w3) || p3.owner_before(w1));
assert(p3.owner_before(w1) == p3.owner_before(w2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp index 3e3da51e446..429e7e9d58a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/unique.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// bool unique() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(p.unique());
{
std::shared_ptr<int> p2 = p;
assert(!p.unique());
}
assert(p.unique());
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// bool unique() const;
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p(new int(32));
assert(p.unique());
{
std::shared_ptr<int> p2 = p;
assert(!p.unique());
}
assert(p.unique());
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp index 5f73c6fdbee..850125f8cf2 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.spec/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 2);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = new A;
A* ptr2 = 0;
std::shared_ptr<A> p1(ptr1);
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 1);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = new A;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2(ptr2);
swap(p1, p2);
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 1);
}
assert(p1.use_count() == 1);
assert(p1.get() == ptr2);
assert(A::count == 1);
}
assert(A::count == 0);
{
A* ptr1 = 0;
A* ptr2 = 0;
std::shared_ptr<A> p1;
{
std::shared_ptr<A> p2;
swap(p1, p2);
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(p2.use_count() == 0);
assert(p2.get() == ptr1);
assert(A::count == 0);
}
assert(p1.use_count() == 0);
assert(p1.get() == ptr2);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp index 051a4408e9b..359bfa7c48a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/types.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// {
// public:
// typedef T element_type;
// ...
// };
#include <memory>
struct A; // purposefully incomplete
int main()
{
static_assert((std::is_same<std::weak_ptr<A>::element_type, A>::value), "");
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp index f2f436b7a36..eb16e033d04 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> struct owner_less;
//
// template <class T>
// struct owner_less<shared_ptr<T> >
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
//
// template <class T>
// struct owner_less<weak_ptr<T> >
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
{
typedef std::owner_less<std::shared_ptr<int> > CS;
CS cs;
assert(!cs(p1, p2));
assert(!cs(p2, p1));
assert(cs(p1 ,p3) || cs(p3, p1));
assert(cs(p3, p1) == cs(p3, p2));
assert(!cs(p1, w2));
assert(!cs(p2, w1));
assert(cs(p1, w3) || cs(p3, w1));
assert(cs(p3, w1) == cs(p3, w2));
}
{
typedef std::owner_less<std::weak_ptr<int> > CS;
CS cs;
assert(!cs(w1, w2));
assert(!cs(w2, w1));
assert(cs(w1, w3) || cs(w3, w1));
assert(cs(w3, w1) == cs(w3, w2));
assert(!cs(w1, p2));
assert(!cs(w2, p1));
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> struct owner_less;
//
// template <class T>
// struct owner_less<shared_ptr<T> >
// : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
//
// template <class T>
// struct owner_less<weak_ptr<T> >
// : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
// {
// typedef bool result_type;
// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
// };
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
{
typedef std::owner_less<std::shared_ptr<int> > CS;
CS cs;
assert(!cs(p1, p2));
assert(!cs(p2, p1));
assert(cs(p1 ,p3) || cs(p3, p1));
assert(cs(p3, p1) == cs(p3, p2));
assert(!cs(p1, w2));
assert(!cs(p2, w1));
assert(cs(p1, w3) || cs(p3, w1));
assert(cs(p3, w1) == cs(p3, w2));
}
{
typedef std::owner_less<std::weak_ptr<int> > CS;
CS cs;
assert(!cs(w1, w2));
assert(!cs(w2, w1));
assert(cs(w1, w3) || cs(w3, w1));
assert(cs(w3, w1) == cs(w3, w2));
assert(!cs(w1, p2));
assert(!cs(w2, p1));
assert(cs(w1, p3) || cs(w3, p1));
assert(cs(w3, p1) == cs(w3, p2));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp index 02dc7e812b8..87569aadb20 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> pA(new A);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp index 0e9859bec34..853d43265ea 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr& operator=(const weak_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr& operator=(const weak_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<A> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp index 1d062145304..85461b90f7e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.assign/weak_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr& operator=(const weak_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
{
std::weak_ptr<B> pB;
pB = pA;
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp index 576ec0c98f9..ef62c139a7e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/default.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// weak_ptr();
#include <memory>
#include <cassert>
struct A;
int main()
{
std::weak_ptr<A> p;
assert(p.use_count() == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class T> class weak_ptr
// weak_ptr();
#include <memory>
#include <cassert>
struct A;
int main()
{
std::weak_ptr<A> p;
assert(p.use_count() == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp index 15a5c1cacd5..1efdb03774b 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/shared_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp index 2b49b9706fa..fabf4324536 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr(const weak_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// weak_ptr(const weak_ptr& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
{
const std::shared_ptr<A> ps(new A);
const std::weak_ptr<A> pA(ps);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 1);
assert(pA.use_count() == 1);
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp index 415ee71cc85..8b2db201d6d 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.const/weak_ptr_Y.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::weak_ptr<A> pA(std::shared_ptr<A>(new A));
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class Y> weak_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::weak_ptr<A>, std::weak_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<B>, std::weak_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::weak_ptr<A>, std::weak_ptr<C> >::value), "");
{
const std::weak_ptr<A> pA(std::shared_ptr<A>(new A));
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::weak_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp index 92348261209..e8db90cbee0 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.dest/tested_elsewhere.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp index 9fcb90994c8..50aa527232a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/reset.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p1(new A);
std::weak_ptr<A> w1(p1);
assert(w1.use_count() == 1);
w1.reset();
assert(w1.use_count() == 0);
assert(p1.use_count() == 1);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p1(new A);
std::weak_ptr<A> w1(p1);
assert(w1.use_count() == 1);
w1.reset();
assert(w1.use_count() == 0);
assert(p1.use_count() == 1);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp index 7ee2277e281..1bd3a3f6c50 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.mod/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
w1.swap(w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// void swap(weak_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
w1.swap(w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp index 59f5388719f..3d93fb93e9e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/expired.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// bool expired() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
assert(wp.use_count() == 1);
assert(wp.expired() == (wp.use_count() == 0));
sp0.reset();
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// bool expired() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
assert(wp.use_count() == 1);
assert(wp.expired() == (wp.use_count() == 0));
sp0.reset();
assert(wp.use_count() == 0);
assert(wp.expired() == (wp.use_count() == 0));
}
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp index fc7e338e6b7..c68792058fc 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/lock.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// shared_ptr<T> lock() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// shared_ptr<T> lock() const;
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
std::shared_ptr<A> sp = wp.lock();
assert(sp.use_count() == 0);
assert(sp.get() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp index aa3aad73b4a..18bacf4a43a 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/not_less_than.fail.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> class weak_ptr;
//
// not less than comparable
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
bool b = w1 < w2;
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class T> class weak_ptr;
//
// not less than comparable
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
bool b = w1 < w2;
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp index 307dba53285..e3ad3807ea3 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const shared_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(p2));
assert(!w2.owner_before(p1));
assert(w1.owner_before(p3) || w3.owner_before(p1));
assert(w3.owner_before(p1) == w3.owner_before(p2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const shared_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(p2));
assert(!w2.owner_before(p1));
assert(w1.owner_before(p3) || w3.owner_before(p1));
assert(w3.owner_before(p1) == w3.owner_before(p2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp index a2603af6ff2..6f123821233 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const weak_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(w2));
assert(!w2.owner_before(w1));
assert(w1.owner_before(w3) || w3.owner_before(w1));
assert(w3.owner_before(w1) == w3.owner_before(w2));
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class U> bool owner_before(const weak_ptr<U>& b);
#include <memory>
#include <cassert>
int main()
{
const std::shared_ptr<int> p1(new int);
const std::shared_ptr<int> p2 = p1;
const std::shared_ptr<int> p3(new int);
const std::weak_ptr<int> w1(p1);
const std::weak_ptr<int> w2(p2);
const std::weak_ptr<int> w3(p3);
assert(!w1.owner_before(w2));
assert(!w2.owner_before(w1));
assert(w1.owner_before(w3) || w3.owner_before(w1));
assert(w3.owner_before(w1) == w3.owner_before(w2));
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp index b02f4eaf7c8..c349f90b638 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.spec/swap.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b)
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
swap(w1, w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// weak_ptr
// template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b)
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr1 = new A;
A* ptr2 = new A;
std::shared_ptr<A> p1(ptr1);
std::weak_ptr<A> w1(p1);
{
std::shared_ptr<A> p2(ptr2);
std::weak_ptr<A> w2(p2);
swap(w1, w2);
assert(w1.use_count() == 1);
assert(w1.lock().get() == ptr2);
assert(w2.use_count() == 1);
assert(w2.lock().get() == ptr1);
assert(A::count == 2);
}
}
assert(A::count == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp index d0de482c2d0..ae75b4fe810 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.weakptr/bad_weak_ptr.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// class bad_weak_ptr
// : public std::exception
// {
// public:
// bad_weak_ptr();
// };
#include <memory>
#include <type_traits>
#include <cassert>
#include <cstring>
int main()
{
static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), "");
std::bad_weak_ptr e;
std::bad_weak_ptr e2 = e;
e2 = e;
assert(std::strcmp(e.what(), "bad_weak_ptr") == 0);
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// class bad_weak_ptr
// : public std::exception
// {
// public:
// bad_weak_ptr();
// };
#include <memory>
#include <type_traits>
#include <cassert>
#include <cstring>
int main()
{
static_assert((std::is_base_of<std::exception, std::bad_weak_ptr>::value), "");
std::bad_weak_ptr e;
std::bad_weak_ptr e2 = e;
e2 = e;
assert(std::strcmp(e.what(), "bad_weak_ptr") == 0);
}
\ No newline at end of file diff --git a/libcxx/test/utilities/memory/version.pass.cpp b/libcxx/test/utilities/memory/version.pass.cpp index dab60f92e6d..e05afd07802 100644 --- a/libcxx/test/utilities/memory/version.pass.cpp +++ b/libcxx/test/utilities/memory/version.pass.cpp @@ -1 +1 @@ -//===----------------------------------------------------------------------===//
//
// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
#include <memory>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file +//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
#include <memory>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}
\ No newline at end of file |