diff options
author | Howard Hinnant <hhinnant@apple.com> | 2010-08-22 00:59:46 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2010-08-22 00:59:46 +0000 |
commit | 94b2dd0998230c758abd92c99d3700c971f7a31a (patch) | |
tree | 1b9f66ba0b4f8fd99fc02a112d4b7a30c4afe0f6 /libcxx/test/utilities/memory | |
parent | d9c6c0b583ac1f1efeec3db571a1028a3c9b7a99 (diff) | |
download | bcm5719-llvm-94b2dd0998230c758abd92c99d3700c971f7a31a.tar.gz bcm5719-llvm-94b2dd0998230c758abd92c99d3700c971f7a31a.zip |
Fixing whitespace problems
llvm-svn: 111767
Diffstat (limited to 'libcxx/test/utilities/memory')
304 files changed, 15523 insertions, 309 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 a75ae54444e..19b81a8a5a3 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 @@ -108,5 +108,5 @@ int main() std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(5), A3<int>(6)))); } -#endif +#endif // _LIBCPP_MOVE } 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 64296e3ec7c..49ea9c0679e 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 @@ -65,5 +65,5 @@ int main() assert(a2 == a1); } -#endif +#endif // _LIBCPP_MOVE } 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 2fae9037ad3..0db40da6ba7 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 @@ -71,5 +71,5 @@ int main() assert(a2 == a1); } -#endif +#endif // _LIBCPP_MOVE } 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 1bf66370dfa..6db3d3a657e 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 @@ -66,5 +66,5 @@ int main() assert(a2 == a1); } -#endif +#endif // _LIBCPP_MOVE } 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 eeac01607ca..26dc7f55171 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 @@ -54,5 +54,5 @@ int main() assert(A3<int>::move_called == false); } -#endif +#endif // _LIBCPP_MOVE } 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 220306824f0..1a433cfa453 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 @@ -45,5 +45,5 @@ int main() assert(A1<int>::allocate_called == true); } -#endif +#endif // _LIBCPP_MOVE } 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 9ea3da8011c..43916cb0bba 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 @@ -66,5 +66,5 @@ int main() assert(a.allocate(10, (const void*)20) == (int*)20); assert(A2<int>::allocate_called == true); } -#endif +#endif // _LIBCPP_MOVE } 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 47d3be53c0a..56306f29c16 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 @@ -111,7 +111,7 @@ struct F bool F::constructed = false; -#endif +#endif // _LIBCPP_MOVE int main() { @@ -189,5 +189,5 @@ int main() s->~S(); } -#endif +#endif // _LIBCPP_MOVE } 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 c123cd8b9e9..137d8011d96 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 @@ -42,5 +42,5 @@ int main() assert((A1<int>::deallocate_called == std::pair<int*, std::size_t>((int*)10, 20))); } -#endif +#endif // _LIBCPP_MOVE } 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 6456c12cf99..9201e16eaed 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 @@ -66,5 +66,5 @@ int main() assert(A3<S>::destroy_called); } -#endif +#endif // _LIBCPP_MOVE } 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 85b7724087f..1eef5beed9a 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 @@ -41,5 +41,5 @@ int main() std::scoped_allocator_adaptor<A2<int>, A3<int>>(A2<int>(6), A3<int>(8)))); } -#endif +#endif // _LIBCPP_MOVE } 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 8c2db74bdca..22655a36397 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 @@ -39,5 +39,5 @@ int main() assert(a.max_size() == 200); } -#endif +#endif // _LIBCPP_MOVE } 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 61ac84738d2..23ab0e59961 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 @@ -40,5 +40,5 @@ int main() assert(a.outer_allocator() == A1<int>(5)); } -#endif +#endif // _LIBCPP_MOVE } 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 883d57360d3..a5d5b109b81 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 @@ -51,5 +51,5 @@ int main() assert(a2.inner_allocator().inner_allocator().outer_allocator().id() == -1); } -#endif +#endif // _LIBCPP_MOVE } 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 952e31ddd8d..416ac524127 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 @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::inner_allocator_type, std::scoped_allocator_adaptor<A2<int>, A3<int>>>::value), ""); -#endif +#endif // _LIBCPP_MOVE } 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 479f65496dd..46ae7812eb6 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 @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_copy_assignment, std::true_type>::value), ""); -#endif +#endif // _LIBCPP_MOVE } 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 d443b0bfbbd..664c27bd787 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 @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_move_assignment, std::true_type>::value), ""); -#endif +#endif // _LIBCPP_MOVE } 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 76da120de9b..585bd14bc50 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 @@ -35,5 +35,5 @@ int main() std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>>::propagate_on_container_swap, std::true_type>::value), ""); -#endif +#endif // _LIBCPP_MOVE } diff --git a/libcxx/test/utilities/memory/allocator.adaptor/allocators.h b/libcxx/test/utilities/memory/allocator.adaptor/allocators.h index 7075f85e222..0e4b7f3299d 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/allocators.h +++ b/libcxx/test/utilities/memory/allocator.adaptor/allocators.h @@ -150,8 +150,6 @@ public: A3 select_on_container_copy_construction() const {return A3(-1);} }; - - template <class T> bool A3<T>::copy_called = false; template <class T> bool A3<T>::move_called = false; template <class T> bool A3<T>::constructed = false; @@ -171,6 +169,6 @@ bool operator!=(const A3<T>& x, const A3<U>& y) return !(x == y); } -#endif +#endif // _LIBCPP_MOVE -#endif +#endif // ALLOCATORS_H diff --git a/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp b/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp index af1e3d24b21..61a347f5ff0 100644 --- a/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp +++ b/libcxx/test/utilities/memory/allocator.adaptor/types.pass.cpp @@ -65,7 +65,6 @@ int main() std::scoped_allocator_adaptor<A1<int>>::const_void_pointer, const void*>::value), ""); - static_assert((std::is_base_of< A2<int>, std::scoped_allocator_adaptor<A2<int>, A1<int>> @@ -99,5 +98,5 @@ int main() std::scoped_allocator_adaptor<A2<int>, A1<int>>::const_void_pointer, const void*>::value), ""); -#endif +#endif // _LIBCPP_MOVE } 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 fb0b9f69aa5..43331ab35d0 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,22 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 c797b1020bc..ebbfa15d7c5 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,38 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 9847c2a6053..527f51b1e59 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class 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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE + B<int> b; + assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF); +} 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 4dda58f8c7a..e2d510e1ef5 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,143 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_VARIADICS +}; + +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 // _LIBCPP_HAS_NO_VARIADICS +} 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 b4bd79a96e3..33ea63cc164 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,42 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 7996ea42033..d9e8de55e2a 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,80 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} 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 c021ea8c108..1a03f735762 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,64 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + 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); + } +} 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 8fe2365bc10..358017bc520 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,68 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} 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 680583ac3a8..5573fcbfb1b 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,55 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 afa0cf29d1e..2c881016a3b 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,55 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 7eab2fc5af5..460f47804c0 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,40 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 6b479cee2a7..a41eabf82ed 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,42 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 8340b582373..0e9a64c148e 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,40 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 827201625cd..d389f17e790 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,40 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 7c4d36afe0a..193dedde825 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,40 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 443ce269725..82fcb71f153 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,79 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + 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 // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} 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 2eef5d435c7..148daacb547 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,39 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 e08dd388b4f..f5ed6a398dd 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,55 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 df2539a3a33..3df8b01ff92 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 6a4dd13df80..8e99e7f923b 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,79 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + 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 // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} 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 20015088451..b91467faf3b 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 23aa45e31bb..99167b71bbd 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,33 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 27846cf94e6..a98f3353ed1 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,14 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 49d39da4034..6712a8d0d9b 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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)); +} 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 c14607f6cfb..5cb4f950160 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,39 @@ -//===----------------------------------------------------------------------===//
//
// 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>(); +} 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 161d3835b3f..84786a813c3 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,63 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 bf6e20ab1f6..c0bea03799e 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,153 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_MOVE + move_only(move_only&); + move_only& operator=(move_only&); +#endif // _LIBCPP_MOVE + +public: + +#ifdef _LIBCPP_MOVE + move_only(move_only&&) {++move_only_constructed;} + move_only& operator=(move_only&&) {} +#else // _LIBCPP_MOVE + operator std::__rv<move_only> () {return std::__rv<move_only>(*this);} + move_only(std::__rv<move_only>) {++move_only_constructed;} +#endif // _LIBCPP_MOVE + + 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); + } +} 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 eb596f42f2c..7e958ee0ed0 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,27 @@ -//===----------------------------------------------------------------------===//
//
// 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()); +} 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 7ee46ff06fc..b62a5ef2c04 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,49 @@ -//===----------------------------------------------------------------------===//
//
// 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; +} 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 79b0690f3a9..f0af8879f68 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,36 @@ -//===----------------------------------------------------------------------===//
//
// 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; +} 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 f28e42f28bd..820b75f6439 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,25 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 e944dc8ff35..cf1ddd865c3 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,25 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} diff --git a/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp index 34fa69454ab..13d15b53d8d 100644 --- a/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/pointer.pass.cpp @@ -1 +1,32 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 8ed66297f31..10cdb897002 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,48 @@ -//===----------------------------------------------------------------------===//
//
// 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; + } +} 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 e2a78d1ddfa..49439dd3701 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,48 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 ca464370c6e..eb48fa26de4 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,49 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 ca8a3a27629..4095754c255 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,69 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_HAS_NO_TEMPLATE_ALIASES + 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 // _LIBCPP_HAS_NO_TEMPLATE_ALIASES +} 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 42fd9300b7d..557bf36b976 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,32 @@ -//===----------------------------------------------------------------------===//
//
// 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; + } +} diff --git a/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp b/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp index f63c03521a0..d3a4d794f90 100644 --- a/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp +++ b/libcxx/test/utilities/memory/pointer.traits/rebind.pass.cpp @@ -1 +1,29 @@ -//===----------------------------------------------------------------------===//
//
// 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 +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 c4b14d3160c..6f1b01163de 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,33 @@ -//===----------------------------------------------------------------------===//
//
// 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; +} 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 d592386557a..401a3948504 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,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class 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); +} 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 0971c61b402..8d51e755141 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,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class 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); +} 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 15518e00f71..1f48d886e53 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,49 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 eaaa6ca8188..83d2d257714 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,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class 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); +} 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 3f356890915..40792d2c324 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,44 @@ -//===----------------------------------------------------------------------===//
//
// 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); + } +} 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 129bae834b9..8e923695c0c 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,29 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} diff --git a/libcxx/test/utilities/memory/unique.ptr/deleter.h b/libcxx/test/utilities/memory/unique.ptr/deleter.h index df8b894e1e2..f14c74f87d1 100644 --- a/libcxx/test/utilities/memory/unique.ptr/deleter.h +++ b/libcxx/test/utilities/memory/unique.ptr/deleter.h @@ -1 +1,181 @@ -//===----------------------------------------------------------------------===//
//
// 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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // DELETER_H 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 c96b5b980ba..ac9b3741f25 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,48 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 5f033a36893..e7b1013f06b 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,34 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 a1662526860..a7a3beab0a4 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,26 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 e1248de8712..edb1dd84d8c 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,32 @@ -//===----------------------------------------------------------------------===//
//
// 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; +} 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 1b41e961912..1b11d6a2512 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,36 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 6fcb94c5637..b01a1dd6c1d 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,26 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 6360686f745..cb123994aa4 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,38 @@ -//===----------------------------------------------------------------------===//
//
// The 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; + } +} 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 dfd6a7136ae..0a9a63be405 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 5e1e5f81483..d343716c741 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,38 @@ -//===----------------------------------------------------------------------===//
//
// The 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; + } +} 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 594704f2a83..53f93869b4d 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 89267738d13..0f0c17682a4 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 45196b630fb..f2792b98833 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 9831ab2283b..e7f64f409a0 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 67e5f36435d..c408e4be07b 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 64aff20ef4a..b0e2a53d941 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 96ef756e099..4bcd542126a 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 5ecec761ae4..bf2090a6175 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 5e959134c66..7d523ea849d 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e408aae3f9d..8d90354d3dd 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,59 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 a1328d62a6f..1f170d110f6 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 da5d287e4c7..7f328176189 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,41 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 31248d50912..d86b812b30f 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,44 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 a168fdc01ca..1f6d406784b 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,41 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 690237e5833..d4bfb8fab5f 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,34 @@ -//===----------------------------------------------------------------------===//
//
// The 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), ""); + } +} 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 4a8c0915405..a748150b65f 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,36 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 280cfd235d6..fa37e3da07d 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,47 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 b94f9b9c24d..623df931a74 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,30 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 41d143996af..98800cc40ac 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,87 @@ -//===----------------------------------------------------------------------===//
//
// The 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() {} 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 dfa0434ee70..5ab1bbea6b9 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,23 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 b9c23628c79..14f89e317b3 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,42 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 f58b18f90dd..661fdab314b 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,85 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 9d387d97a01..8299de7e933 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,42 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 0cf6da30b3f..6a89015d972 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,87 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d3df6146625..f63b7eb8b21 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 6d11937f567..5a601fd8290 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 9a580449fdd..05f8ce02416 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 86a2cf68ed6..0487804ded6 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 9822dc2b3ba..d5d330ad960 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 b0a9bc71075..b423386d31b 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 983d6c8c51d..d55aac8ba3a 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 ae87cfe2f56..004e5d0a85c 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 ce5883a9ad6..164fa4a3aff 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 3203f29e82f..b3a9ce424cd 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d2c5eb92224..b81dd40f7d1 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 ec576470bc1..4d45411901b 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 f3c299c0bab..c3641f86e64 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 26b925da4a8..e429fa88877 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 a6040720ef6..25bdf3dbe0c 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 2b5b27c68c4..74172f3773f 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 ddcdb453a6b..4cbb9950bce 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d9f4d99ad7e..7ce70fbc8c1 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 96ebb838013..002946311af 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 2852c472e6d..ecb76a0b37e 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d0fdb9a2d9d..62e777a4af8 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,46 @@ -//===----------------------------------------------------------------------===//
//
// 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); + } +} 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 bdcd371b5be..14bdf5ba8af 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,36 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 25e41cace94..9b00c50b09f 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,63 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 8f3767dc5f7..804ed5b5efa 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,29 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 f70f9851e10..619b0b06373 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,95 @@ -//===----------------------------------------------------------------------===//
//
// The 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() {} 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 35c1c764e46..650cab49459 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,23 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 507610bb2ab..ddc32d8cf57 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,67 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 4d27319f3ba..73f2b1a7ced 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,43 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e25c5b1f8ea..ffa1c1df136 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,58 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 8f4594c5f78..f6907357769 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 42b84c174c5..24d563059ad 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 34b426e16d9..67402064a6a 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,58 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 66a314ae656..b5eeb5c755a 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,58 @@ -//===----------------------------------------------------------------------===//
//
// The 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()); +} 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 1f80c9e5a1a..560ba3cce7e 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,27 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 1cbea933a87..3c69b19aa90 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,48 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 43bb562e7f4..feae9690f93 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,64 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 07eac0228b3..0c63780b3a9 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 5bfb4de49d0..89597fad43f 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,23 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 f3b7f01d829..4a4f6c062b1 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,39 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 5ed1a201a3e..015ea2fbfd0 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,24 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 0d58c7ac2ce..3e74775d2ba 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,37 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 95ad2f26fb3..61e400ade59 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,47 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 f8973e17504..ad0cf3984a4 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,30 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 daa83841cd7..05d6d1f37be 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,34 @@ -//===----------------------------------------------------------------------===//
//
// The 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), ""); + } +} 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 6360686f745..cb123994aa4 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,38 @@ -//===----------------------------------------------------------------------===//
//
// The 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; + } +} 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 94c8b5b1581..7d3bff0ddc9 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,74 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e245105ae40..73e608d6340 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,38 @@ -//===----------------------------------------------------------------------===//
//
// The 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; + } +} 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 594704f2a83..53f93869b4d 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 89267738d13..0f0c17682a4 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 dc9e6cc731e..4dff75cf66f 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 68aa7be4f8d..7fd7acb0c93 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 01cdc5754b2..fb1a4491e30 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 97217d0ac42..337d3f07971 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,59 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e5b5cb25418..94a0275fa01 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 2c421dfe3e6..880ba2ac066 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,62 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 eef44ceb783..7708ab3fb1d 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,56 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d796ba36cf3..bb821583fbb 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 0400cbdb7dd..91c2c04a449 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 7ec9e00ef79..af293c22d1b 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,35 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 da5d287e4c7..7f328176189 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,41 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 3000f7448db..5627e1a2305 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,41 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e12717599a3..62f1c60c3f9 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,67 @@ -//===----------------------------------------------------------------------===//
//
// The 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(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);
{
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(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); + { + 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); +} 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 a13af5b9d0b..d11eecb92db 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,67 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 9580723069b..cda17b20115 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d9e9d479f52..fb380ec07b6 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,35 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 e0178ba2f5d..48c7fadf35c 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,46 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 1255c5c0c03..66df19698ac 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,29 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 90cf3752937..67332e4bbdd 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,84 @@ -//===----------------------------------------------------------------------===//
//
// The 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() {} 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 f8de7af2fb2..af86c25a117 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,23 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 5d7b6232203..41e4254a9b4 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,42 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 7d3484d54e3..f3bcbcf23c2 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,141 @@ -//===----------------------------------------------------------------------===//
//
// The 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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +int main() +{ + { + std::unique_ptr<A> s(new A); + A* p = s.get(); + std::unique_ptr<A> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + } + assert(A::count == 0); + { + std::unique_ptr<A, Deleter<A> > s(new A); + A* p = s.get(); + std::unique_ptr<A, Deleter<A> > s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter d; + std::unique_ptr<A, CDeleter&> s(new A, d); + A* p = s.get(); + std::unique_ptr<A, CDeleter&> s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == 1); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); +} diff --git a/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 84470c9e4f2..bf2dd807077 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,42 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 5abbb7776a2..e0d8c5acf3f 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,143 @@ -//===----------------------------------------------------------------------===//
//
// The 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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +class CDeleter +{ + int state_; + + CDeleter(CDeleter&); + CDeleter& operator=(CDeleter&); +public: + + CDeleter() : state_(5) {} + + int state() const {return state_;} + void set_state(int s) {state_ = s;} + + void operator()(A* p) {delete p;} +}; + +std::unique_ptr<A> +source1() +{ + return std::unique_ptr<A>(new A); +} + +void sink1(std::unique_ptr<A> p) +{ +} + +std::unique_ptr<A, Deleter<A> > +source2() +{ + return std::unique_ptr<A, Deleter<A> >(new A); +} + +void sink2(std::unique_ptr<A, Deleter<A> > p) +{ +} + +std::unique_ptr<A, CDeleter&> +source3() +{ + static CDeleter d; + return std::unique_ptr<A, CDeleter&>(new A, d); +} + +void sink3(std::unique_ptr<A, CDeleter&> p) +{ +} + +int main() +{ + sink1(source1()); + sink2(source2()); + sink3(source3()); + assert(A::count == 0); +} diff --git a/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 d6bffbec699..5926b9ae551 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 876b5899349..dfec0c3b63e 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 7454a2cc543..6dd63a58466 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 a82e3f8f1b9..7254261d656 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 85388db4d5a..4a631eed7cd 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 091e3fbee97..d084f63b0fa 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 0fb4a4cd058..0435e73631d 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 ecda031dbf6..0accb534f86 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 58a911a6dd2..c691d72cf97 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 79b616139e3..94f932eebe7 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 591bc79bc47..540ece084b7 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,50 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 e4faba25b6e..ee1d80fc2fd 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 9fd6649dbd4..d204c0e4dfe 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 4961a53a669..55aa13d7354 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d05e81e45e7..54bc4e9f9b2 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 3ef4da00c71..1d4ec6d974a 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,62 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 cdd0fd7f0eb..1da66eaef73 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,117 @@ -//===----------------------------------------------------------------------===//
//
// The 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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +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); +} 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 18a7b07e0d4..f79b52ff01b 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 0bed30c2c26..9fd1e910817 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,57 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 3b7d5f81672..fe981de133d 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,117 @@ -//===----------------------------------------------------------------------===//
//
// The 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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +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); +} 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 42d7a189a11..8534110b932 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e5b666e581b..ee02f0d0256 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,34 @@ -//===----------------------------------------------------------------------===//
//
// The 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)); +} 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 c49c9c8deca..f4f6662cf65 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,46 @@ -//===----------------------------------------------------------------------===//
//
// 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); + } +} 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 eaffc6dc2a6..08b7ef29bb9 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,35 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 74f4f7fbfa7..b1c2b120839 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,63 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 7780932a4b5..d25470b4f70 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,29 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 f8ff88d2e86..7a5b75cba1e 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,95 @@ -//===----------------------------------------------------------------------===//
//
// The 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() {} 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 f3f09535b33..32e66471cc2 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,23 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 ef4542564e0..1608adee945 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,78 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 8305a399a3c..1faff87269a 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,99 @@ -//===----------------------------------------------------------------------===//
//
// The 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 // _LIBCPP_MOVE + Deleter(Deleter&); + Deleter& operator=(Deleter&); +#endif // _LIBCPP_MOVE + +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 // _LIBCPP_MOVE + operator std::__rv<Deleter>() {return std::__rv<Deleter>(*this);} + Deleter(std::__rv<Deleter> r) : state_(r->state_) {r->state_ = 0;} + Deleter& operator=(std::__rv<Deleter> r) + { + state_ = r->state_; + r->state_ = 0; + return *this; + } +#endif // _LIBCPP_MOVE + + 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 // _LIBCPP_MOVE + template <class U> + Deleter(Deleter<U> d, + typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) + : state_(d.state()) {} +#endif // _LIBCPP_MOVE +public: + int state() const {return state_;} + void set_state(int i) {state_ = i;} + + void operator()(T* p) {delete p;} +}; + +int main() +{ + { + A* p = new A; + assert(A::count == 1); + std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>()); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); +} diff --git a/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 e5c9e24a72d..2372d9edbf3 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,58 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 d94eaaf2f29..4ad22d495c9 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 0912ba9aa3a..6a617875fdd 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,55 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 b5ff2702579..3c03340ec62 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,58 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 93d324285c4..37d4f125af9 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,66 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 527666fa4df..e802e9e5d14 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,39 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 20f3d00f4aa..a530351df93 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,44 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 da593d124be..d0df6073d70 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,27 @@ -//===----------------------------------------------------------------------===//
//
// The 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; +} 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 806b5d787e6..29419317b31 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,48 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 78da880bc22..e43fa1a2bc1 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,64 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 c31c56fa127..23e419e5e43 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,29 @@ -//===----------------------------------------------------------------------===//
//
// The 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(); +} 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 853273aef2d..03ea92411bf 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,59 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 08092ec2ab1..b70f865d5b7 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,23 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 3fbfb3826a5..7982f9e59a0 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,39 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 d453724c0e8..62bc3269e68 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,24 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 8cefe172f38..34504b6b8c9 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,37 @@ -//===----------------------------------------------------------------------===//
//
// The 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); + } +} 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 4e9657067ed..93807cc1874 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,47 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 4a00ea233e5..eb63dc2444b 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,30 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 683378ec140..595e5777f92 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,86 @@ -//===----------------------------------------------------------------------===//
//
// 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)); + } +} 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 93052283ae3..a9a197be90a 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,100 @@ -//===----------------------------------------------------------------------===//
//
// 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)); + } +} 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 c0bdfea88ca..a38910e56dd 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,77 @@ -//===----------------------------------------------------------------------===//
//
// The 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); +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 d4618719cfb..c3aa6b06556 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,49 @@ -//===----------------------------------------------------------------------===//
//
// 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 + } +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp index 9912d1b8f22..ec12d286f69 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// 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 hash<shared_ptr<T>>
// {
// typedef shared_ptr<T> argument_type;
// typedef size_t result_type;
// size_t operator()(const shared_ptr<T>& p) const;
// };
#include <memory>
#include <cassert>
int main()
{
int* ptr = new int;
std::shared_ptr<int> p(ptr);
std::hash<std::shared_ptr<int> > f;
std::size_t h = f(p);
assert(h == std::hash<int*>()(ptr));
}
\ No newline at end 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 hash<shared_ptr<T>> +// { +// typedef shared_ptr<T> argument_type; +// typedef size_t result_type; +// size_t operator()(const shared_ptr<T>& p) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + int* ptr = new int; + std::shared_ptr<int> p(ptr); + std::hash<std::shared_ptr<int> > f; + std::size_t h = f(p); + assert(h == std::hash<int*>()(ptr)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp index 0541e57a8a2..c8e13b2bc4e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp @@ -1 +1,30 @@ -//===----------------------------------------------------------------------===//
//
// 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 D>
// struct hash<unique_ptr<T, D>>
// {
// typedef unique_ptr<T, D> argument_type;
// typedef size_t result_type;
// size_t operator()(const unique_ptr<T, D>& p) const;
// };
#include <memory>
#include <cassert>
int main()
{
int* ptr = new int;
std::unique_ptr<int> p(ptr);
std::hash<std::unique_ptr<int> > f;
std::size_t h = f(p);
assert(h == std::hash<int*>()(ptr));
}
\ No newline at end 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 D> +// struct hash<unique_ptr<T, D>> +// { +// typedef unique_ptr<T, D> argument_type; +// typedef size_t result_type; +// size_t operator()(const unique_ptr<T, D>& p) const; +// }; + +#include <memory> +#include <cassert> + +int main() +{ + int* ptr = new int; + std::unique_ptr<int> p(ptr); + std::hash<std::unique_ptr<int> > f; + std::size_t h = f(p); + assert(h == std::hash<int*>()(ptr)); +} diff --git a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h index 0c1eaf3dc90..795f6e1f77e 100644 --- a/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h +++ b/libcxx/test/utilities/memory/util.smartptr/util.smartptr.shared/test_allocator.h @@ -74,4 +74,4 @@ public: {return !(x == y);} }; -#endif +#endif // TEST_ALLOCATOR_H 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 b9aeeebcd66..0a8b08eebcb 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,60 @@ -//===----------------------------------------------------------------------===//
//
// 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 // DELETER_H 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 09aa877d2cd..ff1424c5c4e 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,26 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 e12dc2fa6c7..84356569c1c 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,67 @@ -//===----------------------------------------------------------------------===//
//
// 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); + } +} 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 09a95ec2478..27732823300 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,113 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 8e1bb81afcc..45dbc060e1f 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,121 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 a13b1fd2fef..be6b1659571 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,121 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 e4142cda701..8a72f6c0185 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,121 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 d2691b06700..3e8a51fcc0a 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,121 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 75b20bfd12b..11ad6021103 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,113 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 0196cf9b26b..9b98af0edab 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,57 @@ -//===----------------------------------------------------------------------===//
//
// 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)); + } +} 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 ad2b6a4b72e..1f99c8c991b 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,57 @@ -//===----------------------------------------------------------------------===//
//
// 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); + } +} 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 03146c1c4e2..f67c54b4398 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,69 @@ -//===----------------------------------------------------------------------===//
//
// 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)); + } +} 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 a8ae78813a8..692dec7dcb4 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 e5a94e9324b..8c328fdc91e 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,30 @@ -//===----------------------------------------------------------------------===//
//
// 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)); +} 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 eca83722175..dcc594e132e 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,94 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(auto_ptr<Y>&& r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::auto_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
#ifdef _LIBCPP_MOVE
std::shared_ptr<B> p(std::move(ptr));
#else
std::shared_ptr<B> p(ptr);
#endif
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end 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); +} 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 fa55289d9f4..50f3195def0 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,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr();
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p;
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end 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); +} 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 6853ca698ab..4a442157d61 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,22 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr(nullptr_t)
#include <memory>
#include <cassert>
int main()
{
std::shared_ptr<int> p(nullptr);
assert(p.use_count() == 0);
assert(p.get() == 0);
}
\ No newline at end 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); +} 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 6e75c3f2e22..025d09f55c4 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,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end 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); +} 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 c27df0e9a37..1eeb3cefc1f 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,50 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 0);
assert(p.use_count() == 1);
assert(p.get() == 0);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end 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); +} 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 017fa7aaa95..e3f1a5a8e8c 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,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class D, class A> shared_ptr(nullptr_t, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(nullptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end 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); + } +} 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 86e9e7a14d8..878c417876d 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class D> shared_ptr(nullptr_t, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
throw_next = true;
try
{
std::shared_ptr<A> p(nullptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end 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); + } +} 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 28a5a57edea..ed6396ef750 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,46 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
{
A* ptr = new A;
std::shared_ptr<void> p(ptr);
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
}
assert(A::count == 0);
}
\ No newline at end 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); +} 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 9db6b0c8d68..d75d46ad686 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,48 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
\ No newline at end 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); +} 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 e340c76e248..08d1d6f84b2 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,51 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
A* ptr = new A;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(A::count == 1);
assert(p.use_count() == 1);
assert(p.get() == ptr);
test_deleter<A>* d = std::get_deleter<test_deleter<A> >(p);
assert(test_deleter<A>::count == 1);
assert(test_deleter<A>::dealloc_count == 0);
assert(d);
assert(d->state() == 3);
assert(test_allocator<A>::count == 1);
assert(test_allocator<A>::alloc_count == 1);
}
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
\ No newline at end 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); +} 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 4fd7f6c1396..5b738c8965c 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,47 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
#include <memory>
#include <cassert>
#include "../test_deleter.h"
#include "../test_allocator.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
A* ptr = new A;
try
{
test_allocator<A>::throw_after = 0;
std::shared_ptr<A> p(ptr, test_deleter<A>(3), test_allocator<A>(5));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
assert(test_allocator<A>::count == 0);
assert(test_allocator<A>::alloc_count == 0);
}
}
\ No newline at end 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); + } +} 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 5596cdaec9b..ba723e3f645 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,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, class D> shared_ptr(Y* p, D d);
#include <memory>
#include <cassert>
#include <new>
#include <cstdlib>
#include "../test_deleter.h"
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
A* ptr = new A;
throw_next = true;
try
{
std::shared_ptr<A> p(ptr, test_deleter<A>(3));
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
assert(test_deleter<A>::count == 0);
assert(test_deleter<A>::dealloc_count == 1);
}
}
\ No newline at end 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); + } +} 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 4b47a5c0aa6..298b9b40492 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,60 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template<class Y> explicit shared_ptr(Y* p);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
int main()
{
{
A* ptr = new A;
throw_next = true;
assert(A::count == 1);
try
{
std::shared_ptr<A> p(ptr);
assert(false);
}
catch (std::bad_alloc&)
{
assert(A::count == 0);
}
}
}
\ No newline at end 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); + } + } +} 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 0ee5cca1dc7..9a1d8e5e69e 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,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(const shared_ptr& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 1);
assert(pA.use_count() == 2);
assert(pA2.use_count() == 2);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 1);
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA2(pA);
assert(A::count == 0);
assert(pA.use_count() == 0);
assert(pA2.use_count() == 0);
assert(pA2.get() == pA.get());
}
assert(pA.use_count() == 0);
assert(A::count == 0);
}
assert(A::count == 0);
}
\ No newline at end 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); +} 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 a2bc56202bb..ca44ea621f4 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,97 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
const std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 1);
assert(A::count == 1);
assert(pB.use_count() == 2);
assert(pA.use_count() == 2);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
}
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<A> pA;
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
{
std::shared_ptr<B> pB(pA);
assert(B::count == 0);
assert(A::count == 0);
assert(pB.use_count() == 0);
assert(pA.use_count() == 0);
assert(pA.get() == pB.get());
}
assert(pA.use_count() == 0);
assert(B::count == 0);
assert(A::count == 0);
}
assert(B::count == 0);
assert(A::count == 0);
}
\ No newline at end 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); +} 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 a7b1b1cff05..7f9c142afea 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,109 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(shared_ptr<Y>&& r);
#include <memory>
#include <type_traits>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
struct C
{
static int count;
C() {++count;}
C(const C&) {++count;}
virtual ~C() {--count;}
};
int C::count = 0;
int main()
{
static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(B::count == 1);
assert(A::count == 1);
{
B* p = pA.get();
std::shared_ptr<B> pB(std::move(pA));
assert(B::count == 1);
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pB.use_count() == 1);
assert(pA.use_count() == 0);
#else
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 // _LIBCPP_MOVE + assert(pB.use_count() == 2); + assert(pA.use_count() == 2); +#endif // _LIBCPP_MOVE + assert(p == pB.get()); + } +#ifdef _LIBCPP_MOVE + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); +#else // _LIBCPP_MOVE + assert(pA.use_count() == 1); + assert(B::count == 1); + assert(A::count == 1); +#endif // _LIBCPP_MOVE + } + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + { + std::shared_ptr<B> pB(pA); + assert(B::count == 0); + assert(A::count == 0); + assert(pB.use_count() == 0); + assert(pA.use_count() == 0); + assert(pA.get() == pB.get()); + } + assert(pA.use_count() == 0); + assert(B::count == 0); + assert(A::count == 0); + } + assert(B::count == 0); + assert(A::count == 0); +} 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 565d77ff71a..6c2ee0a821e 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,61 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
~B() {--count;}
};
int B::count = 0;
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
{
B b;
std::shared_ptr<B> pB(pA, &b);
assert(A::count == 1);
assert(B::count == 1);
assert(pA.use_count() == 2);
assert(pB.use_count() == 2);
assert(pB.get() == &b);
}
assert(pA.use_count() == 1);
assert(A::count == 1);
assert(B::count == 0);
}
assert(A::count == 0);
assert(B::count == 0);
}
\ No newline at end 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); +} 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 f6528b2cb28..ae3faede98d 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,73 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// shared_ptr(shared_ptr&& r);
#include <memory>
#include <cassert>
struct A
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::shared_ptr<A> pA(new A);
assert(pA.use_count() == 1);
assert(A::count == 1);
{
A* p = pA.get();
std::shared_ptr<A> pA2(std::move(pA));
assert(A::count == 1);
#ifdef _LIBCPP_MOVE
assert(pA.use_count() == 0);
assert(pA2.use_count() == 1);
#else
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 // _LIBCPP_MOVE + assert(pA.use_count() == 2); + assert(pA2.use_count() == 2); +#endif // _LIBCPP_MOVE + assert(pA2.get() == p); + } +#ifdef _LIBCPP_MOVE + assert(pA.use_count() == 0); + assert(A::count == 0); +#else // _LIBCPP_MOVE + assert(pA.use_count() == 1); + assert(A::count == 1); +#endif // _LIBCPP_MOVE + } + assert(A::count == 0); + { + std::shared_ptr<A> pA; + assert(pA.use_count() == 0); + assert(A::count == 0); + { + std::shared_ptr<A> pA2(std::move(pA)); + assert(A::count == 0); + assert(pA.use_count() == 0); + assert(pA2.use_count() == 0); + assert(pA2.get() == pA.get()); + } + assert(pA.use_count() == 0); + assert(A::count == 0); + } + assert(A::count == 0); +} 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 9f57052860e..d5833fe9479 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,86 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// template <class Y, class D> explicit shared_ptr(unique_ptr<Y, D>&&r);
#include <memory>
#include <new>
#include <cstdlib>
#include <cassert>
bool throw_next = false;
void* operator new(std::size_t s) throw(std::bad_alloc)
{
if (throw_next)
throw std::bad_alloc();
return std::malloc(s);
}
void operator delete(void* p) throw()
{
std::free(p);
}
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
std::shared_ptr<B> p(std::move(ptr));
assert(A::count == 1);
assert(B::count == 1);
assert(p.use_count() == 1);
assert(p.get() == raw_ptr);
assert(ptr.get() == 0);
}
assert(A::count == 0);
{
std::unique_ptr<A> ptr(new A);
A* raw_ptr = ptr.get();
throw_next = true;
try
{
std::shared_ptr<B> p(std::move(ptr));
assert(false);
}
catch (...)
{
assert(A::count == 1);
assert(B::count == 1);
assert(ptr.get() == raw_ptr);
}
}
assert(A::count == 0);
}
\ No newline at end 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); +} 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 aa9fbf50377..5ff710411f5 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,79 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
#include <memory>
#include <cassert>
struct B
{
static int count;
B() {++count;}
B(const B&) {++count;}
virtual ~B() {--count;}
};
int B::count = 0;
struct A
: public B
{
static int count;
A() {++count;}
A(const A&) {++count;}
~A() {--count;}
};
int A::count = 0;
int main()
{
{
std::weak_ptr<A> wp;
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
assert(A::count == 0);
}
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
std::shared_ptr<A> sp(wp);
assert(sp.use_count() == 2);
assert(sp.get() == sp0.get());
assert(A::count == 1);
}
assert(A::count == 0);
{
std::shared_ptr<A> sp0(new A);
std::weak_ptr<A> wp(sp0);
sp0.reset();
try
{
std::shared_ptr<A> sp(wp);
assert(false);
}
catch (std::bad_weak_ptr&)
{
}
}
assert(A::count == 0);
}
\ No newline at end 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); +} 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 49ad98cd279..3286400ace9 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,57 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 2db9c66569e..51ae74f37d2 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,66 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 27d9eb93450..745a8bf7d69 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,62 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// 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); +} 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 13656f51849..8841a096571 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,64 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 b4bdd8654e5..b8db36fef30 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,79 @@ -//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <memory>
// shared_ptr
// template<class Y, 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); +} 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 a318f68caf4..bf6279a24a4 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,88 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 6f75444e632..8b0ebf7473f 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,104 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 14646f0392a..30ce67f9038 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,29 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 b02af0f1cfb..786f02ddf54 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,25 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 f0661fb318c..10b4d142525 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,29 @@ -//===----------------------------------------------------------------------===//
//
// 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); + } +} 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 b5aeff5e818..0854cda6b6c 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,28 @@ -//===----------------------------------------------------------------------===//
//
// 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)); +} 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 8e8059b2056..d112e64d2cf 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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)); +} 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 429e7e9d58a..3d779ec2b39 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,28 @@ -//===----------------------------------------------------------------------===//
//
// 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()); +} 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 850125f8cf2..d21a50bb860 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,104 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 359bfa7c48a..cfb2708fa8a 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,26 @@ -//===----------------------------------------------------------------------===//
//
// 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), ""); +} 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 eb16e033d04..fbaf44fcae3 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,74 @@ -//===----------------------------------------------------------------------===//
//
// 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)); + } +} 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 87569aadb20..12091630dff 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,61 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 853d43265ea..a472c1c873a 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,62 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 85461b90f7e..422de83d594 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,62 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 ef62c139a7e..01047a22978 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,25 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 1efdb03774b..3f7e890b897 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,95 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 fabf4324536..80e50ea9e5e 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,93 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 8b2db201d6d..c82d4027c13 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,95 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 e8db90cbee0..b89f168e9c4 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,12 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} 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 50aa527232a..7efe4ae5c26 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,41 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 1bd3a3f6c50..c80598ff2da 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,49 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 3d93fb93e9e..7212923cd4b 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,46 @@ -//===----------------------------------------------------------------------===//
//
// 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)); + } +} 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 c68792058fc..93895ba6f94 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,58 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 18bacf4a43a..acd9558ee93 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,27 @@ -//===----------------------------------------------------------------------===//
//
// 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; +} 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 e3ad3807ea3..a8e88b0dcc6 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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)); +} 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 6f123821233..f6e3f0e74f7 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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)); +} 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 c349f90b638..c3d89fa5612 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,49 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} 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 ae75b4fe810..3b0eb934ab9 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,31 @@ -//===----------------------------------------------------------------------===//
//
// 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); +} diff --git a/libcxx/test/utilities/memory/version.pass.cpp b/libcxx/test/utilities/memory/version.pass.cpp index e05afd07802..bc84501f1b8 100644 --- a/libcxx/test/utilities/memory/version.pass.cpp +++ b/libcxx/test/utilities/memory/version.pass.cpp @@ -1 +1,20 @@ -//===----------------------------------------------------------------------===//
//
// 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() +{ +} |