diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:03:23 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:03:23 +0000 |
commit | 0dc0969cd0a732760f0aa79942a04e0eaef297c4 (patch) | |
tree | 051bdb57b1ac6ee143f61ddbb47bd0da619f6f0c /test/std/utilities | |
parent | 868847c6900e575417c03bced6e562b3af891318 (diff) |
Notes
Diffstat (limited to 'test/std/utilities')
306 files changed, 4713 insertions, 8018 deletions
diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp index ef3b9302c7a2b..dfb187b6cc2df 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_const_lvalue_pair.pass.cpp @@ -87,7 +87,6 @@ void test_no_inner_alloc() void test_with_inner_alloc() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp index 6f31d264280a6..9689fb0147862 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_piecewise.pass.cpp @@ -88,7 +88,6 @@ void test_no_inner_alloc() void test_with_inner_alloc() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp index a761b32880606..92df0f6f2264f 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_rvalue.pass.cpp @@ -87,7 +87,6 @@ void test_no_inner_alloc() void test_with_inner_alloc() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp index de33eeb2fbda9..2b7fe3f641ae5 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair_values.pass.cpp @@ -83,7 +83,6 @@ void test_no_inner_alloc() void test_with_inner_alloc() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; diff --git a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp index 867cc74082e7d..8568c7380b6d0 100644 --- a/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp +++ b/test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_type.pass.cpp @@ -31,7 +31,6 @@ // OUTERMOST_ALLOC_TRAITS(*this)::construct( // OUTERMOST (*this), p, std::forward<Args>(args)...). void test_bullet_one() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; @@ -41,7 +40,6 @@ void test_bullet_one() { using Outer = CountingAllocator<T, 1>; using Inner = CountingAllocator<T, 2>; using SA = std::scoped_allocator_adaptor<Outer, Inner>; - using SAInner = std::scoped_allocator_adaptor<Inner>; static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(!std::uses_allocator<T, Inner>::value, ""); T* ptr = (T*)::operator new(sizeof(T)); @@ -66,7 +64,6 @@ void test_bullet_one() { // true, calls OUTERMOST_ALLOC_TRAITS(*this)::construct(OUTERMOST (*this), p, // allocator_arg, inner_allocator(), std::forward<Args>(args)...). void test_bullet_two() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; @@ -76,7 +73,6 @@ void test_bullet_two() { using Outer = CountingAllocator<T, 1>; using Inner = CountingAllocator<T, 2>; using SA = std::scoped_allocator_adaptor<Outer, Inner>; - using SAInner = std::scoped_allocator_adaptor<Inner>; static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); T* ptr = (T*)::operator new(sizeof(T)); @@ -101,7 +97,6 @@ void test_bullet_two() { // OUTERMOST_ALLOC_TRAITS(*this)::construct(OUTERMOST (*this), p, // std::forward<Args>(args)..., inner_allocator()). void test_bullet_three() { - using VoidAlloc1 = CountingAllocator<void, 1>; using VoidAlloc2 = CountingAllocator<void, 2>; AllocController POuter; @@ -111,7 +106,6 @@ void test_bullet_three() { using Outer = CountingAllocator<T, 1>; using Inner = CountingAllocator<T, 2>; using SA = std::scoped_allocator_adaptor<Outer, Inner>; - using SAInner = std::scoped_allocator_adaptor<Inner>; static_assert(!std::uses_allocator<T, Outer>::value, ""); static_assert(std::uses_allocator<T, Inner>::value, ""); T* ptr = (T*)::operator new(sizeof(T)); diff --git a/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp b/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp index 65d94fd1e0a48..75dfb0a2e7044 100644 --- a/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp +++ b/test/std/utilities/any/any.class/any.modifiers/emplace.pass.cpp @@ -11,9 +11,9 @@ // <any> -// template <class T, class ...Args> emplace(Args&&...); +// template <class T, class ...Args> T& emplace(Args&&...); // template <class T, class U, class ...Args> -// void emplace(initializer_list<U>, Args&&...); +// T& emplace(initializer_list<U>, Args&&...); #include <any> #include <cassert> @@ -42,7 +42,9 @@ void test_emplace_type() { any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>(); + auto &v = a.emplace<Type>(); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); assert(Tracked::count == 0); assert(Type::count == 1); @@ -56,7 +58,9 @@ void test_emplace_type() { any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>(101); + auto &v = a.emplace<Type>(101); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); assert(Tracked::count == 0); assert(Type::count == 1); @@ -70,7 +74,9 @@ void test_emplace_type() { any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>(-1, 42, -1); + auto &v = a.emplace<Type>(-1, 42, -1); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); assert(Tracked::count == 0); assert(Type::count == 1); @@ -89,14 +95,20 @@ void test_emplace_type_tracked() { { any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>(); + auto &v = a.emplace<Type>(); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); + assert(Tracked::count == 0); assertArgsMatch<Type>(a); } { any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>(-1, 42, -1); + auto &v = a.emplace<Type>(-1, 42, -1); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); + assert(Tracked::count == 0); assertArgsMatch<Type, int, int, int>(a); } @@ -104,7 +116,10 @@ void test_emplace_type_tracked() { { any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>({-1, 42, -1}); + auto &v = a.emplace<Type>({-1, 42, -1}); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); + assert(Tracked::count == 0); assertArgsMatch<Type, std::initializer_list<int>>(a); } @@ -112,7 +127,10 @@ void test_emplace_type_tracked() { int x = 42; any a(std::in_place_type<Tracked>); assert(Tracked::count == 1); - a.emplace<Type>({-1, 42, -1}, x); + auto &v = a.emplace<Type>({-1, 42, -1}, x); + static_assert( std::is_same_v<Type&, decltype(v)>, "" ); + assert(&v == std::any_cast<Type>(&a)); + assert(Tracked::count == 0); assertArgsMatch<Type, std::initializer_list<int>, int&>(a); } diff --git a/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp b/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp index 99cc029971a84..bbc135051ef8e 100644 --- a/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp +++ b/test/std/utilities/any/any.nonmembers/any.cast/reference_types.fail.cpp @@ -25,13 +25,30 @@ using std::any_cast; int main() { any a(1); - any_cast<int &>(&a); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} - any_cast<int &&>(&a); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} - any_cast<int const &>(&a); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} - any_cast<int const&&>(&a); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int &>(&a); // expected-note {{requested here}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int &&>(&a); // expected-note {{requested here}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int const &>(&a); // expected-note {{requested here}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int const&&>(&a); // expected-note {{requested here}} + any const& a2 = a; - any_cast<int &>(&a2); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} - any_cast<int &&>(&a2); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} - any_cast<int const &>(&a2); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} - any_cast<int const &&>(&a2); // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int &>(&a2); // expected-note {{requested here}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int &&>(&a2); // expected-note {{requested here}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int const &>(&a2); // expected-note {{requested here}} + + // expected-error@any:* 1 {{static_assert failed "_ValueType may not be a reference."}} + any_cast<int const &&>(&a2); // expected-note {{requested here}} } diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp index 5e347c4c57156..943e162172b05 100644 --- a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/PR23141_invoke_not_constexpr.pass.cpp @@ -16,7 +16,7 @@ // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> // unspecified bind(Fn, Types...); -// https://llvm.org/bugs/show_bug.cgi?id=23141 +// https://bugs.llvm.org/show_bug.cgi?id=23141 #include <functional> #include <type_traits> diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp index ad03e8fb6bb24..a4d502bb800e8 100644 --- a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/copy.pass.cpp @@ -16,7 +16,7 @@ // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> // unspecified bind(Fn, Types...); -// http://llvm.org/bugs/show_bug.cgi?id=16385 +// https://bugs.llvm.org/show_bug.cgi?id=16385 #include <functional> #include <cmath> diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp index 180433109f26f..a9a38b83cb4eb 100644 --- a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/invoke_function_object.pass.cpp @@ -16,7 +16,7 @@ // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> // unspecified bind(Fn, Types...); -// http://llvm.org/bugs/show_bug.cgi?id=22003 +// https://bugs.llvm.org/show_bug.cgi?id=22003 #include <functional> diff --git a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp index 0d4244b4d8605..5b660da617a8f 100644 --- a/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp +++ b/test/std/utilities/function.objects/bind/func.bind/func.bind.bind/nested.pass.cpp @@ -16,7 +16,7 @@ // template<Returnable R, CopyConstructible Fn, CopyConstructible... Types> // unspecified bind(Fn, Types...); -// http://llvm.org/bugs/show_bug.cgi?id=16343 +// https://bugs.llvm.org/show_bug.cgi?id=16343 #include <cmath> #include <functional> diff --git a/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp b/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp index 47a3e1cc59698..2b19211be9bf4 100644 --- a/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp +++ b/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp @@ -414,7 +414,14 @@ void throws_in_constructor_test() throw 42; } ThrowsOnCopy() = default; - bool operator()() const { assert(false); } + bool operator()() const { + assert(false); +#if defined(_LIBCPP_MSVC) + __assume(0); +#else + __builtin_unreachable(); +#endif + } }; { ThrowsOnCopy cp; diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp index 5bdf9e98e897a..812f6fc502d9f 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/derive_from.pass.cpp @@ -8,11 +8,11 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 -// REQUIRES-ANY: c++11, c++14 +// REQUIRES: c++11 || c++14 // <functional> -// See https://llvm.org/bugs/show_bug.cgi?id=20002 +// See https://bugs.llvm.org/show_bug.cgi?id=20002 #include <functional> #include <type_traits> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp index f89bde8e65440..3affd984af600 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_nullptr.pass.cpp @@ -14,7 +14,7 @@ // function(Fp); // Ensure that __not_null works for all function types. -// See https://llvm.org/bugs/show_bug.cgi?id=23589 +// See https://bugs.llvm.org/show_bug.cgi?id=23589 //------------------------------------------------------------------------------ // TESTING std::function<...>::__not_null(Callable) @@ -31,7 +31,7 @@ // types can be null. The other categories are not tested here. // 3) '__not_null(Callable)' is well formed when the call signature includes // varargs. -// 4) '__not_null(Callable)' works for Callable types with all aritys less +// 4) '__not_null(Callable)' works for Callable types with all arities less // than or equal to 3 in C++03. // 5) '__not_null(Callable)' works when 'Callable' is a member function // pointer to a cv or ref qualified function type. diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp index 392dfc1993bce..adc7856357e70 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // <functional> -// REQUIRES-ANY: c++98, c++03, c++11, c++14 +// REQUIRES: c++98 || c++03 || c++11 || c++14 // class function<R(ArgTypes...)> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp index 8d454723320c4..4c1a1ca95ff4a 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_F.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // <functional> -// REQUIRES-ANY: c++98, c++03, c++11, c++14 +// REQUIRES: c++98 || c++03 || c++11 ||c++14 // class function<R(ArgTypes...)> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp index 718aa49341d22..8b0e831287a5f 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_function.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // <functional> -// REQUIRES-ANY: c++98, c++03, c++11, c++14 +// REQUIRES: c++98 || c++03 || c++11 || c++14 // class function<R(ArgTypes...)> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp index 354ad955f207a..943e170878f24 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_nullptr.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // <functional> -// REQUIRES-ANY: c++98, c++03, c++11, c++14 +// REQUIRES: c++98 || c++03 || c++11 || c++14 // class function<R(ArgTypes...)> diff --git a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp index e328481b274d0..3e5435da1a16b 100644 --- a/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp +++ b/test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/alloc_rfunction.pass.cpp @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03 -// REQUIRES-ANY: c++11, c++14 +// REQUIRES: c++11 || c++14 // <functional> diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp b/test/std/utilities/function.objects/unord.hash/enabled_hashes.pass.cpp index 82b84948f3f0d..775247fc80b68 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.fail.cpp +++ b/test/std/utilities/function.objects/unord.hash/enabled_hashes.pass.cpp @@ -7,24 +7,17 @@ // //===----------------------------------------------------------------------===// -// <memory> +// UNSUPPORTED: c++98, c++03 -// unique_ptr +// <functional> -// Test unique_ptr default ctor +// Test that <functional> provides all of the arithmetic, enum, and pointer +// hash specializations. -// default unique_ptr ctor should require non-reference Deleter ctor +#include <functional> -#include <memory> +#include "poisoned_hash_helper.hpp" -class Deleter -{ -public: - - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr<int[], Deleter&> p; +int main() { + test_library_hash_specializations_available(); } diff --git a/test/std/utilities/function.objects/unord.hash/enum.pass.cpp b/test/std/utilities/function.objects/unord.hash/enum.pass.cpp index af367789a105b..a7ddd9a499977 100644 --- a/test/std/utilities/function.objects/unord.hash/enum.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/enum.pass.cpp @@ -36,6 +36,7 @@ test() typedef std::hash<T> H; static_assert((std::is_same<typename H::argument_type, T>::value), "" ); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + ASSERT_NOEXCEPT(H()(T())); typedef typename std::underlying_type<T>::type under_type; H h1; @@ -43,7 +44,8 @@ test() for (int i = 0; i <= 5; ++i) { T t(static_cast<T> (i)); - if (sizeof(T) <= sizeof(std::size_t)) + const bool small = std::integral_constant<bool, sizeof(T) <= sizeof(std::size_t)>::value; // avoid compiler warnings + if (small) assert(h1(t) == h2(static_cast<under_type>(i))); } } diff --git a/test/std/utilities/function.objects/unord.hash/floating.pass.cpp b/test/std/utilities/function.objects/unord.hash/floating.pass.cpp index 643e2d8c5d860..e67aa016c1e74 100644 --- a/test/std/utilities/function.objects/unord.hash/floating.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/floating.pass.cpp @@ -24,6 +24,8 @@ #include <limits> #include <cmath> +#include "test_macros.h" + template <class T> void test() @@ -31,6 +33,7 @@ test() typedef std::hash<T> H; static_assert((std::is_same<typename H::argument_type, T>::value), "" ); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; std::size_t t0 = h(0.); diff --git a/test/std/utilities/function.objects/unord.hash/integral.pass.cpp b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp index 2f3f9bee4bc36..ce87f5918b20b 100644 --- a/test/std/utilities/function.objects/unord.hash/integral.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/integral.pass.cpp @@ -31,12 +31,14 @@ test() typedef std::hash<T> H; static_assert((std::is_same<typename H::argument_type, T>::value), "" ); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; for (int i = 0; i <= 5; ++i) { T t(static_cast<T>(i)); - if (sizeof(T) <= sizeof(std::size_t)) + const bool small = std::integral_constant<bool, sizeof(T) <= sizeof(std::size_t)>::value; // avoid compiler warnings + if (small) { const std::size_t result = h(t); LIBCPP_ASSERT(result == static_cast<size_t>(t)); @@ -63,42 +65,42 @@ int main() test<long long>(); test<unsigned long long>(); -// LWG #2119 +// LWG #2119 test<std::ptrdiff_t>(); test<size_t>(); - test<int8_t>(); - test<int16_t>(); - test<int32_t>(); - test<int64_t>(); + test<int8_t>(); + test<int16_t>(); + test<int32_t>(); + test<int64_t>(); - test<int_fast8_t>(); - test<int_fast16_t>(); - test<int_fast32_t>(); - test<int_fast64_t>(); + test<int_fast8_t>(); + test<int_fast16_t>(); + test<int_fast32_t>(); + test<int_fast64_t>(); - test<int_least8_t>(); - test<int_least16_t>(); - test<int_least32_t>(); - test<int_least64_t>(); + test<int_least8_t>(); + test<int_least16_t>(); + test<int_least32_t>(); + test<int_least64_t>(); test<intmax_t>(); test<intptr_t>(); - test<uint8_t>(); - test<uint16_t>(); - test<uint32_t>(); - test<uint64_t>(); + test<uint8_t>(); + test<uint16_t>(); + test<uint32_t>(); + test<uint64_t>(); - test<uint_fast8_t>(); - test<uint_fast16_t>(); - test<uint_fast32_t>(); - test<uint_fast64_t>(); + test<uint_fast8_t>(); + test<uint_fast16_t>(); + test<uint_fast32_t>(); + test<uint_fast64_t>(); - test<uint_least8_t>(); - test<uint_least16_t>(); - test<uint_least32_t>(); - test<uint_least64_t>(); + test<uint_least8_t>(); + test<uint_least16_t>(); + test<uint_least32_t>(); + test<uint_least64_t>(); test<uintmax_t>(); test<uintptr_t>(); diff --git a/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp b/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp index a48394495e2d5..36280a38e0a7f 100644 --- a/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp +++ b/test/std/utilities/function.objects/unord.hash/pointer.pass.cpp @@ -23,6 +23,8 @@ #include <type_traits> #include <limits> +#include "test_macros.h" + template <class T> void test() @@ -30,6 +32,7 @@ test() typedef std::hash<T> H; static_assert((std::is_same<typename H::argument_type, T>::value), "" ); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + ASSERT_NOEXCEPT(H()(T())); H h; typedef typename std::remove_pointer<T>::type type; @@ -38,7 +41,20 @@ test() assert(h(&i) != h(&j)); } +// can't hash nullptr_t until c++17 +void test_nullptr() +{ +#if TEST_STD_VER > 14 + typedef std::nullptr_t T; + typedef std::hash<T> H; + static_assert((std::is_same<typename H::argument_type, T>::value), "" ); + static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + ASSERT_NOEXCEPT(H()(T())); +#endif +} + int main() { test<int*>(); + test_nullptr(); } diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct.pass.cpp index 533d516707e10..05e55e3d9a4e5 100644 --- a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct.pass.cpp +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct.pass.cpp @@ -80,7 +80,7 @@ void test_counted() Counted* p = (Counted*)pool; std::uninitialized_default_construct(It(p), It(p+1)); assert(Counted::count == 1); - assert(Counted::constructed = 1); + assert(Counted::constructed == 1); std::uninitialized_default_construct(It(p+1), It(p+N)); assert(Counted::count == 5); assert(Counted::constructed == 5); diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct_n.pass.cpp index f22a74f1f832c..e5b9eca439cf8 100644 --- a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct_n.pass.cpp +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.default/uninitialized_default_construct_n.pass.cpp @@ -80,7 +80,7 @@ void test_counted() It e = std::uninitialized_default_construct_n(It(p), 1); assert(e == It(p+1)); assert(Counted::count == 1); - assert(Counted::constructed = 1); + assert(Counted::constructed == 1); e = std::uninitialized_default_construct_n(It(p+1), 4); assert(e == It(p+N)); assert(Counted::count == 5); diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct.pass.cpp index c2d860694a756..8479ce123a786 100644 --- a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct.pass.cpp +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct.pass.cpp @@ -79,7 +79,7 @@ void test_counted() Counted* p = (Counted*)pool; std::uninitialized_value_construct(It(p), It(p+1)); assert(Counted::count == 1); - assert(Counted::constructed = 1); + assert(Counted::constructed == 1); std::uninitialized_value_construct(It(p+1), It(p+N)); assert(Counted::count == 5); assert(Counted::constructed == 5); diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct_n.pass.cpp index 323d00f7c9c41..ad6a51500e36f 100644 --- a/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct_n.pass.cpp +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.construct.value/uninitialized_value_construct_n.pass.cpp @@ -81,7 +81,7 @@ void test_counted() It e = std::uninitialized_value_construct_n(It(p), 1); assert(e == It(p+1)); assert(Counted::count == 1); - assert(Counted::constructed = 1); + assert(Counted::constructed == 1); e = std::uninitialized_value_construct_n(It(p+1), 4); assert(e == It(p+N)); assert(Counted::count == 5); diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move.pass.cpp index d7a9542b4c273..6c535250fd1f1 100644 --- a/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move.pass.cpp +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move.pass.cpp @@ -88,7 +88,7 @@ void test_counted() Counted* p = (Counted*)pool; auto ret = std::uninitialized_move(It(values), It(values + 1), FIt(p)); assert(ret == FIt(p +1)); - assert(Counted::constructed = 1); + assert(Counted::constructed == 1); assert(Counted::count == 1); assert(p[0].value == 1); assert(values[0] == 0); diff --git a/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move_n.pass.cpp b/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move_n.pass.cpp index f27e5726135f0..4175c6bce6880 100644 --- a/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move_n.pass.cpp +++ b/test/std/utilities/memory/specialized.algorithms/uninitialized.move/uninitialized_move_n.pass.cpp @@ -89,7 +89,7 @@ void test_counted() auto ret = std::uninitialized_move_n(It(values), 1, FIt(p)); assert(ret.first == It(values +1)); assert(ret.second == FIt(p +1)); - assert(Counted::constructed = 1); + assert(Counted::constructed == 1); assert(Counted::count == 1); assert(p[0].value == 1); assert(values[0] == 0); diff --git a/test/std/utilities/memory/unique.ptr/deleter.h b/test/std/utilities/memory/unique.ptr/deleter.h deleted file mode 100644 index 1d8e19d5bc419..0000000000000 --- a/test/std/utilities/memory/unique.ptr/deleter.h +++ /dev/null @@ -1,338 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Example move-only deleter - -#ifndef DELETER_H -#define DELETER_H - -#include <type_traits> -#include <utility> -#include <cassert> - -#include "test_macros.h" - -#if TEST_STD_VER >= 11 - -template <class T> -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); - -public: - Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} - Deleter& operator=(Deleter&& r) - { - state_ = r.state_; - r.state_ = 0; - return *this; - } - - - Deleter() : state_(0) {} - explicit Deleter(int s) : state_(s) {} - ~Deleter() {assert(state_ >= 0); state_ = -1;} - - template <class U> - Deleter(Deleter<U>&& d, - typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) - : state_(d.state()) {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); -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_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); - -public: - - Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} - Deleter& operator=(Deleter&& r) - { - state_ = r.state_; - r.state_ = 0; - return *this; - } - - Deleter() : state_(0) {} - explicit Deleter(int s) : state_(s) {} - ~Deleter() {assert(state_ >= 0); state_ = -1;} - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete [] p;} -}; - -#else // TEST_STD_VER < 11 - -template <class T> -class Deleter -{ - mutable int state_; - -public: - Deleter() : state_(0) {} - explicit Deleter(int s) : state_(s) {} - - Deleter(Deleter const & other) : state_(other.state_) { - other.state_ = 0; - } - Deleter& operator=(Deleter const& other) { - state_ = other.state_; - other.state_ = 0; - return *this; - } - - ~Deleter() {assert(state_ >= 0); state_ = -1;} - - template <class U> - Deleter(Deleter<U> d, - typename std::enable_if<!std::is_same<U, T>::value>::type* = 0) - : state_(d.state()) {} - -public: - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete p;} -}; - -template <class T> -class Deleter<T[]> -{ - mutable int state_; - -public: - - Deleter(Deleter const& other) : state_(other.state_) { - other.state_ = 0; - } - Deleter& operator=(Deleter const& other) { - state_ = other.state_; - other.state_ = 0; - return *this; - } - - 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;} -}; - -#endif - -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); -} - -// Non-copyable deleter -template <class T> -class NCDeleter -{ - int state_; - NCDeleter(NCDeleter const&); - NCDeleter& operator=(NCDeleter const&); -public: - - NCDeleter() : state_(0) {} - explicit NCDeleter(int s) : state_(s) {} - ~NCDeleter() {assert(state_ >= 0); state_ = -1;} - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete p;} -}; - - -template <class T> -class NCDeleter<T[]> -{ - int state_; - NCDeleter(NCDeleter const&); - NCDeleter& operator=(NCDeleter const&); -public: - - NCDeleter() : state_(0) {} - explicit NCDeleter(int s) : state_(s) {} - ~NCDeleter() {assert(state_ >= 0); state_ = -1;} - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete [] p;} -}; - - -// Non-copyable deleter -template <class T> -class NCConstDeleter -{ - int state_; - NCConstDeleter(NCConstDeleter const&); - NCConstDeleter& operator=(NCConstDeleter const&); -public: - - NCConstDeleter() : state_(0) {} - explicit NCConstDeleter(int s) : state_(s) {} - ~NCConstDeleter() {assert(state_ >= 0); state_ = -1;} - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) const {delete p;} -}; - - -template <class T> -class NCConstDeleter<T[]> -{ - int state_; - NCConstDeleter(NCConstDeleter const&); - NCConstDeleter& operator=(NCConstDeleter const&); -public: - - NCConstDeleter() : state_(0) {} - explicit NCConstDeleter(int s) : state_(s) {} - ~NCConstDeleter() {assert(state_ >= 0); state_ = -1;} - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) const {delete [] p;} -}; - - -// Non-copyable deleter -template <class T> -class CopyDeleter -{ - int state_; -public: - - CopyDeleter() : state_(0) {} - explicit CopyDeleter(int s) : state_(s) {} - ~CopyDeleter() {assert(state_ >= 0); state_ = -1;} - - CopyDeleter(CopyDeleter const& other) : state_(other.state_) {} - CopyDeleter& operator=(CopyDeleter const& other) { - state_ = other.state_; - return *this; - } - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete p;} -}; - - -template <class T> -class CopyDeleter<T[]> -{ - int state_; - -public: - - CopyDeleter() : state_(0) {} - explicit CopyDeleter(int s) : state_(s) {} - ~CopyDeleter() {assert(state_ >= 0); state_ = -1;} - - CopyDeleter(CopyDeleter const& other) : state_(other.state_) {} - CopyDeleter& operator=(CopyDeleter const& other) { - state_ = other.state_; - return *this; - } - - int state() const {return state_;} - void set_state(int i) {state_ = i;} - - void operator()(T* p) {delete [] p;} -}; - - -#endif // DELETER_H diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp deleted file mode 100644 index ed94c1a1e4701..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.fail.cpp +++ /dev/null @@ -1,28 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> - -#include "test_macros.h" - -int main() -{ - std::unique_ptr<int> s, s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - s2 = s; // expected-error {{'operator=' is a private member of 'std::__1::unique_ptr}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp deleted file mode 100644 index 286e6bc9a7b91..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move01.pass.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -// test move assignment. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp deleted file mode 100644 index 6e13873c2fb3b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move02.fail.cpp +++ /dev/null @@ -1,39 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> -#include <utility> -#include <cassert> - -// Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - const std::unique_ptr<A[]> s(new A[3]); - std::unique_ptr<A[]> s2; - s2 = s; - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp deleted file mode 100644 index 3712a27963929..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move03.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> -#include <utility> -#include <cassert> - -// Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - std::unique_ptr<A, Deleter> s(new A); - A* p = s.get(); - std::unique_ptr<A, Deleter> s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp deleted file mode 100644 index 4e85e5b0fb906..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move04.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test move ctor. Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - const std::unique_ptr<A, Deleter> s(new A); - A* p = s.get(); - std::unique_ptr<A, Deleter> s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp deleted file mode 100644 index 9461958a431dd..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert01.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> -#include <utility> -#include <cassert> - -// Can't assign from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp deleted file mode 100644 index 1737136f4d72a..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert02.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from lvalue - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp deleted file mode 100644 index 3c89bb12344eb..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert03.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from lvalue - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp deleted file mode 100644 index 970beb5a150e9..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert04.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> -#include <utility> -#include <cassert> - -// Can't assign from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const boost::unique_ptr<B[]> s(new B); - A* p = s.get(); - boost::unique_ptr<A[]> s2; - s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp deleted file mode 100644 index 786858dd40169..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert05.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp deleted file mode 100644 index 46d4c0985d716..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert06.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp deleted file mode 100644 index 65ee2694156f6..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert07.fail.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> -#include <utility> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp deleted file mode 100644 index da08195ffdd3a..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert08.fail.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp deleted file mode 100644 index aeec076cb86ab..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/move_convert09.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// test converting move assignment with reference deleters - -#include <memory> -#include <utility> -#include <cassert> - -#include "../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp deleted file mode 100644 index e2d7956cda643..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_asgn.pass.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> -#include <cassert> - -// test assignment from null - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A> s2(new A); - assert(A::count == 1); - s2 = 0; - assert(A::count == 0); - assert(s2.get() == 0); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp deleted file mode 100644 index 50389978e8abb..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/null_ctor.pass.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// The deleter is not called if get() == 0 - -#include <memory> -#include <cassert> - -#include "test_macros.h" - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(0) {} - - int state() const {return state_;} - - void operator()(void*) {++state_;} -}; - -int main() -{ - Deleter d; - assert(d.state() == 0); - { - std::unique_ptr<int[], Deleter&> p(nullptr, d); - assert(p.get() == 0); - assert(&p.get_deleter() == &d); - } -#if defined(_LIBCPP_VERSION) - { - // The standard only requires the constructor accept nullptr, but libc++ - // also supports the literal 0. - std::unique_ptr<int[], Deleter&> p(0, d); - assert(p.get() == 0); - assert(&p.get_deleter() == &d); - } -#endif - assert(d.state() == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp deleted file mode 100644 index 30ecdded3cf7b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/nullptr_asgn.pass.cpp +++ /dev/null @@ -1,41 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> -#include <cassert> - -// test assignment from null - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A[]> s2(new A[3]); - assert(A::count == 3); - s2 = nullptr; - assert(A::count == 0); - assert(s2.get() == 0); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp deleted file mode 100644 index e7ad6ad7ef33d..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/pointer_type.pass.cpp +++ /dev/null @@ -1,34 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr<T[]>::pointer type - -#include <memory> -#include <type_traits> - -struct Deleter -{ - struct pointer {}; -}; - -int main() -{ - { - typedef std::unique_ptr<int[]> P; - static_assert((std::is_same<P::pointer, int*>::value), ""); - } - { - typedef std::unique_ptr<int[], Deleter> P; - static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp deleted file mode 100644 index b6bcad9a91c66..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.fail.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr default ctor - -// default unique_ptr ctor should require default Deleter ctor - - -#include <memory> - -class Deleter -{ - // expected-error@memory:* {{base class 'Deleter' has private default constructor}} - // expected-note@memory:* + {{in instantiation of member function}} - Deleter() {} // expected-note {{implicitly declared private here}} - -public: - - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) { return *this; } - - void operator()(void*) const {} -}; - -int main() -{ - std::unique_ptr<int[], Deleter> p; -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp deleted file mode 100644 index 0cc54382b98df..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default01.pass.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp deleted file mode 100644 index 3ded41c419c88..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default02.pass.cpp +++ /dev/null @@ -1,87 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test default unique_ptr<T[]> ctor - -// default unique_ptr<T[]> ctor shouldn't require complete type - -#include <memory> -#include <cassert> - -struct A; - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p); -}; - -void check(int i); - -template <class D = std::default_delete<A> > -struct B -{ - std::unique_ptr<A[], D> a_; - B(); - ~B(); - - A* get() const {return a_.get();} - D& get_deleter() {return a_.get_deleter();} -}; - -int main() -{ - { - B<> s; - assert(s.get() == 0); - } - check(0); - { - B<Deleter> s; - assert(s.get() == 0); - assert(s.get_deleter().state() == 5); - } - check(0); -} - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -void Deleter::operator()(A* p) {delete p;} - -void check(int i) -{ - assert(A::count == i); -} - -template <class D> -B<D>::B() {} - -template <class D> -B<D>::~B() {} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp deleted file mode 100644 index bc49a0e5c31e1..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <cassert> - -// test move ctor. Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A[]> s(new A[3]); - A* p = s.get(); - std::unique_ptr<A[]> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp deleted file mode 100644 index 5088a4410e792..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move01.pass.cpp +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A[]> s(new A[3]); - A* p = s.get(); - std::unique_ptr<A[]> s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 3); - } - assert(A::count == 0); - { - std::unique_ptr<A[], Deleter<A[]> > s(new A[3], Deleter<A[]>(5)); - A* p = s.get(); - std::unique_ptr<A[], Deleter<A[]> > s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 3); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - { - NCDeleter<A[]> d; - std::unique_ptr<A[], NCDeleter<A[]>&> s(new A[3], d); - A* p = s.get(); - std::unique_ptr<A[], NCDeleter<A[]>&> s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 3); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp deleted file mode 100644 index 8e44c78bf1e94..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Can't copy from const lvalue - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - const std::unique_ptr<A[]> s(new A[3]); - A* p = s.get(); - std::unique_ptr<A[]> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp deleted file mode 100644 index 89b6fa2488458..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move02.pass.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include <memory> -#include <cassert> - -#include "../../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - - -std::unique_ptr<A[]> -source1() -{ - return std::unique_ptr<A[]>(new A[3]); -} - -void sink1(std::unique_ptr<A[]>) -{ -} - -std::unique_ptr<A[], Deleter<A[]> > -source2() -{ - return std::unique_ptr<A[], Deleter<A[]> >(new A[3]); -} - -void sink2(std::unique_ptr<A[], Deleter<A[]> >) -{ -} - -std::unique_ptr<A[], NCDeleter<A[]>&> -source3() -{ - static NCDeleter<A[]> d; - return std::unique_ptr<A[], NCDeleter<A[]>&>(new A[3], d); -} - -void sink3(std::unique_ptr<A[], NCDeleter<A[]>&>) -{ -} - -int main() -{ - sink1(source1()); - sink2(source2()); - sink3(source3()); - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp deleted file mode 100644 index c952cf2d4e13c..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move03.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Can't copy from lvalue - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - std::unique_ptr<A[], Deleter> s(new A[3]); - A* p = s.get(); - std::unique_ptr<A[], Deleter> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp deleted file mode 100644 index 0d091ff346d12..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move04.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -// test move ctor. Can't copy from const lvalue - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - const std::unique_ptr<A[], Deleter> s(new A[3]); - A* p = s.get(); - std::unique_ptr<A[], Deleter> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp deleted file mode 100644 index d175fbf93adc5..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert01.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp deleted file mode 100644 index 1838511b49297..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert02.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp deleted file mode 100644 index 36ad75d8331a5..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert03.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp deleted file mode 100644 index 3a19bde928890..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert04.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp deleted file mode 100644 index bda2a70a4ef30..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert05.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp deleted file mode 100644 index fba895137b05f..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert06.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp deleted file mode 100644 index 24c646988f0a3..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert07.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp deleted file mode 100644 index 486d90825d9ef..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert08.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp deleted file mode 100644 index e4cbef5c05606..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert09.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp deleted file mode 100644 index 73423d1b3751f..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert10.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - const std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp deleted file mode 100644 index cfc097ba0b841..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert11.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp deleted file mode 100644 index fdb088250b9fe..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert12.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp deleted file mode 100644 index d9ef8e96fe8fc..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert13.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2(std::move(s)); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp deleted file mode 100644 index b4577a126c68a..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert14.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp deleted file mode 100644 index 9325d07d0d0c1..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert15.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp deleted file mode 100644 index b090e593ec62d..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert16.fail.cpp +++ /dev/null @@ -1,57 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B[]> s(new B); - A* p = s.get(); - std::unique_ptr<A[]> s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp deleted file mode 100644 index b2af3c7a69385..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert17.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp deleted file mode 100644 index d1c0e8a781e67..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/move_convert18.fail.cpp +++ /dev/null @@ -1,78 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp deleted file mode 100644 index 9a8c17547bca8..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/nullptr.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp deleted file mode 100644 index 4c31611508315..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.fail.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr<T[]>(pointer) ctor - -// unique_ptr<T[]>(pointer) ctor should require default Deleter ctor - -#include <memory> - -class Deleter -{ - - Deleter() {} - -public: - - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) {} - - void operator()(void*) const {} -}; - -int main() -{ - std::unique_ptr<int[], Deleter> p(new int); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp deleted file mode 100644 index dab42f277411b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer01.pass.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp deleted file mode 100644 index 1afb1c32ce8c4..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.pass.cpp +++ /dev/null @@ -1,95 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr<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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp deleted file mode 100644 index 591144f7aa588..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer04.fail.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -// unique_ptr(pointer) ctor should not work with derived pointers - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -class Deleter -{ - int state_; - - Deleter(Deleter&); - Deleter& operator=(Deleter&); - -public: - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - B* p = new B[3]; - std::unique_ptr<A[]> s(p); - } - { - B* p = new B[3]; - std::unique_ptr<A[], Deleter> s(p); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp deleted file mode 100644 index 3de556563f97a..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter01.pass.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, deleter()) only requires MoveConstructible deleter - -#include <memory> -#include <cassert> - -#include "../../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - std::unique_ptr<A[], Deleter<A[]> > s(p, Deleter<A[]>()); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - - { // LWG#2520 says that nullptr is a valid input as well as null -#ifdef _LIBCPP_VERSION - std::unique_ptr<A[], Deleter<A[]> > s1(NULL, Deleter<A[]>()); -#endif - std::unique_ptr<A[], Deleter<A[]> > s2(nullptr, Deleter<A[]>()); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp deleted file mode 100644 index a92fdbc1d2c41..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter02.pass.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr(pointer, d) requires CopyConstructible deleter - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - Deleter d; - std::unique_ptr<A[], Deleter> s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { - Deleter d; - std::unique_ptr<A[], Deleter> s(nullptr, d); - assert(s.get() == nullptr); - assert(s.get_deleter().state() == 5); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp deleted file mode 100644 index dd27401731a6d..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter03.pass.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr<T[], D&>(pointer, d) does not requires CopyConstructible deleter - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(A* p) {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - Deleter d; - std::unique_ptr<A[], Deleter&> s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 6); - } - assert(A::count == 0); - { - Deleter d; - std::unique_ptr<A[], Deleter&> s(nullptr, d); - assert(s.get() == nullptr); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp deleted file mode 100644 index 9d3f94098a08d..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.fail.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// XFAIL: c++98, c++03 - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr<T, const D&>(pointer, D()) should not compile - -#include <memory> - -class Deleter -{ -public: - Deleter() {} - void operator()(int* p) const {delete [] p;} -}; - -int main() -{ - int* p = nullptr; - std::unique_ptr<int[], const Deleter&> s(p, Deleter()); // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}} -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp deleted file mode 100644 index 02f44d3575615..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter04.pass.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer, deleter) ctor - -// unique_ptr<T[], const D&>(pointer, d) does not requires CopyConstructible deleter - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(A* p) const {delete [] p;} -}; - -int main() -{ - { - A* p = new A[3]; - assert(A::count == 3); - Deleter d; - std::unique_ptr<A[], const Deleter&> s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { - Deleter d; - std::unique_ptr<A[], const Deleter&> s(nullptr, d); - assert(s.get() == nullptr); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp deleted file mode 100644 index 0e03a7da07fb6..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer_deleter05.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer, 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp deleted file mode 100644 index d79a4e396eeda..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/release.pass.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp deleted file mode 100644 index 195d877bbb700..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset1.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test reset - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A[]> p(new A[3]); - assert(A::count == 3); - A* i = p.get(); - assert(i != nullptr); - p.reset(); - assert(A::count == 0); - assert(p.get() == 0); - } - assert(A::count == 0); - { - std::unique_ptr<A[]> p(new A[4]); - assert(A::count == 4); - A* i = p.get(); - assert(i != nullptr); - p.reset(new A[5]); - assert(A::count == 5); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp deleted file mode 100644 index bca6cb2470ac4..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/reset2.fail.cpp +++ /dev/null @@ -1,64 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test reset - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<A[]> p(new A); - assert(A::count == 1); - assert(B::count == 0); - A* i = p.get(); - p.reset(new B); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { - std::unique_ptr<A[]> p(new B); - assert(A::count == 1); - assert(B::count == 1); - A* i = p.get(); - p.reset(new B); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp deleted file mode 100644 index e9754cc0f2266..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.modifiers/swap.pass.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test 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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp deleted file mode 100644 index 46ba1395bb857..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/dereference.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test op*() - -#include <memory> -#include <cassert> - -int main() -{ - std::unique_ptr<int[]> p(new int(3)); - assert(*p == 3); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp deleted file mode 100644 index 4496740715a51..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get_deleter.pass.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test get_deleter() - -#include <memory> -#include <cassert> - -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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp deleted file mode 100644 index 519eae688ec1b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/index.pass.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test op[](size_t) - -#include <memory> -#include <cassert> - -class A -{ - int state_; - static int next_; -public: - A() : state_(++next_) {} - int get() const {return state_;} - - friend bool operator==(const A& x, int y) - {return x.state_ == y;} - - A& operator=(int i) {state_ = i; return *this;} -}; - -int A::next_ = 0; - -int main() -{ - std::unique_ptr<A[]> p(new A[3]); - assert(p[0] == 1); - assert(p[1] == 2); - assert(p[2] == 3); - p[0] = 3; - p[1] = 2; - p[2] = 1; - assert(p[0] == 3); - assert(p[1] == 2); - assert(p[2] == 1); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp deleted file mode 100644 index 380f2e100eb6e..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/pointer_type.pass.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr::pointer type - -#include <memory> -#include <type_traits> - -#include "test_macros.h" - -struct Deleter -{ - struct pointer {}; -}; - -struct D2 { -private: - typedef void pointer; -}; - -struct D3 { - static long pointer; -}; - -int main() -{ - { - typedef std::unique_ptr<int> P; - static_assert((std::is_same<P::pointer, int*>::value), ""); - } - { - typedef std::unique_ptr<int, Deleter> P; - static_assert((std::is_same<P::pointer, Deleter::pointer>::value), ""); - } -#if TEST_STD_VER >= 11 - { - typedef std::unique_ptr<int, D2> P; - static_assert(std::is_same<P::pointer, int*>::value, ""); - } - { - typedef std::unique_ptr<int, D3> P; - static_assert(std::is_same<P::pointer, int*>::value, ""); - } -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp deleted file mode 100644 index 87cfb72ad6e02..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> - -#include "test_macros.h" - -// Can't copy from lvalue -int main() -{ - std::unique_ptr<int> s, s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - s2 = s; // expected-error {{'operator=' is a private member}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp deleted file mode 100644 index 9535ed0295d46..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move01.pass.cpp +++ /dev/null @@ -1,75 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -// test move assignment. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp deleted file mode 100644 index 9cea12b1249ff..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move02.fail.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> - -#include "test_macros.h" - -// Can't copy from const lvalue - -int main() -{ - const std::unique_ptr<int> s(new int); - std::unique_ptr<int> s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - // NOTE: The error says "constructor" because the assignment operator takes - // 's' by value and attempts to copy construct it. - s2 = s; // expected-error {{no matching constructor for initialization}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp deleted file mode 100644 index 05a057f9bb325..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move03.fail.cpp +++ /dev/null @@ -1,33 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> - -#include "test_macros.h" - -struct Deleter { - void operator()(int* p) {delete p;} -}; - -// Can't copy from lvalue -int main() -{ - std::unique_ptr<int, Deleter> s, s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - s2 = s; // expected-error {{'operator=' is a private member}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp deleted file mode 100644 index 24703ec98238e..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move04.fail.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move assignment - -#include <memory> - -#include "test_macros.h" - -struct Deleter { - void operator()(int* p) {delete p;} -}; - -// Can't copy from a const lvalue -int main() -{ - const std::unique_ptr<int, Deleter> s(new int); - std::unique_ptr<int, Deleter> s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{cannot be assigned because its copy assignment operator is implicitly deleted}} -#else - // NOTE: The error says "constructor" because the assignment operator takes - // 's' by value and attempts to copy construct it. - s2 = s; // expected-error {{no matching constructor for initialization}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp deleted file mode 100644 index 4c4a320356410..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert.pass.cpp +++ /dev/null @@ -1,89 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - - -template <class APtr, class BPtr> -void testAssign(APtr& aptr, BPtr& bptr) { - A* p = bptr.get(); - assert(A::count == 2); - aptr = std::move(bptr); - assert(aptr.get() == p); - assert(bptr.get() == 0); - assert(A::count == 1); - assert(B::count == 1); -} - -template <class LHS, class RHS> -void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { - assert(lhs.get_deleter().state() == LHSState); - assert(rhs.get_deleter().state() == RHSState); -} - -int main() -{ - { - std::unique_ptr<B> bptr(new B); - std::unique_ptr<A> aptr(new A); - testAssign(aptr, bptr); - } - assert(A::count == 0); - assert(B::count == 0); - { - Deleter<B> del(42); - std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del)); - std::unique_ptr<A, Deleter<A> > aptr(new A); - testAssign(aptr, bptr); - checkDeleter(aptr, bptr, 42, 0); - } - assert(A::count == 0); - assert(B::count == 0); - { - CDeleter<A> adel(6); - CDeleter<B> bdel(42); - std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel); - std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel); - testAssign(aptr, bptr); - checkDeleter(aptr, bptr, 42, 42); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp deleted file mode 100644 index 816a598d9a237..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert01.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> - -#include "test_macros.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - std::unique_ptr<B> s; - std::unique_ptr<A> s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The move-semantic emulation creates an ambiguous overload set - // so that assignment from an lvalue does not compile - s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp deleted file mode 100644 index 1ddf1d811651c..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert02.fail.cpp +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> - -#include "test_macros.h" -#include "../../deleter.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - std::unique_ptr<B, Deleter<B> > s; - std::unique_ptr<A, Deleter<A> > s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The move-semantic emulation creates an ambiguous overload set - // so that assignment from an lvalue does not compile - s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp deleted file mode 100644 index 570c1c42f4fe3..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert03.fail.cpp +++ /dev/null @@ -1,47 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from lvalue - -#include <memory> - -#include "test_macros.h" -#include "../../deleter.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - Deleter<B> db; - std::unique_ptr<B, Deleter<B>& > s(new B, db); - Deleter<A> da; - std::unique_ptr<A, Deleter<A> &> s2(new A, da); -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The move-semantic emulation creates an ambiguous overload set - // so that assignment from an lvalue does not compile - s2 = s; // expected-error {{use of overloaded operator '=' is ambiguous}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp deleted file mode 100644 index 2ebc33d21d81e..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert04.fail.cpp +++ /dev/null @@ -1,43 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -#include <memory> - -#include "test_macros.h" -#include "../../deleter.h" - -struct A -{ - A() {} - virtual ~A() {} -}; - -struct B : public A -{ -}; - -// Can't assign from lvalue -int main() -{ - const std::unique_ptr<B> s(new B); - std::unique_ptr<A> s2; -#if TEST_STD_VER >= 11 - s2 = s; // expected-error {{no viable overloaded '='}} -#else - // NOTE: The error says "constructor" because the assignment operator takes - // 's' by value and attempts to copy construct it. - s2 = s; // expected-error {{no matching constructor for initialization}} -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp deleted file mode 100644 index 4694986c67730..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert05.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp deleted file mode 100644 index 220677cd6fa77..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert06.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Can't assign from const lvalue - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp deleted file mode 100644 index 412648420d46d..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/move_convert13.fail.cpp +++ /dev/null @@ -1,36 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move assignment - -// Do not convert from an array unique_ptr - -#include <memory> -#include <utility> -#include <cassert> - -struct A -{ -}; - -struct Deleter -{ - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr<A[], Deleter> s; - std::unique_ptr<A, Deleter> s2; - s2 = std::move(s); // expected-error {{no viable overloaded '='}} -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp deleted file mode 100644 index 7c3ac462c2876..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer.pass.cpp +++ /dev/null @@ -1,80 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// libc++ cannot safely provide the auto_ptr constructor without rvalue -// references. -// XFAIL: c++98, c++03 - -// <memory> - -// unique_ptr - -// template <class U> unique_ptr(auto_ptr<U>&&) noexcept - -#include <memory> -#include <utility> -#include <cassert> - -#include "test_macros.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() -{ - { - 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); -#if TEST_STD_VER >= 11 - { - static_assert(std::is_nothrow_constructible< - std::unique_ptr<A>, - std::auto_ptr<B>&& - >::value, ""); - } -#endif -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp deleted file mode 100644 index 1f317c7824542..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer01.fail.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include <memory> -#include <cassert> - -// template <class U> explicit unique_ptr(auto_ptr<U>&); - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B -// : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - B* p = new B; - std::auto_ptr<B> ap(p); - std::unique_ptr<A> up(ap); - assert(up.get() == p); - assert(ap.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { - B* p = new B; - std::auto_ptr<B> ap(p); - std::unique_ptr<A> up; - up = ap; - assert(up.get() == p); - assert(ap.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp deleted file mode 100644 index 2dd5ea30049b8..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/auto_pointer02.fail.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(pointer) ctor - -#include <memory> -#include <cassert> - -// template <class U> explicit unique_ptr(auto_ptr<U>&); - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -struct Deleter -{ - template <class T> - void operator()(T*) {} -}; - -int main() -{ - { - B* p = new B; - std::auto_ptr<B> ap(p); - std::unique_ptr<A, Deleter> up(ap); - assert(up.get() == p); - assert(ap.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp deleted file mode 100644 index 2694538145b90..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default.pass.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -//============================================================================= -// TESTING std::unique_ptr::unique_ptr() -// -// Concerns: -// 1 The default constructor works for any default constructible deleter types. -// 2 The stored type 'T' is allowed to be incomplete. -// -// Plan -// 1 Default construct unique_ptr's with various deleter types (C-1) -// 2 Default construct a unique_ptr with a incomplete element_type and -// various deleter types (C-1,2) - -#include <memory> -#include <cassert> - -#include "../../deleter.h" - -struct IncompleteT; - -void checkNumIncompleteTypeAlive(int i); - -template <class Del = std::default_delete<IncompleteT> > -struct StoresIncomplete { - std::unique_ptr<IncompleteT, Del> m_ptr; - StoresIncomplete() {} - ~StoresIncomplete(); - - IncompleteT* get() const { return m_ptr.get(); } - Del& get_deleter() { return m_ptr.get_deleter(); } -}; - -int main() -{ - { - std::unique_ptr<int> p; - assert(p.get() == 0); - } - { - std::unique_ptr<int, NCDeleter<int> > p; - assert(p.get() == 0); - assert(p.get_deleter().state() == 0); - p.get_deleter().set_state(5); - assert(p.get_deleter().state() == 5); - } - { - StoresIncomplete<> s; - assert(s.get() == 0); - checkNumIncompleteTypeAlive(0); - } - checkNumIncompleteTypeAlive(0); - { - StoresIncomplete< Deleter<IncompleteT> > s; - assert(s.get() == 0); - assert(s.get_deleter().state() == 0); - checkNumIncompleteTypeAlive(0); - } - checkNumIncompleteTypeAlive(0); -} - -struct IncompleteT { - static int count; - IncompleteT() { ++count; } - ~IncompleteT() {--count; } -}; - -int IncompleteT::count = 0; - -void checkNumIncompleteTypeAlive(int i) { - assert(IncompleteT::count == i); -} - -template <class Del> -StoresIncomplete<Del>::~StoresIncomplete() { }
\ No newline at end of file diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp deleted file mode 100644 index 2ffe1be190e0b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default01.fail.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr default ctor - -#include <memory> - -// default unique_ptr ctor should require default Deleter ctor -class Deleter -{ - - Deleter() {} - -public: - - Deleter(Deleter&) {} - Deleter& operator=(Deleter&) {} - - void operator()(void*) const {} -}; - -int main() -{ - std::unique_ptr<int, Deleter> p; -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp deleted file mode 100644 index 690750143414b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default02.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr default ctor - -#include <memory> - -// default unique_ptr ctor should require non-reference Deleter ctor -class Deleter -{ -public: - - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr<int, Deleter&> p; -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp deleted file mode 100644 index 78f6e73a1d55c..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/default03.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr default ctor - -#include <memory> - -// default unique_ptr ctor should require non-pointer Deleter - -int main() -{ - std::unique_ptr<int, void (*)(void*)> p; -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp deleted file mode 100644 index 4c5cc843a138c..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move.pass.cpp +++ /dev/null @@ -1,140 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.h" - -//============================================================================= -// TESTING unique_ptr(unique_ptr&&) -// -// Concerns -// 1 The moved from pointer is empty and the new pointer stores the old value. -// 2 The only requirement on the deleter is that it is MoveConstructible -// or a reference. -// 3 The constructor works for explicitly moved values (ie std::move(x)) -// 4 The constructor works for true temporaries (ie a return value) -// -// Plan -// 1 Explicitly construct unique_ptr<T, D> for various deleter types 'D'. -// check that the value and deleter have been properly moved. (C-1,2,3) -// -// 2 Use the expression 'sink(source())' to move construct a unique_ptr<T, D> -// from a temporary. 'source' should return the unique_ptr by value and -// 'sink' should accept the unique_ptr by value. (C-1,2,4) - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -template <class Expect> -void sinkFunction(Expect) -{ -} - -typedef std::unique_ptr<A> APtrSource1; -typedef std::unique_ptr<A, Deleter<A> > APtrSource2; -typedef std::unique_ptr<A, NCDeleter<A>& > APtrSource3; - -APtrSource1 source1() { - return APtrSource1 (new A); -} - -void sink1(APtrSource1 p) { - assert(p.get() != nullptr); -} - -APtrSource2 source2() { - return APtrSource2(new A, Deleter<A>(5)); -} - -void sink2(APtrSource2 p) { - assert(p.get() != nullptr); - assert(p.get_deleter().state() == 5); -} - -APtrSource3 source3() { - static NCDeleter<A> d(5); - return APtrSource3(new A, d); -} - -void sink3(APtrSource3 p) { - assert(p.get() != nullptr); - assert(p.get_deleter().state() == 5); - assert(&p.get_deleter() == &source3().get_deleter()); -} - -int main() -{ - { - typedef std::unique_ptr<A> APtr; - APtr s(new A); - A* p = s.get(); - APtr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); - { - typedef Deleter<A> MoveDel; - typedef std::unique_ptr<A, MoveDel> APtr; - MoveDel d(5); - APtr s(new A, std::move(d)); - assert(d.state() == 0); - assert(s.get_deleter().state() == 5); - A* p = s.get(); - APtr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(s2.get_deleter().state() == 5); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - { - typedef NCDeleter<A> NonCopyDel; - typedef std::unique_ptr<A, NonCopyDel&> APtr; - - NonCopyDel d; - APtr s(new A, d); - A* p = s.get(); - APtr s2 = std::move(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - { - sink1(source1()); - assert(A::count == 0); - sink2(source2()); - assert(A::count == 0); - sink3(source3()); - assert(A::count == 0); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp deleted file mode 100644 index 68ad589b11480..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move01.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <cassert> - -// test move ctor. Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A> s(new A); - A* p = s.get(); - std::unique_ptr<A> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp deleted file mode 100644 index 897b889d67789..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move02.fail.cpp +++ /dev/null @@ -1,42 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <cassert> - -// test move ctor. Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - const std::unique_ptr<A> s(new A); - A* p = s.get(); - std::unique_ptr<A> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp deleted file mode 100644 index 7fb1a0a748114..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move03.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <cassert> - -// test move ctor. Can't copy from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - std::unique_ptr<A, Deleter> s(new A); - A* p = s.get(); - std::unique_ptr<A, Deleter> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp deleted file mode 100644 index 671e343fd7f5d..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move04.fail.cpp +++ /dev/null @@ -1,55 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr move ctor - -#include <memory> -#include <cassert> - -// test move ctor. Can't copy from const lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -class Deleter -{ - int state_; - -public: - - Deleter() : state_(5) {} - - int state() const {return state_;} - - void operator()(A* p) {delete p;} -}; - -int main() -{ - { - const std::unique_ptr<A, Deleter> s(new A); - A* p = s.get(); - std::unique_ptr<A, Deleter> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp deleted file mode 100644 index f00fcfe15b808..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert.pass.cpp +++ /dev/null @@ -1,171 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// - -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// NOTE: unique_ptr does not provide converting constructors in c++03 -// XFAIL: c++98, c++03 - - - -#include <memory> -#include <type_traits> -#include <utility> -#include <cassert> - -#include "../../deleter.h" - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - - -template <class LHS, class RHS> -void checkReferenceDeleter(LHS& lhs, RHS& rhs) { - typedef typename LHS::deleter_type NewDel; - static_assert(std::is_reference<NewDel>::value, ""); - rhs.get_deleter().set_state(42); - assert(rhs.get_deleter().state() == 42); - assert(lhs.get_deleter().state() == 42); - lhs.get_deleter().set_state(99); - assert(lhs.get_deleter().state() == 99); - assert(rhs.get_deleter().state() == 99); -} - -template <class LHS, class RHS> -void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) { - assert(lhs.get_deleter().state() == LHSVal); - assert(rhs.get_deleter().state() == RHSVal); -} - -template <class LHS, class RHS> -void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) { - assert(lhs.get() == RHSVal); - assert(rhs.get() == nullptr); - assert(A::count == 1); - assert(B::count == 1); -} - -void checkNoneAlive() { - assert(A::count == 0); - assert(B::count == 0); -} - -int main() -{ - { - typedef std::unique_ptr<A> APtr; - typedef std::unique_ptr<B> BPtr; - { // explicit - BPtr b(new B); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - } - checkNoneAlive(); - { // implicit - BPtr b(new B); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - } - checkNoneAlive(); - } - { // test with moveable deleters - typedef std::unique_ptr<A, Deleter<A> > APtr; - typedef std::unique_ptr<B, Deleter<B> > BPtr; - { - Deleter<B> del(5); - BPtr b(new B, std::move(del)); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 0); - } - checkNoneAlive(); - { - Deleter<B> del(5); - BPtr b(new B, std::move(del)); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 0); - } - checkNoneAlive(); - - } - { // test with reference deleters - typedef std::unique_ptr<A, NCDeleter<A>& > APtr; - typedef std::unique_ptr<B, NCDeleter<A>& > BPtr; - NCDeleter<A> del(5); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - checkReferenceDeleter(a, b); - } - checkNoneAlive(); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - checkReferenceDeleter(a, b); - } - checkNoneAlive(); - } - { - typedef std::unique_ptr<A, CDeleter<A> > APtr; - typedef std::unique_ptr<B, CDeleter<B>& > BPtr; - CDeleter<B> del(5); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a(std::move(b)); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 5); - } - checkNoneAlive(); - { - BPtr b(new B, del); - A* p = b.get(); - APtr a = std::move(b); - checkCtor(a, b, p); - checkDeleter(a, b, 5, 5); - } - checkNoneAlive(); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp deleted file mode 100644 index ed1fe8c2bdd4b..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert01.fail.cpp +++ /dev/null @@ -1,56 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// Can't construct from lvalue - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B> s(new B); - A* p = s.get(); - std::unique_ptr<A> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp deleted file mode 100644 index a1bf634b9995e..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert02.fail.cpp +++ /dev/null @@ -1,62 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp deleted file mode 100644 index 7409199791b56..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert03.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template <class T> -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter<A> d; - std::unique_ptr<B, CDeleter<A>&> s(new B, d); - A* p = s.get(); - std::unique_ptr<A, CDeleter<A>&> s2(s); - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp deleted file mode 100644 index 981ea706eb293..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert04.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - std::unique_ptr<B> s(new B); - A* p = s.get(); - std::unique_ptr<A> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp deleted file mode 100644 index d055b80627f91..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert05.fail.cpp +++ /dev/null @@ -1,51 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp deleted file mode 100644 index 5b9b12e0d60ba..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert06.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template <class T> -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter<A> d; - std::unique_ptr<B, CDeleter<A>&> s(new B, d); - A* p = s.get(); - std::unique_ptr<A, CDeleter<A>&> s2 = s; - assert(s2.get() == p); - assert(s.get() == 0); - assert(A::count == 1); - assert(B::count == 1); - d.set_state(6); - assert(s2.get_deleter().state() == d.state()); - assert(s.get_deleter().state() == d.state()); - } - assert(A::count == 0); - assert(B::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp deleted file mode 100644 index bef022cfc1434..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert07.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp deleted file mode 100644 index 016eadcb24607..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert08.fail.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++98, c++03 - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template <class T> -class Deleter -{ - int state_; - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); - -public: - Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} - Deleter& operator=(Deleter&& r) - { - state_ = r.state_; - r.state_ = 0; - return *this; - } - - Deleter() : state_(5) {} - - 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); - -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; - std::unique_ptr<A, Deleter<A> > s2(s); // expected-error {{no matching constructor}} -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp deleted file mode 100644 index a475c17547c92..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert09.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template <class T> -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter<A> d; - 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp deleted file mode 100644 index f0da5efb69174..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert10.fail.cpp +++ /dev/null @@ -1,58 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -int main() -{ - { - 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp deleted file mode 100644 index 1b8bb736df200..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert11.fail.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// UNSUPPORTED: c++98, c++03 - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Implicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template <class T> -class Deleter -{ - int state_; - - Deleter(const Deleter&); - Deleter& operator=(const Deleter&); -public: - Deleter(Deleter&& r) : state_(r.state_) {r.state_ = 0;} - Deleter& operator=(Deleter&& r) - { - state_ = r.state_; - r.state_ = 0; - return *this; - } - - Deleter() : state_(5) {} - - 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); - -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; - std::unique_ptr<A, Deleter<A> > s2 = s; // expected-error {{no viable conversion}} -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp deleted file mode 100644 index 095bec65669b3..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert12.fail.cpp +++ /dev/null @@ -1,79 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -#include <memory> -#include <utility> -#include <cassert> - -// test converting move ctor. Should only require a MoveConstructible deleter, or if -// deleter is a reference, not even that. -// Explicit version - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -template <class T> -class CDeleter -{ - int state_; - - CDeleter(CDeleter&); - CDeleter& operator=(CDeleter&); -public: - - CDeleter() : state_(5) {} - - int state() const {return state_;} - void set_state(int s) {state_ = s;} - - void operator()(T* p) {delete p;} -}; - -int main() -{ - { - CDeleter<A> d; - 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp deleted file mode 100644 index a4bd2cba1cef8..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/move_convert13.fail.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr converting move ctor - -// Do not convert from an array unique_ptr - -#include <memory> -#include <utility> -#include <cassert> - -struct A -{ -}; - -struct Deleter -{ - void operator()(void*) {} -}; - -int main() -{ - std::unique_ptr<A[], Deleter> s; - std::unique_ptr<A, Deleter> s2(std::move(s)); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp deleted file mode 100644 index 67a48a3e7a12f..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/nullptr.pass.cpp +++ /dev/null @@ -1,46 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp deleted file mode 100644 index faa554d8b3209..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer.pass.cpp +++ /dev/null @@ -1,163 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -//============================================================================= -// TESTING std::unique_ptr::unique_ptr() -// -// Concerns: -// 1 The pointer constructor works for any default constructible deleter types. -// 2 The pointer constructor accepts pointers to derived types. -// 2 The stored type 'T' is allowed to be incomplete. -// -// Plan -// 1 Construct unique_ptr<T, D>'s with a pointer to 'T' and various deleter -// types (C-1) -// 2 Construct unique_ptr<T, D>'s with a pointer to 'D' and various deleter -// types where 'D' is derived from 'T'. (C-1,2) -// 3 Construct a unique_ptr<T, D> with a pointer to 'T' and various deleter -// types where 'T' is an incomplete type (C-1,3) - -// Test unique_ptr(pointer) ctor - -#include <memory> -#include <cassert> - -#include "../../deleter.h" - -// unique_ptr(pointer) ctor should only require default Deleter ctor - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - - -struct IncompleteT; - -IncompleteT* getIncomplete(); -void checkNumIncompleteTypeAlive(int i); - -template <class Del = std::default_delete<IncompleteT> > -struct StoresIncomplete { - std::unique_ptr<IncompleteT, Del> m_ptr; - StoresIncomplete() {} - explicit StoresIncomplete(IncompleteT* ptr) : m_ptr(ptr) {} - ~StoresIncomplete(); - - IncompleteT* get() const { return m_ptr.get(); } - Del& get_deleter() { return m_ptr.get_deleter(); } -}; - -void test_pointer() -{ - { - A* p = new A; - assert(A::count == 1); - std::unique_ptr<A> s(p); - assert(s.get() == p); - } - assert(A::count == 0); - { - A* p = new A; - assert(A::count == 1); - std::unique_ptr<A, NCDeleter<A> > s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); -} - -void test_derived() -{ - { - B* p = new B; - assert(A::count == 1); - assert(B::count == 1); - std::unique_ptr<A> s(p); - assert(s.get() == p); - } - assert(A::count == 0); - assert(B::count == 0); - { - B* p = new B; - assert(A::count == 1); - assert(B::count == 1); - std::unique_ptr<A, NCDeleter<A> > s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - assert(A::count == 0); - assert(B::count == 0); -} - -void test_incomplete() -{ - { - IncompleteT* p = getIncomplete(); - checkNumIncompleteTypeAlive(1); - StoresIncomplete<> s(p); - assert(s.get() == p); - } - checkNumIncompleteTypeAlive(0); - { - IncompleteT* p = getIncomplete(); - checkNumIncompleteTypeAlive(1); - StoresIncomplete< NCDeleter<IncompleteT> > s(p); - assert(s.get() == p); - assert(s.get_deleter().state() == 0); - } - checkNumIncompleteTypeAlive(0); -} - -struct IncompleteT { - static int count; - IncompleteT() { ++count; } - ~IncompleteT() {--count; } -}; - -int IncompleteT::count = 0; - -IncompleteT* getIncomplete() { - return new IncompleteT; -} - -void checkNumIncompleteTypeAlive(int i) { - assert(IncompleteT::count == i); -} - -template <class Del> -StoresIncomplete<Del>::~StoresIncomplete() { } - -int main() -{ - test_pointer(); - test_derived(); - test_incomplete(); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp deleted file mode 100644 index 1af04b2c00338..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer01.fail.cpp +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp deleted file mode 100644 index 9b7dd8c70f280..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer02.fail.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp deleted file mode 100644 index a917d87eeeded..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer03.fail.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// Test unique_ptr(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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp deleted file mode 100644 index 7ddd162651078..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter.pass.cpp +++ /dev/null @@ -1,123 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -//============================================================================= -// TESTING unique_ptr(pointer, deleter) -// -// Concerns: -// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter. -// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter. -// 3 unique_ptr<T, D&>(pointer, deleter) does not require a CopyConstructible deleter. -// 4 unique_ptr<T, D const&>(pointer, deleter) does not require a CopyConstructible deleter. -// 5 unique_ptr(pointer, deleter) should work for derived pointers. -// 6 unique_ptr(pointer, deleter) should work with function pointers. -// 7 unique_ptr<void> should work. - - -#include <memory> -#include <cassert> - -#include "../../deleter.h" - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; - -int A::count = 0; - - -struct B - : public A -{ - static int count; - B() {++count;} - B(const B&) {++count;} - virtual ~B() {--count;} -}; - -int B::count = 0; - -bool my_free_called = false; - -void my_free(void*) { - my_free_called = true; -} - -int main() -{ - { // MoveConstructible deleter (C-1) - A* p = new A; - assert(A::count == 1); - std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5)); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { // CopyConstructible deleter (C-2) - A* p = new A; - assert(A::count == 1); - CopyDeleter<A> d(5); - std::unique_ptr<A, CopyDeleter<A> > s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - { // Reference deleter (C-3) - A* p = new A; - assert(A::count == 1); - NCDeleter<A> d(5); - std::unique_ptr<A, NCDeleter<A>&> s(p, d); - assert(s.get() == p); - assert(&s.get_deleter() == &d); - assert(s.get_deleter().state() == 5); - d.set_state(6); - assert(s.get_deleter().state() == 6); - } - assert(A::count == 0); - { // Const Reference deleter (C-4) - A* p = new A; - assert(A::count == 1); - NCConstDeleter<A> d(5); - std::unique_ptr<A, NCConstDeleter<A> const&> s(p, d); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - assert(&s.get_deleter() == &d); - } - assert(A::count == 0); - { // Derived pointers (C-5) - B* p = new B; - assert(A::count == 1); - assert(B::count == 1); - std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5)); - assert(s.get() == p); - assert(s.get_deleter().state() == 5); - } - assert(A::count == 0); - assert(B::count == 0); - { // Void and function pointers (C-6,7) - { - int i = 0; - std::unique_ptr<void, void(*)(void*)> s(&i, my_free); - assert(s.get() == &i); - assert(s.get_deleter() == my_free); - assert(!my_free_called); - } - assert(my_free_called); - } -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp deleted file mode 100644 index dadd4ecbe5901..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/release.pass.cpp +++ /dev/null @@ -1,27 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test 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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp deleted file mode 100644 index 2cf7f8b775683..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset1.pass.cpp +++ /dev/null @@ -1,50 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test reset - -#include <memory> -#include <cassert> - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; - -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A> p(new A); - assert(A::count == 1); - A* i = p.get(); - assert(i != nullptr); - p.reset(); - assert(A::count == 0); - assert(p.get() == 0); - } - assert(A::count == 0); - { - std::unique_ptr<A> p(new A); - assert(A::count == 1); - A* i = p.get(); - assert(i != nullptr); - p.reset(new A); - assert(A::count == 1); - } - assert(A::count == 0); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp deleted file mode 100644 index d0a03be803269..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/swap.pass.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test swap - -#include <memory> -#include <cassert> - -#include "../../deleter.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/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp deleted file mode 100644 index 24fa6beb42733..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get.pass.cpp +++ /dev/null @@ -1,24 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test get - -#include <memory> -#include <cassert> - -int main() -{ - int* p = new int; - std::unique_ptr<int> s(p); - assert(s.get() == p); -} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp b/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp deleted file mode 100644 index 5ed8a22b14c45..0000000000000 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/get_deleter.pass.cpp +++ /dev/null @@ -1,37 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// unique_ptr - -// test get_deleter() - -#include <memory> -#include <cassert> - -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/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp index b9f8ee0746c31..5a0d9259c11d4 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.enab/enable_shared_from_this.pass.cpp @@ -51,11 +51,11 @@ struct Bar : public Foo { int main() { - { // https://llvm.org/bugs/show_bug.cgi?id=18843 + { // https://bugs.llvm.org/show_bug.cgi?id=18843 std::shared_ptr<T const> t1(new T); std::shared_ptr<T const> t2(std::make_shared<T>()); } - { // https://llvm.org/bugs/show_bug.cgi?id=27115 + { // https://bugs.llvm.org/show_bug.cgi?id=27115 int x = 42; std::shared_ptr<Bar> t1(new Bar(42)); assert(t1->shared_from_this() == t1); @@ -84,12 +84,12 @@ int main() T* ptr = new T; std::shared_ptr<T> s(ptr); { - // Don't re-initialize the "enabled_shared_from_this" base + // Don't re-initialize the "enable_shared_from_this" base // because it already references a non-expired shared_ptr. std::shared_ptr<T> s2(ptr, &nullDeleter); } #if TEST_STD_VER > 14 - // The enabled_shared_from_this base should still be referencing + // The enable_shared_from_this base should still be referencing // the original shared_ptr. assert(!ptr->weak_from_this().expired()); #endif diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/enabled_hash.pass.cpp index 31f7ce367e3dc..e9237c534fba5 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer03.fail.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/enabled_hash.pass.cpp @@ -7,17 +7,17 @@ // //===----------------------------------------------------------------------===// -// <memory> - -// unique_ptr +// UNSUPPORTED: c++98, c++03 -// Test unique_ptr<T[]>(pointer) ctor +// <memory> -// unique_ptr<T[]>(pointer) ctor should require non-pointer Deleter +// Test that <memory> provides all of the arithmetic, enum, and pointer +// hash specializations. #include <memory> -int main() -{ - std::unique_ptr<int[], void (*)(void*)> p(new int); +#include "poisoned_hash_helper.hpp" + +int main() { + test_library_hash_specializations_available(); } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp index 990cb58722b1c..5fba1fc0460ba 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_shared_ptr.pass.cpp @@ -20,11 +20,25 @@ #include <memory> #include <cassert> +#if TEST_STD_VER >= 11 +#include "poisoned_hash_helper.hpp" + +struct A {}; +#endif + 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)); + } +#if TEST_STD_VER >= 11 + { + test_hash_enabled_for_type<std::shared_ptr<int>>(); + test_hash_enabled_for_type<std::shared_ptr<A>>(); + } +#endif } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp index 5cd4ab1f83d0e..fc346d4dce7df 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.hash/hash_unique_ptr.pass.cpp @@ -20,11 +20,80 @@ #include <memory> #include <cassert> +#include "test_macros.h" + +#if TEST_STD_VER >= 11 +#include "poisoned_hash_helper.hpp" +#include "deleter_types.h" +#include "min_allocator.h" + +template <class ValueT, class Del> +void test_enabled_with_deleter() { + using UPtr = std::unique_ptr<ValueT, Del>; + using pointer = typename UPtr::pointer; + using RawDel = typename std::decay<Del>::type; + RawDel d(1); + UPtr p(nullptr, std::forward<Del>(d)); + test_hash_enabled_for_type<UPtr>(p); + test_hash_enabled_for_type<pointer>(); +} + +template <class ValueT, class Del> +void test_disabled_with_deleter() { + using UPtr = std::unique_ptr<ValueT, Del>; + using pointer = typename UPtr::pointer; + test_hash_disabled_for_type<UPtr>(); + test_hash_disabled_for_type<pointer>(); +} + +namespace std { + +template <class T> +struct hash<::min_pointer<T, std::integral_constant<size_t, 1>>> { + size_t operator()(::min_pointer<T, std::integral_constant<size_t, 1>> p) const noexcept(false) { + if (!p) return 0; + return std::hash<T*>{}(std::addressof(*p)); + } +}; +} + +struct A {}; + +#endif // TEST_STD_VER >= 11 + int main() { + { int* ptr = new int; std::unique_ptr<int> p(ptr); std::hash<std::unique_ptr<int> > f; + ASSERT_NOT_NOEXCEPT(f(p)); std::size_t h = f(p); assert(h == std::hash<int*>()(ptr)); + } +#if TEST_STD_VER >= 11 + { + test_enabled_with_deleter<int, Deleter<int>>(); + test_enabled_with_deleter<int[], Deleter<int[]>>(); + test_enabled_with_deleter<int, CopyDeleter<int>>(); + test_enabled_with_deleter<int, CopyDeleter<int[]>>(); + test_enabled_with_deleter<int, NCDeleter<int>&>(); + test_enabled_with_deleter<int[], NCDeleter<int[]>&>(); + test_enabled_with_deleter<int, NCConstDeleter<int> const&>(); + test_enabled_with_deleter<int[], NCConstDeleter<int[]> const&>(); + } + { + test_enabled_with_deleter<int, PointerDeleter<int, 1>>(); + test_enabled_with_deleter<int[], PointerDeleter<int[], 1>>(); + test_enabled_with_deleter<A, PointerDeleter<A, 1>>(); + test_enabled_with_deleter<A[], PointerDeleter<A[], 1>>(); + +#if TEST_STD_VER > 14 + test_disabled_with_deleter<int, PointerDeleter<int, 0>>(); + test_disabled_with_deleter<int[], PointerDeleter<int[], 0>>(); + test_disabled_with_deleter<A, PointerDeleter<A, 0>>(); + test_disabled_with_deleter<A[], PointerDeleter<A[], 0>>(); +#endif + } +#endif } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp index 3bad537e34315..d1e13139bce36 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp index 5cc1234ad34ee..08e31e8d7d700 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_strong_explicit.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp index a89c0dbd2207c..f8f550deb0513 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp index 821cea6868e48..1ea11ceed43d9 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_compare_exchange_weak_explicit.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp index 66be756d54fd6..9a5792f519d5f 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp index 493ba7fcc94d0..aac9af082d74e 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_exchange_explicit.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp index 4820d05420a2f..fa79e7cdd9ad4 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp index ef8dc822102ff..c650899f764ac 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_load_explicit.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp index a13a7d57ab960..cbcc4ddbbc2ca 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp index 6dfe3166c8c58..eb5e246833c2b 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared.atomic/atomic_store_explicit.pass.cpp @@ -11,8 +11,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // <memory> diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h deleted file mode 100644 index 6b3f1e2ab0dea..0000000000000 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/test_deleter.h +++ /dev/null @@ -1,70 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// <memory> - -// shared_ptr - -// Example move-only deleter - -#ifndef DELETER_H -#define DELETER_H - -#include <type_traits> -#include <cassert> - -#include "test_macros.h" - -#if TEST_STD_VER >= 11 -#define DELETE_FUNCTION = delete -#else -#define DELETE_FUNCTION { assert(false); } -#endif - -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;} - - test_deleter* operator&() const DELETE_FUNCTION; -}; - -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/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp index a6c62496fd62f..05a199cced639 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.getdeleter/get_deleter.pass.cpp @@ -15,7 +15,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp index 21cdf4a13e476..10d53c1268aa2 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.assign/auto_ptr_Y.pass.cpp @@ -10,6 +10,7 @@ // <memory> // shared_ptr +// REQUIRES: c++98 || c++03 || c++11 || c++14 // template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp index f8fdb7a094782..3ad3232a90b41 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/auto_ptr.pass.cpp @@ -10,6 +10,7 @@ // <memory> // template<class Y> explicit shared_ptr(auto_ptr<Y>&& r); +// REQUIRES: c++98 || c++03 || c++11 || c++14 #include <memory> @@ -85,6 +86,7 @@ int main() // Without rvalue references, ptr got copied into // the shared_ptr destructor and the copy was // destroyed during unwinding. + (void) raw_ptr; // silence 'unused variable' warning assert(A::count == 0); assert(B::count == 0); #endif diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp index 7d4dc38d4b9a0..bf2a304011c8d 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter.pass.cpp @@ -15,7 +15,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp index 8a6cd0f352ff7..aabc66a03c40e 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator.pass.cpp @@ -13,7 +13,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" #include "test_allocator.h" #include "min_allocator.h" diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp index 2e6441d663160..55e52f49c752c 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_allocator_throw.pass.cpp @@ -14,7 +14,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" #include "test_allocator.h" struct A diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp index 009b4cfc00f9a..e82f0fdcc9ed8 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/nullptr_t_deleter_throw.pass.cpp @@ -24,7 +24,7 @@ #include "test_macros.h" #include "count_new.hpp" -#include "../test_deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp index 43eedee176c2c..c813f6f6f9c5a 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter.pass.cpp @@ -15,7 +15,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp index b0facfc1a6eb5..96a1779fe870e 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator.pass.cpp @@ -13,7 +13,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" #include "test_allocator.h" #include "min_allocator.h" diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp index 388599bd70157..47d24c349871b 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_allocator_throw.pass.cpp @@ -14,7 +14,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" #include "test_allocator.h" struct A diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp index 7b40d6df2164b..13c2d435b93a7 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/pointer_deleter_throw.pass.cpp @@ -22,7 +22,7 @@ #include <cstdlib> #include "count_new.hpp" -#include "../test_deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp index 877577c9ce58a..17289197d35e3 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.const/unique_ptr.pass.cpp @@ -80,6 +80,7 @@ int main() assert(B::count == 1); assert(ptr.get() == raw_ptr); #else + (void) raw_ptr; // silence 'unused variable' warning assert(A::count == 0); assert(B::count == 0); assert(ptr.get() == 0); diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp index 8d782716b94f0..2a7ac9979d025 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.create/make_shared.pass.cpp @@ -59,7 +59,7 @@ int main() assert(p->get_char() == 'e'); } - { // https://llvm.org/bugs/show_bug.cgi?id=24137 + { // https://bugs.llvm.org/show_bug.cgi?id=24137 std::shared_ptr<Foo> p1 = std::make_shared<Foo>(); assert(p1.get()); std::shared_ptr<const Foo> p2 = std::make_shared<const Foo>(); diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp index 33965dfeb33c0..c33133d79fdc8 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter.pass.cpp @@ -15,7 +15,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" struct B { diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp index 09070e2c059b0..58262eb4334eb 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.mod/reset_pointer_deleter_allocator.pass.cpp @@ -15,7 +15,7 @@ #include <memory> #include <cassert> -#include "../test_deleter.h" +#include "deleter_types.h" #include "test_allocator.h" struct B diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp index 3acd2f8c6f2d4..9f6f1bc75c71a 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_shared_ptr.pass.cpp @@ -11,10 +11,11 @@ // shared_ptr -// template <class U> bool owner_before(shared_ptr<U> const& b) const; +// template <class U> bool owner_before(shared_ptr<U> const& b) const noexcept; #include <memory> #include <cassert> +#include "test_macros.h" int main() { @@ -25,4 +26,5 @@ int main() assert(!p2.owner_before(p1)); assert(p1.owner_before(p3) || p3.owner_before(p1)); assert(p3.owner_before(p1) == p3.owner_before(p2)); + ASSERT_NOEXCEPT(p1.owner_before(p2)); } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp index 33447ba7da00f..560293bbedb7c 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.shared/util.smartptr.shared.obs/owner_before_weak_ptr.pass.cpp @@ -11,10 +11,11 @@ // shared_ptr -// template <class U> bool owner_before(weak_ptr<U> const& b) const; +// template <class U> bool owner_before(weak_ptr<U> const& b) const noexcept; #include <memory> #include <cassert> +#include "test_macros.h" int main() { @@ -28,4 +29,5 @@ int main() assert(!p2.owner_before(w1)); assert(p1.owner_before(w3) || p3.owner_before(w1)); assert(p3.owner_before(w1) == p3.owner_before(w2)); + ASSERT_NOEXCEPT(p1.owner_before(w2)); } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp index 142eba2d96478..7ab60da77c7d7 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.ownerless/owner_less.pass.cpp @@ -16,9 +16,9 @@ // : 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; +// bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; +// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; +// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; // }; // // template <class T> @@ -26,22 +26,22 @@ // : 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; +// bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; +// bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; +// bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; // }; // // Added in C++17 // template<> struct owner_less<void> // { // template<class T, class U> -// bool operator()(shared_ptr<T> const&, shared_ptr<U> const&) const; +// bool operator()(shared_ptr<T> const&, shared_ptr<U> const&) const noexcept; // template<class T, class U> -// bool operator()(shared_ptr<T> const&, weak_ptr<U> const&) const; +// bool operator()(shared_ptr<T> const&, weak_ptr<U> const&) const noexcept; // template<class T, class U> -// bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const; +// bool operator()(weak_ptr<T> const&, shared_ptr<U> const&) const noexcept; // template<class T, class U> -// bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const; +// bool operator()(weak_ptr<T> const&, weak_ptr<U> const&) const noexcept; // // typedef unspecified is_transparent; // }; @@ -69,16 +69,19 @@ int main() static_assert((std::is_same<std::shared_ptr<int>, CS::first_argument_type>::value), "" ); static_assert((std::is_same<std::shared_ptr<int>, CS::second_argument_type>::value), "" ); static_assert((std::is_same<bool, CS::result_type>::value), "" ); - + assert(!cs(p1, p2)); assert(!cs(p2, p1)); assert(cs(p1 ,p3) || cs(p3, p1)); assert(cs(p3, p1) == cs(p3, p2)); + ASSERT_NOEXCEPT(cs(p1, p1)); assert(!cs(p1, w2)); assert(!cs(p2, w1)); assert(cs(p1, w3) || cs(p3, w1)); assert(cs(p3, w1) == cs(p3, w2)); + ASSERT_NOEXCEPT(cs(p1, w1)); + ASSERT_NOEXCEPT(cs(w1, p1)); } { typedef std::owner_less<std::weak_ptr<int> > CS; @@ -92,11 +95,14 @@ int main() assert(!cs(w2, w1)); assert(cs(w1, w3) || cs(w3, w1)); assert(cs(w3, w1) == cs(w3, w2)); + ASSERT_NOEXCEPT(cs(w1, w1)); assert(!cs(w1, p2)); assert(!cs(w2, p1)); assert(cs(w1, p3) || cs(w3, p1)); assert(cs(w3, p1) == cs(w3, p2)); + ASSERT_NOEXCEPT(cs(w1, p1)); + ASSERT_NOEXCEPT(cs(p1, w1)); } #if TEST_STD_VER > 14 { @@ -111,6 +117,10 @@ int main() cmp(sp1, sp3); cmp(wp1, sp1); cmp(wp1, wp1); + ASSERT_NOEXCEPT(cmp(sp1, sp1)); + ASSERT_NOEXCEPT(cmp(sp1, wp1)); + ASSERT_NOEXCEPT(cmp(wp1, sp1)); + ASSERT_NOEXCEPT(cmp(wp1, wp1)); } { // test heterogeneous lookups diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp index 4aa49cfe8a24d..458f8a11ed120 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_shared_ptr.pass.cpp @@ -11,10 +11,11 @@ // weak_ptr -// template<class U> bool owner_before(const shared_ptr<U>& b); +// template<class U> bool owner_before(const shared_ptr<U>& b) const noexcept; #include <memory> #include <cassert> +#include "test_macros.h" int main() { @@ -28,4 +29,6 @@ int main() assert(!w2.owner_before(p1)); assert(w1.owner_before(p3) || w3.owner_before(p1)); assert(w3.owner_before(p1) == w3.owner_before(p2)); +// change to 'ASSERT_NOEXCEPT' when LWG2942 is adopted + LIBCPP_ASSERT_NOEXCEPT(w1.owner_before(p2)); } diff --git a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp index 9fe2b6e390350..5cd171a53021d 100644 --- a/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp +++ b/test/std/utilities/memory/util.smartptr/util.smartptr.weak/util.smartptr.weak.obs/owner_before_weak_ptr.pass.cpp @@ -11,10 +11,11 @@ // weak_ptr -// template<class U> bool owner_before(const weak_ptr<U>& b); +// template<class U> bool owner_before(const weak_ptr<U>& b) const noexcept; #include <memory> #include <cassert> +#include "test_macros.h" int main() { @@ -28,4 +29,6 @@ int main() assert(!w2.owner_before(w1)); assert(w1.owner_before(w3) || w3.owner_before(w1)); assert(w3.owner_before(w1) == w3.owner_before(w2)); +// change to 'ASSERT_NOEXCEPT' when LWG2942 is adopted + LIBCPP_ASSERT_NOEXCEPT(w1.owner_before(w2)); } diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp index 61523e4872d46..85b14726617f8 100644 --- a/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/common_type.pass.cpp @@ -37,8 +37,16 @@ namespace std typedef S<T> type; }; +// P0548 + template <class T> + struct common_type< ::S<T>, ::S<T> > { + typedef S<T> type; + }; + template <> struct common_type< ::S<long>, long> {}; template <> struct common_type<long, ::S<long> > {}; + template <> struct common_type< ::X<float> > {}; + template <> struct common_type< ::X<double>, ::X<double> > {}; } #if TEST_STD_VER >= 11 @@ -88,6 +96,9 @@ void test_bullet_two() { static_assert(std::is_same<CommonType<int const>, int>::value, ""); static_assert(std::is_same<CommonType<int volatile[]>, int volatile*>::value, ""); static_assert(std::is_same<CommonType<void(&)()>, void(*)()>::value, ""); + + static_assert(no_common_type<X<float> >::value, ""); + static_assert(no_common_type<X<double> >::value, ""); } template <class T, class U, class Expect> @@ -284,4 +295,18 @@ int main() test_bullet_three_two(); test_bullet_four(); #endif + +// P0548 + static_assert((std::is_same<std::common_type<S<int> >::type, S<int> >::value), ""); + static_assert((std::is_same<std::common_type<S<int>, S<int> >::type, S<int> >::value), ""); + + static_assert((std::is_same<std::common_type<int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<const int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<volatile int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<const volatile int>::type, int>::value), ""); + + static_assert((std::is_same<std::common_type<int, int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<const int, int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<int, const int>::type, int>::value), ""); + static_assert((std::is_same<std::common_type<const int, const int>::type, int>::value), ""); } diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp index bcd8398494533..4f45a0340a916 100644 --- a/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/decay.pass.cpp @@ -33,4 +33,10 @@ int main() test_decay<int[3], int*>(); test_decay<const int[3], const int*>(); test_decay<void(), void (*)()>(); +#if TEST_STD_VER > 11 + test_decay<int(int) const, int(int) const>(); + test_decay<int(int) volatile, int(int) volatile>(); + test_decay<int(int) &, int(int) &>(); + test_decay<int(int) &&, int(int) &&>(); +#endif } diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp index 8cb5853bbc6d7..eac4e4a089fed 100644 --- a/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/result_of11.pass.cpp @@ -26,7 +26,6 @@ struct wat struct F {}; struct FD : public F {}; -struct NotDerived {}; template <class T, class U> void test_result_of_imp() @@ -43,7 +42,6 @@ void test_result_of_imp() int main() { - typedef NotDerived ND; { typedef char F::*PMD; test_result_of_imp<PMD(F &), char &>(); diff --git a/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp b/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp index 410e47e03bcc2..b00798b72240c 100644 --- a/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp +++ b/test/std/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp @@ -17,24 +17,32 @@ #include "test_macros.h" enum E { V = INT_MIN }; -enum F { W = UINT_MAX }; -int main() -{ #if !defined(_WIN32) || defined(__MINGW32__) - typedef unsigned ExpectUnsigned; + #define TEST_UNSIGNED_UNDERLYING_TYPE 1 #else - typedef int ExpectUnsigned; // MSVC's ABI doesn't follow the Standard + #define TEST_UNSIGNED_UNDERLYING_TYPE 0 // MSVC's ABI doesn't follow the Standard #endif + +#if TEST_UNSIGNED_UNDERLYING_TYPE +enum F { W = UINT_MAX }; +#endif // TEST_UNSIGNED_UNDERLYING_TYPE + +int main() +{ static_assert((std::is_same<std::underlying_type<E>::type, int>::value), "E has the wrong underlying type"); - static_assert((std::is_same<std::underlying_type<F>::type, ExpectUnsigned>::value), +#if TEST_UNSIGNED_UNDERLYING_TYPE + static_assert((std::is_same<std::underlying_type<F>::type, unsigned>::value), "F has the wrong underlying type"); +#endif // TEST_UNSIGNED_UNDERLYING_TYPE #if TEST_STD_VER > 11 static_assert((std::is_same<std::underlying_type_t<E>, int>::value), ""); - static_assert((std::is_same<std::underlying_type_t<F>, ExpectUnsigned>::value), ""); -#endif +#if TEST_UNSIGNED_UNDERLYING_TYPE + static_assert((std::is_same<std::underlying_type_t<F>, unsigned>::value), ""); +#endif // TEST_UNSIGNED_UNDERLYING_TYPE +#endif // TEST_STD_VER > 11 #if TEST_STD_VER >= 11 enum G : char { }; @@ -43,6 +51,6 @@ int main() "G has the wrong underlying type"); #if TEST_STD_VER > 11 static_assert((std::is_same<std::underlying_type_t<G>, char>::value), ""); -#endif +#endif // TEST_STD_VER > 11 #endif // TEST_STD_VER >= 11 } diff --git a/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp b/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp index 05ef99d0ebf4d..2d10fb0040a7e 100644 --- a/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp +++ b/test/std/utilities/meta/meta.unary.prop.query/void_t.pass.cpp @@ -13,7 +13,7 @@ // UNSUPPORTED: c++98, c++03, c++11, c++14 -// XFAIL: gcc-5.1 gcc-5.2 +// XFAIL: gcc-5.1, gcc-5.2 #include <type_traits> diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/is_function.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/is_function.pass.cpp index 32e4f06beb04e..c340ba69cda3c 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.cat/is_function.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/is_function.pass.cpp @@ -13,6 +13,7 @@ #include <type_traits> #include <cstddef> // for std::nullptr_t + #include "test_macros.h" template <class T> @@ -79,22 +80,27 @@ int main() test_is_function<int(Abstract *)>(); test_is_function<void(...)>(); - test_is_not_function<std::nullptr_t>(); - test_is_not_function<void>(); - test_is_not_function<int>(); - test_is_not_function<int&>(); - test_is_not_function<int&&>(); - test_is_not_function<int*>(); - test_is_not_function<double>(); - test_is_not_function<char[3]>(); - test_is_not_function<char[]>(); - test_is_not_function<Union>(); - test_is_not_function<Enum>(); - test_is_not_function<FunctionPtr>(); // function pointer is not a function - test_is_not_function<Empty>(); - test_is_not_function<bit_zero>(); - test_is_not_function<NotEmpty>(); - test_is_not_function<Abstract>(); - test_is_not_function<Abstract*>(); - test_is_not_function<incomplete_type>(); + test_is_not_function<std::nullptr_t>(); + test_is_not_function<void>(); + test_is_not_function<int>(); + test_is_not_function<int&>(); + test_is_not_function<int&&>(); + test_is_not_function<int*>(); + test_is_not_function<double>(); + test_is_not_function<char[3]>(); + test_is_not_function<char[]>(); + test_is_not_function<Union>(); + test_is_not_function<Enum>(); + test_is_not_function<FunctionPtr>(); // function pointer is not a function + test_is_not_function<Empty>(); + test_is_not_function<bit_zero>(); + test_is_not_function<NotEmpty>(); + test_is_not_function<Abstract>(); + test_is_not_function<Abstract*>(); + test_is_not_function<incomplete_type>(); + +#if TEST_STD_VER >= 11 + test_is_function<void() noexcept>(); + test_is_function<void() const && noexcept>(); +#endif } diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/is_member_pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/is_member_pointer.pass.cpp index d4043f48f98ed..a63a88c4d18bd 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.cat/is_member_pointer.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/is_member_pointer.pass.cpp @@ -97,4 +97,10 @@ int main() test_is_not_member_pointer<NotEmpty>(); test_is_not_member_pointer<Abstract>(); test_is_not_member_pointer<incomplete_type>(); + +#if TEST_STD_VER >= 11 + test_is_member_pointer<int (Empty::*)(int, ...) const>(); + test_is_member_pointer<int (Empty::*)(int, long, long) const noexcept>(); + test_is_member_pointer<int (Empty::*)() & noexcept>(); +#endif } diff --git a/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp index a895a8d447b66..691c549b5e78b 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp @@ -52,90 +52,175 @@ struct incomplete_type; int main() { - test_member_function_pointer<void (Class::*)()>(); - test_member_function_pointer<void (Class::*)(int)>(); - test_member_function_pointer<void (Class::*)(int, char)>(); + test_member_function_pointer<void (Class::*)()>(); + test_member_function_pointer<void (Class::*)(int)>(); + test_member_function_pointer<void (Class::*)(int, char)>(); - test_member_function_pointer<void (Class::*)() const>(); - test_member_function_pointer<void (Class::*)(int) const>(); - test_member_function_pointer<void (Class::*)(int, char) const>(); + test_member_function_pointer<void (Class::*)() const>(); + test_member_function_pointer<void (Class::*)(int) const>(); + test_member_function_pointer<void (Class::*)(int, char) const>(); - test_member_function_pointer<void (Class::*)() volatile>(); - test_member_function_pointer<void (Class::*)(int) volatile>(); - test_member_function_pointer<void (Class::*)(int, char) volatile>(); + test_member_function_pointer<void (Class::*)() volatile>(); + test_member_function_pointer<void (Class::*)(int) volatile>(); + test_member_function_pointer<void (Class::*)(int, char) volatile>(); - test_member_function_pointer<void (Class::*)(...)>(); - test_member_function_pointer<void (Class::*)(int, ...)>(); - test_member_function_pointer<void (Class::*)(int, char, ...)>(); + test_member_function_pointer<void (Class::*)(...)>(); + test_member_function_pointer<void (Class::*)(int, ...)>(); + test_member_function_pointer<void (Class::*)(int, char, ...)>(); - test_member_function_pointer<void (Class::*)(...) const>(); - test_member_function_pointer<void (Class::*)(int, ...) const>(); - test_member_function_pointer<void (Class::*)(int, char, ...) const>(); + test_member_function_pointer<void (Class::*)(...) const>(); + test_member_function_pointer<void (Class::*)(int, ...) const>(); + test_member_function_pointer<void (Class::*)(int, char, ...) const>(); + + test_member_function_pointer<void (Class::*)(...) volatile>(); + test_member_function_pointer<void (Class::*)(int, ...) volatile>(); + test_member_function_pointer<void (Class::*)(int, char, ...) volatile>(); - test_member_function_pointer<void (Class::*)(...) volatile>(); - test_member_function_pointer<void (Class::*)(int, ...) volatile>(); - test_member_function_pointer<void (Class::*)(int, char, ...) volatile>(); // reference qualifiers on functions are a C++11 extension #if TEST_STD_VER >= 11 - test_member_function_pointer<void (Class::*)() &>(); - test_member_function_pointer<void (Class::*)(int) &>(); - test_member_function_pointer<void (Class::*)(int, char) &>(); - test_member_function_pointer<void (Class::*)(...) &>(); - test_member_function_pointer<void (Class::*)(int,...) &>(); - test_member_function_pointer<void (Class::*)(int, char,...) &>(); - - test_member_function_pointer<void (Class::*)() const &>(); - test_member_function_pointer<void (Class::*)(int) const &>(); - test_member_function_pointer<void (Class::*)(int, char) const &>(); - test_member_function_pointer<void (Class::*)(...) const &>(); - test_member_function_pointer<void (Class::*)(int,...) const &>(); - test_member_function_pointer<void (Class::*)(int, char,...) const &>(); - - test_member_function_pointer<void (Class::*)() volatile &>(); - test_member_function_pointer<void (Class::*)(int) volatile &>(); - test_member_function_pointer<void (Class::*)(int, char) volatile &>(); - test_member_function_pointer<void (Class::*)(...) volatile &>(); - test_member_function_pointer<void (Class::*)(int,...) volatile &>(); - test_member_function_pointer<void (Class::*)(int, char,...) volatile &>(); - - test_member_function_pointer<void (Class::*)() const volatile &>(); - test_member_function_pointer<void (Class::*)(int) const volatile &>(); - test_member_function_pointer<void (Class::*)(int, char) const volatile &>(); - test_member_function_pointer<void (Class::*)(...) const volatile &>(); - test_member_function_pointer<void (Class::*)(int,...) const volatile &>(); - test_member_function_pointer<void (Class::*)(int, char,...) const volatile &>(); - - // RValue qualifiers - test_member_function_pointer<void (Class::*)() &&>(); - test_member_function_pointer<void (Class::*)(int) &&>(); - test_member_function_pointer<void (Class::*)(int, char) &&>(); - test_member_function_pointer<void (Class::*)(...) &&>(); - test_member_function_pointer<void (Class::*)(int,...) &&>(); - test_member_function_pointer<void (Class::*)(int, char,...) &&>(); - - test_member_function_pointer<void (Class::*)() const &&>(); - test_member_function_pointer<void (Class::*)(int) const &&>(); - test_member_function_pointer<void (Class::*)(int, char) const &&>(); - test_member_function_pointer<void (Class::*)(...) const &&>(); - test_member_function_pointer<void (Class::*)(int,...) const &&>(); - test_member_function_pointer<void (Class::*)(int, char,...) const &&>(); - - test_member_function_pointer<void (Class::*)() volatile &&>(); - test_member_function_pointer<void (Class::*)(int) volatile &&>(); - test_member_function_pointer<void (Class::*)(int, char) volatile &&>(); - test_member_function_pointer<void (Class::*)(...) volatile &&>(); - test_member_function_pointer<void (Class::*)(int,...) volatile &&>(); - test_member_function_pointer<void (Class::*)(int, char,...) volatile &&>(); - - test_member_function_pointer<void (Class::*)() const volatile &&>(); - test_member_function_pointer<void (Class::*)(int) const volatile &&>(); - test_member_function_pointer<void (Class::*)(int, char) const volatile &&>(); - test_member_function_pointer<void (Class::*)(...) const volatile &&>(); - test_member_function_pointer<void (Class::*)(int,...) const volatile &&>(); - test_member_function_pointer<void (Class::*)(int, char,...) const volatile &&>(); + // Noexcept qualifiers + test_member_function_pointer<void (Class::*)() noexcept>(); + test_member_function_pointer<void (Class::*)(int) noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) noexcept>(); + + test_member_function_pointer<void (Class::*)() const noexcept>(); + test_member_function_pointer<void (Class::*)(int) const noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) const noexcept>(); + + test_member_function_pointer<void (Class::*)() volatile noexcept>(); + test_member_function_pointer<void (Class::*)(int) volatile noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) volatile noexcept>(); + + test_member_function_pointer<void (Class::*)(...) noexcept>(); + test_member_function_pointer<void (Class::*)(int, ...) noexcept>(); + test_member_function_pointer<void (Class::*)(int, char, ...) noexcept>(); + + test_member_function_pointer<void (Class::*)(...) const noexcept>(); + test_member_function_pointer<void (Class::*)(int, ...) const noexcept>(); + test_member_function_pointer<void (Class::*)(int, char, ...) const noexcept>(); + + test_member_function_pointer<void (Class::*)(...) volatile noexcept>(); + test_member_function_pointer<void (Class::*)(int, ...) volatile noexcept>(); + test_member_function_pointer<void (Class::*)(int, char, ...) volatile noexcept>(); + + // lvalue qualifiers + test_member_function_pointer<void (Class::*)() &>(); + test_member_function_pointer<void (Class::*)(int) &>(); + test_member_function_pointer<void (Class::*)(int, char) &>(); + test_member_function_pointer<void (Class::*)(...) &>(); + test_member_function_pointer<void (Class::*)(int,...) &>(); + test_member_function_pointer<void (Class::*)(int, char,...) &>(); + + test_member_function_pointer<void (Class::*)() const &>(); + test_member_function_pointer<void (Class::*)(int) const &>(); + test_member_function_pointer<void (Class::*)(int, char) const &>(); + test_member_function_pointer<void (Class::*)(...) const &>(); + test_member_function_pointer<void (Class::*)(int,...) const &>(); + test_member_function_pointer<void (Class::*)(int, char,...) const &>(); + + test_member_function_pointer<void (Class::*)() volatile &>(); + test_member_function_pointer<void (Class::*)(int) volatile &>(); + test_member_function_pointer<void (Class::*)(int, char) volatile &>(); + test_member_function_pointer<void (Class::*)(...) volatile &>(); + test_member_function_pointer<void (Class::*)(int,...) volatile &>(); + test_member_function_pointer<void (Class::*)(int, char,...) volatile &>(); + + test_member_function_pointer<void (Class::*)() const volatile &>(); + test_member_function_pointer<void (Class::*)(int) const volatile &>(); + test_member_function_pointer<void (Class::*)(int, char) const volatile &>(); + test_member_function_pointer<void (Class::*)(...) const volatile &>(); + test_member_function_pointer<void (Class::*)(int,...) const volatile &>(); + test_member_function_pointer<void (Class::*)(int, char,...) const volatile &>(); + + // Lvalue qualifiers with noexcept + test_member_function_pointer<void (Class::*)() & noexcept>(); + test_member_function_pointer<void (Class::*)(int) & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) & noexcept>(); + test_member_function_pointer<void (Class::*)(...) & noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) & noexcept>(); + + test_member_function_pointer<void (Class::*)() const & noexcept>(); + test_member_function_pointer<void (Class::*)(int) const & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) const & noexcept>(); + test_member_function_pointer<void (Class::*)(...) const & noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) const & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) const & noexcept>(); + + test_member_function_pointer<void (Class::*)() volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int) volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(...) volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) volatile & noexcept>(); + + test_member_function_pointer<void (Class::*)() const volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int) const volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) const volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(...) const volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) const volatile & noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) const volatile & noexcept>(); + + // RValue qualifiers + test_member_function_pointer<void (Class::*)() &&>(); + test_member_function_pointer<void (Class::*)(int) &&>(); + test_member_function_pointer<void (Class::*)(int, char) &&>(); + test_member_function_pointer<void (Class::*)(...) &&>(); + test_member_function_pointer<void (Class::*)(int,...) &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) &&>(); + + test_member_function_pointer<void (Class::*)() const &&>(); + test_member_function_pointer<void (Class::*)(int) const &&>(); + test_member_function_pointer<void (Class::*)(int, char) const &&>(); + test_member_function_pointer<void (Class::*)(...) const &&>(); + test_member_function_pointer<void (Class::*)(int,...) const &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) const &&>(); + + test_member_function_pointer<void (Class::*)() volatile &&>(); + test_member_function_pointer<void (Class::*)(int) volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char) volatile &&>(); + test_member_function_pointer<void (Class::*)(...) volatile &&>(); + test_member_function_pointer<void (Class::*)(int,...) volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) volatile &&>(); + + test_member_function_pointer<void (Class::*)() const volatile &&>(); + test_member_function_pointer<void (Class::*)(int) const volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char) const volatile &&>(); + test_member_function_pointer<void (Class::*)(...) const volatile &&>(); + test_member_function_pointer<void (Class::*)(int,...) const volatile &&>(); + test_member_function_pointer<void (Class::*)(int, char,...) const volatile &&>(); + + // RValue qualifiers with noexcept + test_member_function_pointer<void (Class::*)() && noexcept>(); + test_member_function_pointer<void (Class::*)(int) && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) && noexcept>(); + test_member_function_pointer<void (Class::*)(...) && noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) && noexcept>(); + + test_member_function_pointer<void (Class::*)() const && noexcept>(); + test_member_function_pointer<void (Class::*)(int) const && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) const && noexcept>(); + test_member_function_pointer<void (Class::*)(...) const && noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) const && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) const && noexcept>(); + + test_member_function_pointer<void (Class::*)() volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int) volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(...) volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) volatile && noexcept>(); + + test_member_function_pointer<void (Class::*)() const volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int) const volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char) const volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(...) const volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int,...) const volatile && noexcept>(); + test_member_function_pointer<void (Class::*)(int, char,...) const volatile && noexcept>(); #endif // LWG#2582 - static_assert(!std::is_member_function_pointer<incomplete_type>::value, ""); + static_assert(!std::is_member_function_pointer<incomplete_type>::value, ""); } diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp index a54adf10258f2..99ca74cc2fa91 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_abstract.pass.cpp @@ -65,6 +65,14 @@ class Abstract virtual ~Abstract() = 0; }; +template <class> +struct AbstractTemplate { + virtual void test() = 0; +}; + +template <> +struct AbstractTemplate<double> {}; + int main() { test_is_not_abstract<void>(); @@ -81,4 +89,6 @@ int main() test_is_not_abstract<NotEmpty>(); test_is_abstract<Abstract>(); + test_is_abstract<AbstractTemplate<int> >(); + test_is_not_abstract<AbstractTemplate<double> >(); } diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp new file mode 100644 index 0000000000000..9c72d4d44ce5d --- /dev/null +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_aggregate.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <type_traits> + +// template <class T> struct is_aggregate; +// template <class T> constexpr bool is_aggregate_v = is_aggregate<T>::value; + +#include <type_traits> +#include "test_macros.h" + +template <class T> +void test_true() +{ +#if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + static_assert( std::is_aggregate<T>::value, ""); + static_assert( std::is_aggregate<const T>::value, ""); + static_assert( std::is_aggregate<volatile T>::value, ""); + static_assert( std::is_aggregate<const volatile T>::value, ""); + static_assert( std::is_aggregate_v<T>, ""); + static_assert( std::is_aggregate_v<const T>, ""); + static_assert( std::is_aggregate_v<volatile T>, ""); + static_assert( std::is_aggregate_v<const volatile T>, ""); +#endif +} + +template <class T> +void test_false() +{ +#if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE) + static_assert(!std::is_aggregate<T>::value, ""); + static_assert(!std::is_aggregate<const T>::value, ""); + static_assert(!std::is_aggregate<volatile T>::value, ""); + static_assert(!std::is_aggregate<const volatile T>::value, ""); + static_assert(!std::is_aggregate_v<T>, ""); + static_assert(!std::is_aggregate_v<const T>, ""); + static_assert(!std::is_aggregate_v<volatile T>, ""); + static_assert(!std::is_aggregate_v<const volatile T>, ""); +#endif +} + +struct Aggregate {}; +struct HasCons { HasCons(int); }; +struct HasPriv { + void PreventUnusedPrivateMemberWarning(); +private: + int x; +}; +struct Union { int x; void* y; }; + + +int main () +{ + { + test_false<void>(); + test_false<int>(); + test_false<void*>(); + test_false<void()>(); + test_false<void() const>(); + test_false<void(Aggregate::*)(int) const>(); + test_false<Aggregate&>(); + test_false<HasCons>(); + test_false<HasPriv>(); + } + { + test_true<Aggregate>(); + test_true<Aggregate[]>(); + test_true<Aggregate[42][101]>(); + test_true<Union>(); + } +} diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp index f4736e7134226..3955d4bc3306b 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_assignable.pass.cpp @@ -82,5 +82,4 @@ int main() // pointer to incomplete template type test_is_assignable<X<D>*&, X<D>*> (); - test_is_not_assignable<Incomplete&, Incomplete const&>(); } diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp index f6ae401533a98..9d2ec5edea583 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp @@ -251,6 +251,7 @@ int main() LIBCPP_STATIC_ASSERT( clang_disallows_valid_static_cast_bug != std::__libcpp_is_constructible<int&&, ExplicitTo<int&&>>::value, ""); + ((void)clang_disallows_valid_static_cast_bug); // Prevent unused warning #else static_assert(clang_disallows_valid_static_cast_bug == false, ""); LIBCPP_STATIC_ASSERT(std::__libcpp_is_constructible<int&&, ExplicitTo<int&&>>::value, ""); diff --git a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp index 59aa5e26a2921..7ead5f5d5df95 100644 --- a/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp +++ b/test/std/utilities/meta/meta.unary/meta.unary.prop/is_literal_type.pass.cpp @@ -77,7 +77,7 @@ int main() #endif // Before C++14, void was not a literal type -// In C++14, cv-void is is a literal type +// In C++14, cv-void is a literal type #if TEST_STD_VER < 14 test_is_not_literal_type<void>(); #else diff --git a/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp b/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp index b54a08f5575ba..29fb7a8431f1a 100644 --- a/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp +++ b/test/std/utilities/optional/optional.comp_with_t/equal.pass.cpp @@ -17,37 +17,48 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator == ( const X &lhs, const X &rhs ) - { return lhs.i_ == rhs.i_ ; } +constexpr bool operator==(const X& lhs, const X& rhs) { + return lhs.i_ == rhs.i_; +} -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged - constexpr O o3{val}; // engaged - - static_assert ( !(o1 == T(1)), "" ); - static_assert ( (o2 == T(1)), "" ); - static_assert ( !(o3 == T(1)), "" ); - static_assert ( (o3 == T(2)), "" ); - static_assert ( (o3 == val), "" ); - - static_assert ( !(T(1) == o1), "" ); - static_assert ( (T(1) == o2), "" ); - static_assert ( !(T(1) == o3), "" ); - static_assert ( (T(2) == o3), "" ); - static_assert ( (val == o3), "" ); - } + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert(!(o1 == T(1)), ""); + static_assert((o2 == T(1)), ""); + static_assert(!(o3 == T(1)), ""); + static_assert((o3 == T(2)), ""); + static_assert((o3 == val), ""); + + static_assert(!(T(1) == o1), ""); + static_assert((T(1) == o2), ""); + static_assert(!(T(1) == o3), ""); + static_assert((T(2) == o3), ""); + static_assert((val == o3), ""); + } + { + using O = optional<int>; + constexpr O o1(42); + static_assert(o1 == 42l, ""); + static_assert(!(101l == o1), ""); + } + { + using O = optional<const int>; + constexpr O o1(42); + static_assert(o1 == 42, ""); + static_assert(!(101 == o1), ""); + } } diff --git a/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp b/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp index 064114fb9db2b..ae34eb20517e7 100644 --- a/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp +++ b/test/std/utilities/optional/optional.comp_with_t/greater.pass.cpp @@ -17,39 +17,48 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator > ( const X &lhs, const X &rhs ) - { return lhs.i_ > rhs.i_ ; } +constexpr bool operator>(const X& lhs, const X& rhs) { return lhs.i_ > rhs.i_; } -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged - constexpr O o3{val}; // engaged - - static_assert ( !(o1 > T(1)), "" ); - static_assert ( !(o2 > T(1)), "" ); // equal - static_assert ( (o3 > T(1)), "" ); - static_assert ( !(o2 > val), "" ); - static_assert ( !(o3 > val), "" ); // equal - static_assert ( !(o3 > T(3)), "" ); - - static_assert ( (T(1) > o1), "" ); - static_assert ( !(T(1) > o2), "" ); // equal - static_assert ( !(T(1) > o3), "" ); - static_assert ( (val > o2), "" ); - static_assert ( !(val > o3), "" ); // equal - static_assert ( (T(3) > o3), "" ); - } + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert(!(o1 > T(1)), ""); + static_assert(!(o2 > T(1)), ""); // equal + static_assert((o3 > T(1)), ""); + static_assert(!(o2 > val), ""); + static_assert(!(o3 > val), ""); // equal + static_assert(!(o3 > T(3)), ""); + + static_assert((T(1) > o1), ""); + static_assert(!(T(1) > o2), ""); // equal + static_assert(!(T(1) > o3), ""); + static_assert((val > o2), ""); + static_assert(!(val > o3), ""); // equal + static_assert((T(3) > o3), ""); + } + { + using O = optional<int>; + constexpr O o1(42); + static_assert(o1 > 11l, ""); + static_assert(!(42l > o1), ""); + } + { + using O = optional<const int>; + constexpr O o1(42); + static_assert(o1 > 11, ""); + static_assert(!(42 > o1), ""); + } } diff --git a/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp b/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp index 663686cdf3478..dac94002661f8 100644 --- a/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp +++ b/test/std/utilities/optional/optional.comp_with_t/greater_equal.pass.cpp @@ -17,39 +17,50 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator >= ( const X &lhs, const X &rhs ) - { return lhs.i_ >= rhs.i_ ; } +constexpr bool operator>=(const X& lhs, const X& rhs) { + return lhs.i_ >= rhs.i_; +} -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged - constexpr O o3{val}; // engaged - - static_assert ( !(o1 >= T(1)), "" ); - static_assert ( (o2 >= T(1)), "" ); // equal - static_assert ( (o3 >= T(1)), "" ); - static_assert ( !(o2 >= val), "" ); - static_assert ( (o3 >= val), "" ); // equal - static_assert ( !(o3 >= T(3)), "" ); - - static_assert ( (T(1) >= o1), "" ); - static_assert ( (T(1) >= o2), "" ); // equal - static_assert ( !(T(1) >= o3), "" ); - static_assert ( (val >= o2), "" ); - static_assert ( (val >= o3), "" ); // equal - static_assert ( (T(3) >= o3), "" ); - } + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert(!(o1 >= T(1)), ""); + static_assert((o2 >= T(1)), ""); // equal + static_assert((o3 >= T(1)), ""); + static_assert(!(o2 >= val), ""); + static_assert((o3 >= val), ""); // equal + static_assert(!(o3 >= T(3)), ""); + + static_assert((T(1) >= o1), ""); + static_assert((T(1) >= o2), ""); // equal + static_assert(!(T(1) >= o3), ""); + static_assert((val >= o2), ""); + static_assert((val >= o3), ""); // equal + static_assert((T(3) >= o3), ""); + } + { + using O = optional<int>; + constexpr O o1(42); + static_assert(o1 >= 42l, ""); + static_assert(!(11l >= o1), ""); + } + { + using O = optional<const int>; + constexpr O o1(42); + static_assert(o1 >= 42, ""); + static_assert(!(11 >= o1), ""); + } } diff --git a/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp b/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp index 05ac5eb12b48a..b71f8363b0a62 100644 --- a/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp +++ b/test/std/utilities/optional/optional.comp_with_t/less_equal.pass.cpp @@ -17,39 +17,50 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator <= ( const X &lhs, const X &rhs ) - { return lhs.i_ <= rhs.i_ ; } +constexpr bool operator<=(const X& lhs, const X& rhs) { + return lhs.i_ <= rhs.i_; +} -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged - constexpr O o3{val}; // engaged - - static_assert ( (o1 <= T(1)), "" ); - static_assert ( (o2 <= T(1)), "" ); // equal - static_assert ( !(o3 <= T(1)), "" ); - static_assert ( (o2 <= val), "" ); - static_assert ( (o3 <= val), "" ); // equal - static_assert ( (o3 <= T(3)), "" ); - - static_assert ( !(T(1) <= o1), "" ); - static_assert ( (T(1) <= o2), "" ); // equal - static_assert ( (T(1) <= o3), "" ); - static_assert ( !(val <= o2), "" ); - static_assert ( (val <= o3), "" ); // equal - static_assert ( !(T(3) <= o3), "" ); - } + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert((o1 <= T(1)), ""); + static_assert((o2 <= T(1)), ""); // equal + static_assert(!(o3 <= T(1)), ""); + static_assert((o2 <= val), ""); + static_assert((o3 <= val), ""); // equal + static_assert((o3 <= T(3)), ""); + + static_assert(!(T(1) <= o1), ""); + static_assert((T(1) <= o2), ""); // equal + static_assert((T(1) <= o3), ""); + static_assert(!(val <= o2), ""); + static_assert((val <= o3), ""); // equal + static_assert(!(T(3) <= o3), ""); + } + { + using O = optional<int>; + constexpr O o1(42); + static_assert(o1 <= 42l, ""); + static_assert(!(101l <= o1), ""); + } + { + using O = optional<const int>; + constexpr O o1(42); + static_assert(o1 <= 42, ""); + static_assert(!(101 <= o1), ""); + } } diff --git a/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp b/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp index d1891a286d7b8..84456b3baa6ef 100644 --- a/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp +++ b/test/std/utilities/optional/optional.comp_with_t/less_than.pass.cpp @@ -17,39 +17,48 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator < ( const X &lhs, const X &rhs ) - { return lhs.i_ < rhs.i_ ; } +constexpr bool operator<(const X& lhs, const X& rhs) { return lhs.i_ < rhs.i_; } -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged - constexpr O o3{val}; // engaged - - static_assert ( (o1 < T(1)), "" ); - static_assert ( !(o2 < T(1)), "" ); // equal - static_assert ( !(o3 < T(1)), "" ); - static_assert ( (o2 < val), "" ); - static_assert ( !(o3 < val), "" ); // equal - static_assert ( (o3 < T(3)), "" ); - - static_assert ( !(T(1) < o1), "" ); - static_assert ( !(T(1) < o2), "" ); // equal - static_assert ( (T(1) < o3), "" ); - static_assert ( !(val < o2), "" ); - static_assert ( !(val < o3), "" ); // equal - static_assert ( !(T(3) < o3), "" ); - } + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert((o1 < T(1)), ""); + static_assert(!(o2 < T(1)), ""); // equal + static_assert(!(o3 < T(1)), ""); + static_assert((o2 < val), ""); + static_assert(!(o3 < val), ""); // equal + static_assert((o3 < T(3)), ""); + + static_assert(!(T(1) < o1), ""); + static_assert(!(T(1) < o2), ""); // equal + static_assert((T(1) < o3), ""); + static_assert(!(val < o2), ""); + static_assert(!(val < o3), ""); // equal + static_assert(!(T(3) < o3), ""); + } + { + using O = optional<int>; + constexpr O o1(42); + static_assert(o1 < 101l, ""); + static_assert(!(42l < o1), ""); + } + { + using O = optional<const int>; + constexpr O o1(42); + static_assert(o1 < 101, ""); + static_assert(!(42 < o1), ""); + } } diff --git a/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp b/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp index ae2ff808fb25a..a4ffdc25e7213 100644 --- a/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp +++ b/test/std/utilities/optional/optional.comp_with_t/not_equal.pass.cpp @@ -17,37 +17,48 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator != ( const X &lhs, const X &rhs ) - { return lhs.i_ != rhs.i_ ; } +constexpr bool operator!=(const X& lhs, const X& rhs) { + return lhs.i_ != rhs.i_; +} -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; constexpr T val(2); - constexpr O o1; // disengaged - constexpr O o2{1}; // engaged - constexpr O o3{val}; // engaged - - static_assert ( (o1 != T(1)), "" ); - static_assert ( !(o2 != T(1)), "" ); - static_assert ( (o3 != T(1)), "" ); - static_assert ( !(o3 != T(2)), "" ); - static_assert ( !(o3 != val), "" ); - - static_assert ( (T(1) != o1), "" ); - static_assert ( !(T(1) != o2), "" ); - static_assert ( (T(1) != o3), "" ); - static_assert ( !(T(2) != o3), "" ); - static_assert ( !(val != o3), "" ); - } + constexpr O o1; // disengaged + constexpr O o2{1}; // engaged + constexpr O o3{val}; // engaged + + static_assert((o1 != T(1)), ""); + static_assert(!(o2 != T(1)), ""); + static_assert((o3 != T(1)), ""); + static_assert(!(o3 != T(2)), ""); + static_assert(!(o3 != val), ""); + + static_assert((T(1) != o1), ""); + static_assert(!(T(1) != o2), ""); + static_assert((T(1) != o3), ""); + static_assert(!(T(2) != o3), ""); + static_assert(!(val != o3), ""); + } + { + using O = optional<int>; + constexpr O o1(42); + static_assert(o1 != 101l, ""); + static_assert(!(42l != o1), ""); + } + { + using O = optional<const int>; + constexpr O o1(42); + static_assert(o1 != 101, ""); + static_assert(!(42 != o1), ""); + } } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp b/test/std/utilities/optional/optional.hash/enabled_hash.pass.cpp index af7f27f73fc59..e54a4ced84118 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/pointer02.fail.cpp +++ b/test/std/utilities/optional/optional.hash/enabled_hash.pass.cpp @@ -7,23 +7,20 @@ // //===----------------------------------------------------------------------===// -// <memory> +// UNSUPPORTED: c++98, c++03, c++11, c++14 -// unique_ptr +// <optional> -// Test unique_ptr<T[]>(pointer) ctor +// Test that <optional> provides all of the arithmetic, enum, and pointer +// hash specializations. -#include <memory> +#include <optional> -// unique_ptr<T[]>(pointer) ctor should require non-reference Deleter ctor -class Deleter -{ -public: +#include "poisoned_hash_helper.hpp" - void operator()(void*) {} -}; +int main() { + test_library_hash_specializations_available(); + { -int main() -{ - std::unique_ptr<int[], Deleter&> p(new int); + } } diff --git a/test/std/utilities/optional/optional.hash/hash.pass.cpp b/test/std/utilities/optional/optional.hash/hash.pass.cpp index dfdd07ddf452e..8c91d6da761e2 100644 --- a/test/std/utilities/optional/optional.hash/hash.pass.cpp +++ b/test/std/utilities/optional/optional.hash/hash.pass.cpp @@ -17,6 +17,19 @@ #include <memory> #include <cassert> +#include "poisoned_hash_helper.hpp" + +struct A {}; +struct B {}; + +namespace std { + +template <> +struct hash<B> { + size_t operator()(B const&) noexcept(false) { return 0; } +}; + +} int main() { @@ -27,6 +40,7 @@ int main() { typedef int T; optional<T> opt; + ASSERT_NOT_NOEXCEPT(std::hash<optional<T>>()(opt)); assert(std::hash<optional<T>>{}(opt) == nullopt_hash); opt = 2; assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt)); @@ -34,6 +48,7 @@ int main() { typedef std::string T; optional<T> opt; + ASSERT_NOT_NOEXCEPT(std::hash<optional<T>>()(opt)); assert(std::hash<optional<T>>{}(opt) == nullopt_hash); opt = std::string("123"); assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt)); @@ -41,8 +56,21 @@ int main() { typedef std::unique_ptr<int> T; optional<T> opt; + ASSERT_NOT_NOEXCEPT(std::hash<optional<T>>()(opt)); assert(std::hash<optional<T>>{}(opt) == nullopt_hash); opt = std::unique_ptr<int>(new int(3)); assert(std::hash<optional<T>>{}(opt) == std::hash<T>{}(*opt)); } + { + test_hash_enabled_for_type<std::optional<int> >(); + test_hash_enabled_for_type<std::optional<int*> >(); + test_hash_enabled_for_type<std::optional<const int> >(); + test_hash_enabled_for_type<std::optional<int* const> >(); + + test_hash_disabled_for_type<std::optional<A>>(); + test_hash_disabled_for_type<std::optional<const A>>(); + + test_hash_enabled_for_type<std::optional<B>>(); + test_hash_enabled_for_type<std::optional<const B>>(); + } } diff --git a/test/std/utilities/optional/optional.nullopt/nullopt_t.fail.cpp b/test/std/utilities/optional/optional.nullopt/nullopt_t.fail.cpp new file mode 100644 index 0000000000000..f9ea7b47911fa --- /dev/null +++ b/test/std/utilities/optional/optional.nullopt/nullopt_t.fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// <optional> + +// struct nullopt_t{see below}; +// constexpr nullopt_t nullopt(unspecified); + +// [optional.nullopt]/2: +// Type nullopt_t shall not have a default constructor or an initializer-list constructor. +// It shall not be an aggregate and shall be a literal type. +// Constant nullopt shall be initialized with an argument of literal type. + +#include <optional> +#include "test_macros.h" + +int main() +{ + std::nullopt_t n = {}; +} diff --git a/test/std/utilities/optional/optional.nullopt/nullopt_t.pass.cpp b/test/std/utilities/optional/optional.nullopt/nullopt_t.pass.cpp index 84bb29fabac8d..9b752a665a837 100644 --- a/test/std/utilities/optional/optional.nullopt/nullopt_t.pass.cpp +++ b/test/std/utilities/optional/optional.nullopt/nullopt_t.pass.cpp @@ -13,6 +13,11 @@ // struct nullopt_t{see below}; // constexpr nullopt_t nullopt(unspecified); +// [optional.nullopt]/2: +// Type nullopt_t shall not have a default constructor or an initializer-list constructor. +// It shall not be an aggregate and shall be a literal type. +// Constant nullopt shall be initialized with an argument of literal type. + #include <optional> #include <type_traits> @@ -29,9 +34,9 @@ test(const nullopt_t&) int main() { - static_assert((std::is_class<nullopt_t>::value), ""); - static_assert((std::is_empty<nullopt_t>::value), ""); - static_assert((std::is_literal_type<nullopt_t>::value), ""); + static_assert(( std::is_class<nullopt_t>::value), ""); + static_assert(( std::is_empty<nullopt_t>::value), ""); + static_assert(( std::is_literal_type<nullopt_t>::value), ""); static_assert((!std::is_default_constructible<nullopt_t>::value), ""); static_assert(test(nullopt) == 3, ""); diff --git a/test/std/utilities/optional/optional.object/optional.object.assign/assign_value.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.assign/assign_value.pass.cpp index 1207e24150ff7..0fcc52be13546 100644 --- a/test/std/utilities/optional/optional.object/optional.object.assign/assign_value.pass.cpp +++ b/test/std/utilities/optional/optional.object/optional.object.assign/assign_value.pass.cpp @@ -216,7 +216,6 @@ void test_throws() #ifndef TEST_HAS_NO_EXCEPTIONS using T = ThrowAssign; { - using T = ThrowAssign; optional<T> opt; try { opt = 42; diff --git a/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp index b5362589963c2..0696c11526d59 100644 --- a/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp +++ b/test/std/utilities/optional/optional.object/optional.object.assign/emplace.pass.cpp @@ -10,7 +10,7 @@ // UNSUPPORTED: c++98, c++03, c++11, c++14 // <optional> -// template <class... Args> void optional<T>::emplace(Args&&... args); +// template <class... Args> T& optional<T>::emplace(Args&&... args); #include <optional> #include <type_traits> @@ -51,27 +51,35 @@ void test_one_arg() { using Opt = std::optional<T>; { Opt opt; - opt.emplace(); + auto & v = opt.emplace(); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); assert(*opt == T(0)); + assert(&v == &*opt); } { Opt opt; - opt.emplace(1); + auto & v = opt.emplace(1); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); assert(*opt == T(1)); + assert(&v == &*opt); } { Opt opt(2); - opt.emplace(); + auto & v = opt.emplace(); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); assert(*opt == T(0)); + assert(&v == &*opt); } { Opt opt(2); - opt.emplace(1); + auto & v = opt.emplace(1); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); assert(*opt == T(1)); + assert(&v == &*opt); } } @@ -83,20 +91,26 @@ void test_multi_arg() using Opt = std::optional<T>; { Opt opt; - opt.emplace(101, 41); + auto &v = opt.emplace(101, 41); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); + assert( v == T(101, 41)); assert(*opt == T(101, 41)); } { Opt opt; - opt.emplace({1, 2, 3, 4}); + auto &v = opt.emplace({1, 2, 3, 4}); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); - assert(*opt == T(4)); // T sets its value to the size of the init list + assert( v == T(4)); // T sets its value to the size of the init list + assert(*opt == T(4)); } { Opt opt; - opt.emplace({1, 2, 3, 4, 5}, 6); + auto &v = opt.emplace({1, 2, 3, 4, 5}, 6); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(static_cast<bool>(opt) == true); + assert( v == T(5)); // T sets its value to the size of the init list assert(*opt == T(5)); // T sets its value to the size of the init list } } @@ -109,73 +123,87 @@ void test_on_test_type() { assert(T::alive == 0); { T::reset_constructors(); - opt.emplace(); + auto &v = opt.emplace(); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::default_constructed == 1); assert(T::destroyed == 0); assert(static_cast<bool>(opt) == true); assert(*opt == T()); + assert(&v == &*opt); } { T::reset_constructors(); - opt.emplace(); + auto &v = opt.emplace(); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::default_constructed == 1); assert(T::destroyed == 1); assert(static_cast<bool>(opt) == true); assert(*opt == T()); + assert(&v == &*opt); } { T::reset_constructors(); - opt.emplace(101); + auto &v = opt.emplace(101); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::value_constructed == 1); assert(T::destroyed == 1); assert(static_cast<bool>(opt) == true); assert(*opt == T(101)); + assert(&v == &*opt); } { T::reset_constructors(); - opt.emplace(-10, 99); + auto &v = opt.emplace(-10, 99); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::value_constructed == 1); assert(T::destroyed == 1); assert(static_cast<bool>(opt) == true); assert(*opt == T(-10, 99)); + assert(&v == &*opt); } { T::reset_constructors(); - opt.emplace(-10, 99); + auto &v = opt.emplace(-10, 99); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::value_constructed == 1); assert(T::destroyed == 1); assert(static_cast<bool>(opt) == true); assert(*opt == T(-10, 99)); + assert(&v == &*opt); } { T::reset_constructors(); - opt.emplace({-10, 99, 42, 1}); + auto &v = opt.emplace({-10, 99, 42, 1}); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::value_constructed == 1); assert(T::destroyed == 1); assert(static_cast<bool>(opt) == true); assert(*opt == T(4)); // size of the initializer list + assert(&v == &*opt); } { T::reset_constructors(); - opt.emplace({-10, 99, 42, 1}, 42); + auto &v = opt.emplace({-10, 99, 42, 1}, 42); + static_assert( std::is_same_v<T&, decltype(v)>, "" ); assert(T::alive == 1); assert(T::constructed == 1); assert(T::value_constructed == 1); assert(T::destroyed == 1); assert(static_cast<bool>(opt) == true); assert(*opt == T(4)); // size of the initializer list + assert(&v == &*opt); } } @@ -210,8 +238,10 @@ int main() } { optional<const int> opt; - opt.emplace(42); + auto &v = opt.emplace(42); + static_assert( std::is_same_v<const int&, decltype(v)>, "" ); assert(*opt == 42); + assert( v == 42); opt.emplace(); assert(*opt == 0); } diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp index c4d4763a6f0ae..d068fbc2db7e7 100644 --- a/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp +++ b/test/std/utilities/optional/optional.object/optional.object.ctor/U.pass.cpp @@ -35,6 +35,11 @@ struct ExplicitThrow constexpr explicit ExplicitThrow(int x) { if (x != -1) TEST_THROW(6);} }; +struct ImplicitAny { + template <class U> + constexpr ImplicitAny(U&&) {} +}; + template <class To, class From> constexpr bool implicit_conversion(optional<To>&& opt, const From& v) @@ -61,11 +66,9 @@ constexpr bool explicit_conversion(Input&& in, const Expect& v) void test_implicit() { { - using T = long long; static_assert(implicit_conversion<long long>(42, 42), ""); } { - using T = long double; static_assert(implicit_conversion<long double>(3.14, 3.14), ""); } { @@ -81,6 +84,15 @@ void test_implicit() using T = TestTypes::TestType; assert(implicit_conversion<T>(3, T(3))); } + { + using O = optional<ImplicitAny>; + static_assert(!test_convertible<O, std::in_place_t>(), ""); + static_assert(!test_convertible<O, std::in_place_t&>(), ""); + static_assert(!test_convertible<O, const std::in_place_t&>(), ""); + static_assert(!test_convertible<O, std::in_place_t&&>(), ""); + static_assert(!test_convertible<O, const std::in_place_t&&>(), ""); + + } #ifndef TEST_HAS_NO_EXCEPTIONS { try { @@ -97,18 +109,15 @@ void test_implicit() void test_explicit() { { using T = ExplicitTrivialTestTypes::TestType; - using O = optional<T>; static_assert(explicit_conversion<T>(42, 42), ""); } { using T = ExplicitConstexprTestTypes::TestType; - using O = optional<T>; static_assert(explicit_conversion<T>(42, 42), ""); static_assert(!std::is_convertible<int, T>::value, ""); } { using T = ExplicitTestTypes::TestType; - using O = optional<T>; T::reset(); { assert(explicit_conversion<T>(42, 42)); diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/copy.fail.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/copy.fail.cpp new file mode 100644 index 0000000000000..d9e5ca821e85f --- /dev/null +++ b/test/std/utilities/optional/optional.object/optional.object.ctor/copy.fail.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// <optional> + +// constexpr optional(const optional<T>& rhs); +// If is_trivially_copy_constructible_v<T> is true, +// this constructor shall be a constexpr constructor. + +#include <optional> +#include <type_traits> +#include <cassert> + +#include "test_macros.h" + +struct S { + constexpr S() : v_(0) {} + S(int v) : v_(v) {} + S(const S &rhs) : v_(rhs.v_) {} // make it not trivially copyable + int v_; + }; + + +int main() +{ + static_assert (!std::is_trivially_copy_constructible_v<S>, "" ); + constexpr std::optional<S> o1; + constexpr std::optional<S> o2 = o1; // not constexpr +} diff --git a/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp b/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp new file mode 100644 index 0000000000000..c7458d95abfd3 --- /dev/null +++ b/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// <optional> + +// constexpr optional(const optional<T>&& rhs); +// If is_trivially_move_constructible_v<T> is true, +// this constructor shall be a constexpr constructor. + +#include <optional> +#include <type_traits> +#include <cassert> + +#include "test_macros.h" + +struct S { + constexpr S() : v_(0) {} + S(int v) : v_(v) {} + constexpr S(const S &rhs) : v_(rhs.v_) {} // not trivially moveable + constexpr S(const S &&rhs) : v_(rhs.v_) {} // not trivially moveable + int v_; + }; + + +int main() +{ + static_assert (!std::is_trivially_move_constructible_v<S>, "" ); + constexpr std::optional<S> o1; + constexpr std::optional<S> o2 = std::move(o1); // not constexpr +} diff --git a/test/std/utilities/optional/optional.relops/equal.pass.cpp b/test/std/utilities/optional/optional.relops/equal.pass.cpp index 6650b6720a8e9..7667540f97601 100644 --- a/test/std/utilities/optional/optional.relops/equal.pass.cpp +++ b/test/std/utilities/optional/optional.relops/equal.pass.cpp @@ -18,57 +18,69 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator == ( const X &lhs, const X &rhs ) - { return lhs.i_ == rhs.i_ ; } +constexpr bool operator==(const X& lhs, const X& rhs) { + return lhs.i_ == rhs.i_; +} -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; - constexpr O o1; // disengaged - constexpr O o2; // disengaged - constexpr O o3{1}; // engaged - constexpr O o4{2}; // engaged - constexpr O o5{1}; // engaged - - static_assert ( o1 == o1 , "" ); - static_assert ( o1 == o2 , "" ); - static_assert ( !(o1 == o3), "" ); - static_assert ( !(o1 == o4), "" ); - static_assert ( !(o1 == o5), "" ); + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged - static_assert ( o2 == o1 , "" ); - static_assert ( o2 == o2 , "" ); - static_assert ( !(o2 == o3), "" ); - static_assert ( !(o2 == o4), "" ); - static_assert ( !(o2 == o5), "" ); + static_assert(o1 == o1, ""); + static_assert(o1 == o2, ""); + static_assert(!(o1 == o3), ""); + static_assert(!(o1 == o4), ""); + static_assert(!(o1 == o5), ""); - static_assert ( !(o3 == o1), "" ); - static_assert ( !(o3 == o2), "" ); - static_assert ( o3 == o3 , "" ); - static_assert ( !(o3 == o4), "" ); - static_assert ( o3 == o5 , "" ); + static_assert(o2 == o1, ""); + static_assert(o2 == o2, ""); + static_assert(!(o2 == o3), ""); + static_assert(!(o2 == o4), ""); + static_assert(!(o2 == o5), ""); - static_assert ( !(o4 == o1), "" ); - static_assert ( !(o4 == o2), "" ); - static_assert ( !(o4 == o3), "" ); - static_assert ( o4 == o4 , "" ); - static_assert ( !(o4 == o5), "" ); + static_assert(!(o3 == o1), ""); + static_assert(!(o3 == o2), ""); + static_assert(o3 == o3, ""); + static_assert(!(o3 == o4), ""); + static_assert(o3 == o5, ""); - static_assert ( !(o5 == o1), "" ); - static_assert ( !(o5 == o2), "" ); - static_assert ( o5 == o3 , "" ); - static_assert ( !(o5 == o4), "" ); - static_assert ( o5 == o5 , "" ); + static_assert(!(o4 == o1), ""); + static_assert(!(o4 == o2), ""); + static_assert(!(o4 == o3), ""); + static_assert(o4 == o4, ""); + static_assert(!(o4 == o5), ""); - } + static_assert(!(o5 == o1), ""); + static_assert(!(o5 == o2), ""); + static_assert(o5 == o3, ""); + static_assert(!(o5 == o4), ""); + static_assert(o5 == o5, ""); + } + { + using O1 = optional<int>; + using O2 = optional<long>; + constexpr O1 o1(42); + static_assert(o1 == O2(42), ""); + static_assert(!(O2(101) == o1), ""); + } + { + using O1 = optional<int>; + using O2 = optional<const int>; + constexpr O1 o1(42); + static_assert(o1 == O2(42), ""); + static_assert(!(O2(101) == o1), ""); + } } diff --git a/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp b/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp index f9b30449638aa..0e05834c147a5 100644 --- a/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp +++ b/test/std/utilities/optional/optional.relops/greater_equal.pass.cpp @@ -16,55 +16,68 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator >= ( const X &lhs, const X &rhs ) - { return lhs.i_ >= rhs.i_ ; } +constexpr bool operator>=(const X& lhs, const X& rhs) { + return lhs.i_ >= rhs.i_; +} -int main() -{ - { +int main() { + { typedef optional<X> O; - constexpr O o1; // disengaged - constexpr O o2; // disengaged - constexpr O o3{1}; // engaged - constexpr O o4{2}; // engaged - constexpr O o5{1}; // engaged + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged - static_assert ( (o1 >= o1), "" ); - static_assert ( (o1 >= o2), "" ); - static_assert ( !(o1 >= o3), "" ); - static_assert ( !(o1 >= o4), "" ); - static_assert ( !(o1 >= o5), "" ); + static_assert((o1 >= o1), ""); + static_assert((o1 >= o2), ""); + static_assert(!(o1 >= o3), ""); + static_assert(!(o1 >= o4), ""); + static_assert(!(o1 >= o5), ""); - static_assert ( (o2 >= o1), "" ); - static_assert ( (o2 >= o2), "" ); - static_assert ( !(o2 >= o3), "" ); - static_assert ( !(o2 >= o4), "" ); - static_assert ( !(o2 >= o5), "" ); + static_assert((o2 >= o1), ""); + static_assert((o2 >= o2), ""); + static_assert(!(o2 >= o3), ""); + static_assert(!(o2 >= o4), ""); + static_assert(!(o2 >= o5), ""); - static_assert ( (o3 >= o1), "" ); - static_assert ( (o3 >= o2), "" ); - static_assert ( (o3 >= o3), "" ); - static_assert ( !(o3 >= o4), "" ); - static_assert ( (o3 >= o5), "" ); + static_assert((o3 >= o1), ""); + static_assert((o3 >= o2), ""); + static_assert((o3 >= o3), ""); + static_assert(!(o3 >= o4), ""); + static_assert((o3 >= o5), ""); - static_assert ( (o4 >= o1), "" ); - static_assert ( (o4 >= o2), "" ); - static_assert ( (o4 >= o3), "" ); - static_assert ( (o4 >= o4), "" ); - static_assert ( (o4 >= o5), "" ); + static_assert((o4 >= o1), ""); + static_assert((o4 >= o2), ""); + static_assert((o4 >= o3), ""); + static_assert((o4 >= o4), ""); + static_assert((o4 >= o5), ""); - static_assert ( (o5 >= o1), "" ); - static_assert ( (o5 >= o2), "" ); - static_assert ( (o5 >= o3), "" ); - static_assert ( !(o5 >= o4), "" ); - static_assert ( (o5 >= o5), "" ); - } + static_assert((o5 >= o1), ""); + static_assert((o5 >= o2), ""); + static_assert((o5 >= o3), ""); + static_assert(!(o5 >= o4), ""); + static_assert((o5 >= o5), ""); + } + { + using O1 = optional<int>; + using O2 = optional<long>; + constexpr O1 o1(42); + static_assert(o1 >= O2(42), ""); + static_assert(!(O2(11) >= o1), ""); + } + { + using O1 = optional<int>; + using O2 = optional<const int>; + constexpr O1 o1(42); + static_assert(o1 >= O2(42), ""); + static_assert(!(O2(1) >= o1), ""); + } } diff --git a/test/std/utilities/optional/optional.relops/greater_than.pass.cpp b/test/std/utilities/optional/optional.relops/greater_than.pass.cpp index 8a27eb471f283..3946a6102ba9d 100644 --- a/test/std/utilities/optional/optional.relops/greater_than.pass.cpp +++ b/test/std/utilities/optional/optional.relops/greater_than.pass.cpp @@ -16,55 +16,66 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator > ( const X &lhs, const X &rhs ) - { return lhs.i_ > rhs.i_ ; } +constexpr bool operator>(const X& lhs, const X& rhs) { return lhs.i_ > rhs.i_; } -int main() -{ - { +int main() { + { typedef optional<X> O; - constexpr O o1; // disengaged - constexpr O o2; // disengaged - constexpr O o3{1}; // engaged - constexpr O o4{2}; // engaged - constexpr O o5{1}; // engaged + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged - static_assert ( !(o1 > o1), "" ); - static_assert ( !(o1 > o2), "" ); - static_assert ( !(o1 > o3), "" ); - static_assert ( !(o1 > o4), "" ); - static_assert ( !(o1 > o5), "" ); + static_assert(!(o1 > o1), ""); + static_assert(!(o1 > o2), ""); + static_assert(!(o1 > o3), ""); + static_assert(!(o1 > o4), ""); + static_assert(!(o1 > o5), ""); - static_assert ( !(o2 > o1), "" ); - static_assert ( !(o2 > o2), "" ); - static_assert ( !(o2 > o3), "" ); - static_assert ( !(o2 > o4), "" ); - static_assert ( !(o2 > o5), "" ); + static_assert(!(o2 > o1), ""); + static_assert(!(o2 > o2), ""); + static_assert(!(o2 > o3), ""); + static_assert(!(o2 > o4), ""); + static_assert(!(o2 > o5), ""); - static_assert ( (o3 > o1), "" ); - static_assert ( (o3 > o2), "" ); - static_assert ( !(o3 > o3), "" ); - static_assert ( !(o3 > o4), "" ); - static_assert ( !(o3 > o5), "" ); + static_assert((o3 > o1), ""); + static_assert((o3 > o2), ""); + static_assert(!(o3 > o3), ""); + static_assert(!(o3 > o4), ""); + static_assert(!(o3 > o5), ""); - static_assert ( (o4 > o1), "" ); - static_assert ( (o4 > o2), "" ); - static_assert ( (o4 > o3), "" ); - static_assert ( !(o4 > o4), "" ); - static_assert ( (o4 > o5), "" ); + static_assert((o4 > o1), ""); + static_assert((o4 > o2), ""); + static_assert((o4 > o3), ""); + static_assert(!(o4 > o4), ""); + static_assert((o4 > o5), ""); - static_assert ( (o5 > o1), "" ); - static_assert ( (o5 > o2), "" ); - static_assert ( !(o5 > o3), "" ); - static_assert ( !(o5 > o4), "" ); - static_assert ( !(o5 > o5), "" ); - } + static_assert((o5 > o1), ""); + static_assert((o5 > o2), ""); + static_assert(!(o5 > o3), ""); + static_assert(!(o5 > o4), ""); + static_assert(!(o5 > o5), ""); + } + { + using O1 = optional<int>; + using O2 = optional<long>; + constexpr O1 o1(42); + static_assert(o1 > O2(1), ""); + static_assert(!(O2(42) > o1), ""); + } + { + using O1 = optional<int>; + using O2 = optional<const int>; + constexpr O1 o1(42); + static_assert(o1 > O2(1), ""); + static_assert(!(O2(42) > o1), ""); + } } diff --git a/test/std/utilities/optional/optional.relops/less_equal.pass.cpp b/test/std/utilities/optional/optional.relops/less_equal.pass.cpp index a7d594dd34a2d..5a1954154f442 100644 --- a/test/std/utilities/optional/optional.relops/less_equal.pass.cpp +++ b/test/std/utilities/optional/optional.relops/less_equal.pass.cpp @@ -16,55 +16,68 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator <= ( const X &lhs, const X &rhs ) - { return lhs.i_ <= rhs.i_ ; } +constexpr bool operator<=(const X& lhs, const X& rhs) { + return lhs.i_ <= rhs.i_; +} -int main() -{ - { +int main() { + { typedef optional<X> O; - constexpr O o1; // disengaged - constexpr O o2; // disengaged - constexpr O o3{1}; // engaged - constexpr O o4{2}; // engaged - constexpr O o5{1}; // engaged + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged - static_assert ( (o1 <= o1), "" ); - static_assert ( (o1 <= o2), "" ); - static_assert ( (o1 <= o3), "" ); - static_assert ( (o1 <= o4), "" ); - static_assert ( (o1 <= o5), "" ); + static_assert((o1 <= o1), ""); + static_assert((o1 <= o2), ""); + static_assert((o1 <= o3), ""); + static_assert((o1 <= o4), ""); + static_assert((o1 <= o5), ""); - static_assert ( (o2 <= o1), "" ); - static_assert ( (o2 <= o2), "" ); - static_assert ( (o2 <= o3), "" ); - static_assert ( (o2 <= o4), "" ); - static_assert ( (o2 <= o5), "" ); + static_assert((o2 <= o1), ""); + static_assert((o2 <= o2), ""); + static_assert((o2 <= o3), ""); + static_assert((o2 <= o4), ""); + static_assert((o2 <= o5), ""); - static_assert ( !(o3 <= o1), "" ); - static_assert ( !(o3 <= o2), "" ); - static_assert ( (o3 <= o3), "" ); - static_assert ( (o3 <= o4), "" ); - static_assert ( (o3 <= o5), "" ); + static_assert(!(o3 <= o1), ""); + static_assert(!(o3 <= o2), ""); + static_assert((o3 <= o3), ""); + static_assert((o3 <= o4), ""); + static_assert((o3 <= o5), ""); - static_assert ( !(o4 <= o1), "" ); - static_assert ( !(o4 <= o2), "" ); - static_assert ( !(o4 <= o3), "" ); - static_assert ( (o4 <= o4), "" ); - static_assert ( !(o4 <= o5), "" ); + static_assert(!(o4 <= o1), ""); + static_assert(!(o4 <= o2), ""); + static_assert(!(o4 <= o3), ""); + static_assert((o4 <= o4), ""); + static_assert(!(o4 <= o5), ""); - static_assert ( !(o5 <= o1), "" ); - static_assert ( !(o5 <= o2), "" ); - static_assert ( (o5 <= o3), "" ); - static_assert ( (o5 <= o4), "" ); - static_assert ( (o5 <= o5), "" ); - } + static_assert(!(o5 <= o1), ""); + static_assert(!(o5 <= o2), ""); + static_assert((o5 <= o3), ""); + static_assert((o5 <= o4), ""); + static_assert((o5 <= o5), ""); + } + { + using O1 = optional<int>; + using O2 = optional<long>; + constexpr O1 o1(42); + static_assert(o1 <= O2(42), ""); + static_assert(!(O2(101) <= o1), ""); + } + { + using O1 = optional<int>; + using O2 = optional<const int>; + constexpr O1 o1(42); + static_assert(o1 <= O2(42), ""); + static_assert(!(O2(101) <= o1), ""); + } } diff --git a/test/std/utilities/optional/optional.relops/less_than.pass.cpp b/test/std/utilities/optional/optional.relops/less_than.pass.cpp index deffa5e849f9d..35956e6f4a70e 100644 --- a/test/std/utilities/optional/optional.relops/less_than.pass.cpp +++ b/test/std/utilities/optional/optional.relops/less_than.pass.cpp @@ -16,55 +16,66 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator < ( const X &lhs, const X &rhs ) - { return lhs.i_ < rhs.i_ ; } +constexpr bool operator<(const X& lhs, const X& rhs) { return lhs.i_ < rhs.i_; } -int main() -{ - { +int main() { + { typedef optional<X> O; - constexpr O o1; // disengaged - constexpr O o2; // disengaged - constexpr O o3{1}; // engaged - constexpr O o4{2}; // engaged - constexpr O o5{1}; // engaged + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged - static_assert ( !(o1 < o1), "" ); - static_assert ( !(o1 < o2), "" ); - static_assert ( (o1 < o3), "" ); - static_assert ( (o1 < o4), "" ); - static_assert ( (o1 < o5), "" ); + static_assert(!(o1 < o1), ""); + static_assert(!(o1 < o2), ""); + static_assert((o1 < o3), ""); + static_assert((o1 < o4), ""); + static_assert((o1 < o5), ""); - static_assert ( !(o2 < o1), "" ); - static_assert ( !(o2 < o2), "" ); - static_assert ( (o2 < o3), "" ); - static_assert ( (o2 < o4), "" ); - static_assert ( (o2 < o5), "" ); + static_assert(!(o2 < o1), ""); + static_assert(!(o2 < o2), ""); + static_assert((o2 < o3), ""); + static_assert((o2 < o4), ""); + static_assert((o2 < o5), ""); - static_assert ( !(o3 < o1), "" ); - static_assert ( !(o3 < o2), "" ); - static_assert ( !(o3 < o3), "" ); - static_assert ( (o3 < o4), "" ); - static_assert ( !(o3 < o5), "" ); + static_assert(!(o3 < o1), ""); + static_assert(!(o3 < o2), ""); + static_assert(!(o3 < o3), ""); + static_assert((o3 < o4), ""); + static_assert(!(o3 < o5), ""); - static_assert ( !(o4 < o1), "" ); - static_assert ( !(o4 < o2), "" ); - static_assert ( !(o4 < o3), "" ); - static_assert ( !(o4 < o4), "" ); - static_assert ( !(o4 < o5), "" ); + static_assert(!(o4 < o1), ""); + static_assert(!(o4 < o2), ""); + static_assert(!(o4 < o3), ""); + static_assert(!(o4 < o4), ""); + static_assert(!(o4 < o5), ""); - static_assert ( !(o5 < o1), "" ); - static_assert ( !(o5 < o2), "" ); - static_assert ( !(o5 < o3), "" ); - static_assert ( (o5 < o4), "" ); - static_assert ( !(o5 < o5), "" ); - } + static_assert(!(o5 < o1), ""); + static_assert(!(o5 < o2), ""); + static_assert(!(o5 < o3), ""); + static_assert((o5 < o4), ""); + static_assert(!(o5 < o5), ""); + } + { + using O1 = optional<int>; + using O2 = optional<long>; + constexpr O1 o1(42); + static_assert(o1 < O2(101), ""); + static_assert(!(O2(101) < o1), ""); + } + { + using O1 = optional<int>; + using O2 = optional<const int>; + constexpr O1 o1(42); + static_assert(o1 < O2(101), ""); + static_assert(!(O2(101) < o1), ""); + } } diff --git a/test/std/utilities/optional/optional.relops/not_equal.pass.cpp b/test/std/utilities/optional/optional.relops/not_equal.pass.cpp index fd11b2a207ca8..1256537d6a867 100644 --- a/test/std/utilities/optional/optional.relops/not_equal.pass.cpp +++ b/test/std/utilities/optional/optional.relops/not_equal.pass.cpp @@ -18,57 +18,69 @@ using std::optional; -struct X -{ - int i_; +struct X { + int i_; - constexpr X(int i) : i_(i) {} + constexpr X(int i) : i_(i) {} }; -constexpr bool operator != ( const X &lhs, const X &rhs ) - { return lhs.i_ != rhs.i_ ; } +constexpr bool operator!=(const X& lhs, const X& rhs) { + return lhs.i_ != rhs.i_; +} -int main() -{ - { +int main() { + { typedef X T; typedef optional<T> O; - constexpr O o1; // disengaged - constexpr O o2; // disengaged - constexpr O o3{1}; // engaged - constexpr O o4{2}; // engaged - constexpr O o5{1}; // engaged - - static_assert ( !(o1 != o1), "" ); - static_assert ( !(o1 != o2), "" ); - static_assert ( (o1 != o3), "" ); - static_assert ( (o1 != o4), "" ); - static_assert ( (o1 != o5), "" ); + constexpr O o1; // disengaged + constexpr O o2; // disengaged + constexpr O o3{1}; // engaged + constexpr O o4{2}; // engaged + constexpr O o5{1}; // engaged - static_assert ( !(o2 != o1), "" ); - static_assert ( !(o2 != o2), "" ); - static_assert ( (o2 != o3), "" ); - static_assert ( (o2 != o4), "" ); - static_assert ( (o2 != o5), "" ); + static_assert(!(o1 != o1), ""); + static_assert(!(o1 != o2), ""); + static_assert((o1 != o3), ""); + static_assert((o1 != o4), ""); + static_assert((o1 != o5), ""); - static_assert ( (o3 != o1), "" ); - static_assert ( (o3 != o2), "" ); - static_assert ( !(o3 != o3), "" ); - static_assert ( (o3 != o4), "" ); - static_assert ( !(o3 != o5), "" ); + static_assert(!(o2 != o1), ""); + static_assert(!(o2 != o2), ""); + static_assert((o2 != o3), ""); + static_assert((o2 != o4), ""); + static_assert((o2 != o5), ""); - static_assert ( (o4 != o1), "" ); - static_assert ( (o4 != o2), "" ); - static_assert ( (o4 != o3), "" ); - static_assert ( !(o4 != o4), "" ); - static_assert ( (o4 != o5), "" ); + static_assert((o3 != o1), ""); + static_assert((o3 != o2), ""); + static_assert(!(o3 != o3), ""); + static_assert((o3 != o4), ""); + static_assert(!(o3 != o5), ""); - static_assert ( (o5 != o1), "" ); - static_assert ( (o5 != o2), "" ); - static_assert ( !(o5 != o3), "" ); - static_assert ( (o5 != o4), "" ); - static_assert ( !(o5 != o5), "" ); + static_assert((o4 != o1), ""); + static_assert((o4 != o2), ""); + static_assert((o4 != o3), ""); + static_assert(!(o4 != o4), ""); + static_assert((o4 != o5), ""); - } + static_assert((o5 != o1), ""); + static_assert((o5 != o2), ""); + static_assert(!(o5 != o3), ""); + static_assert((o5 != o4), ""); + static_assert(!(o5 != o5), ""); + } + { + using O1 = optional<int>; + using O2 = optional<long>; + constexpr O1 o1(42); + static_assert(o1 != O2(101), ""); + static_assert(!(O2(42) != o1), ""); + } + { + using O1 = optional<int>; + using O2 = optional<const int>; + constexpr O1 o1(42); + static_assert(o1 != O2(101), ""); + static_assert(!(O2(42) != o1), ""); + } } diff --git a/test/std/utilities/smartptr/unique.ptr/README.TXT b/test/std/utilities/smartptr/unique.ptr/README.TXT new file mode 100644 index 0000000000000..20f77f61827ce --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/README.TXT @@ -0,0 +1,16 @@ +Test Naming and Directory Structure +=================================== + +The directory structure for the unique_ptr class templates differs from the +normal test directory naming conventions (e.g. matching the stable name in the standard). + +Instead of having a [unique.ptr.single] and [unique.ptr.runtime] directory, +each containing their own tests, a single directory, "unique.ptr.class", +contains both sets of tests. + +This allows the common behavior of the two unique_ptr specializations to be +tested in the same place without duplication. + +Tests specific to [unique.ptr.single] have the suffix ".single.pass.cpp" +and those specific to [unique.ptr.runtime] are named "*.runtime.pass.cpp". +Tests for both specializations are named normally. diff --git a/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp b/test/std/utilities/smartptr/unique.ptr/nothing_to_do.pass.cpp index b58f5c55b643a..b58f5c55b643a 100644 --- a/test/std/utilities/memory/unique.ptr/nothing_to_do.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/nothing_to_do.pass.cpp diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp new file mode 100644 index 0000000000000..54c2cf16ecc72 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/pointer_type.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr::pointer type + +#include <memory> +#include <type_traits> + +#include "test_macros.h" + +struct Deleter { + struct pointer {}; +}; + +struct D2 { +private: + typedef void pointer; +}; + +struct D3 { + static long pointer; +}; + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, int[], int>::type VT; + { + typedef std::unique_ptr<VT> P; + static_assert((std::is_same<typename P::pointer, int*>::value), ""); + } + { + typedef std::unique_ptr<VT, Deleter> P; + static_assert((std::is_same<typename P::pointer, Deleter::pointer>::value), + ""); + } +#if TEST_STD_VER >= 11 + { + typedef std::unique_ptr<VT, D2> P; + static_assert(std::is_same<typename P::pointer, int*>::value, ""); + } + { + typedef std::unique_ptr<VT, D3> P; + static_assert(std::is_same<typename P::pointer, int*>::value, ""); + } +#endif +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp new file mode 100644 index 0000000000000..5d2f955aa185f --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// Test unique_ptr move assignment + +// test move assignment. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. + +#include <memory> +#include <utility> +#include <cassert> + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +struct GenericDeleter { + void operator()(void*) const; +}; + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + std::unique_ptr<VT> s1(newValue<VT>(expect_alive)); + A* p = s1.get(); + std::unique_ptr<VT> s2(newValue<VT>(expect_alive)); + assert(A::count == (expect_alive * 2)); + s2 = std::move(s1); + assert(A::count == expect_alive); + assert(s2.get() == p); + assert(s1.get() == 0); + } + assert(A::count == 0); + { + std::unique_ptr<VT, Deleter<VT> > s1(newValue<VT>(expect_alive), + Deleter<VT>(5)); + A* p = s1.get(); + std::unique_ptr<VT, Deleter<VT> > s2(newValue<VT>(expect_alive)); + assert(A::count == (expect_alive * 2)); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == expect_alive); + assert(s2.get_deleter().state() == 5); + assert(s1.get_deleter().state() == 0); + } + assert(A::count == 0); + { + CDeleter<VT> d1(5); + std::unique_ptr<VT, CDeleter<VT>&> s1(newValue<VT>(expect_alive), d1); + A* p = s1.get(); + CDeleter<VT> d2(6); + std::unique_ptr<VT, CDeleter<VT>&> s2(newValue<VT>(expect_alive), d2); + s2 = std::move(s1); + assert(s2.get() == p); + assert(s1.get() == 0); + assert(A::count == expect_alive); + assert(d1.state() == 5); + assert(d2.state() == 5); + } + assert(A::count == 0); +} + +template <bool IsArray> +void test_sfinae() { + typedef typename std::conditional<IsArray, int[], int>::type VT; + { + typedef std::unique_ptr<VT> U; + static_assert(!std::is_assignable<U, U&>::value, ""); + static_assert(!std::is_assignable<U, const U&>::value, ""); + static_assert(!std::is_assignable<U, const U&&>::value, ""); + static_assert(std::is_nothrow_assignable<U, U&&>::value, ""); + } + { + typedef std::unique_ptr<VT, GenericDeleter> U; + static_assert(!std::is_assignable<U, U&>::value, ""); + static_assert(!std::is_assignable<U, const U&>::value, ""); + static_assert(!std::is_assignable<U, const U&&>::value, ""); + static_assert(std::is_nothrow_assignable<U, U&&>::value, ""); + } + { + typedef std::unique_ptr<VT, NCDeleter<VT>&> U; + static_assert(!std::is_assignable<U, U&>::value, ""); + static_assert(!std::is_assignable<U, const U&>::value, ""); + static_assert(!std::is_assignable<U, const U&&>::value, ""); + static_assert(std::is_nothrow_assignable<U, U&&>::value, ""); + } + { + typedef std::unique_ptr<VT, const NCDeleter<VT>&> U; + static_assert(!std::is_assignable<U, U&>::value, ""); + static_assert(!std::is_assignable<U, const U&>::value, ""); + static_assert(!std::is_assignable<U, const U&&>::value, ""); + static_assert(std::is_nothrow_assignable<U, U&&>::value, ""); + } +} + + +int main() { + { + test_basic</*IsArray*/ false>(); + test_sfinae<false>(); + } + { + test_basic</*IsArray*/ true>(); + test_sfinae<true>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.pass.cpp new file mode 100644 index 0000000000000..8d83c3c8888a9 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.pass.cpp @@ -0,0 +1,420 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" +#include "type_id.h" + +template <int ID = 0> +struct GenericDeleter { + void operator()(void*) const {} +}; + +template <int ID = 0> +struct GenericConvertingDeleter { + + template <int OID> + GenericConvertingDeleter(GenericConvertingDeleter<OID>) {} + + template <int OID> + GenericConvertingDeleter& operator=(GenericConvertingDeleter<OID> const&) { + return *this; + } + + void operator()(void*) const {} +}; + +template <class T, class U> +using EnableIfNotSame = typename std::enable_if< + !std::is_same<typename std::decay<T>::type, typename std::decay<U>::type>::value +>::type; + +template <class Templ, class Other> +struct is_specialization; + +template <template <int> class Templ, int ID1, class Other> +struct is_specialization<Templ<ID1>, Other> : std::false_type {}; + +template <template <int> class Templ, int ID1, int ID2> +struct is_specialization<Templ<ID1>, Templ<ID2> > : std::true_type {}; + +template <class Templ, class Other> +using EnableIfSpecialization = typename std::enable_if< + is_specialization<Templ, typename std::decay<Other>::type >::value + >::type; + +template <int ID> struct TrackingDeleter; +template <int ID> struct ConstTrackingDeleter; + +template <int ID> +struct TrackingDeleter { + TrackingDeleter() : arg_type(&makeArgumentID<>()) {} + + TrackingDeleter(TrackingDeleter const&) + : arg_type(&makeArgumentID<TrackingDeleter const&>()) {} + + TrackingDeleter(TrackingDeleter&&) + : arg_type(&makeArgumentID<TrackingDeleter &&>()) {} + + template <class T, class = EnableIfSpecialization<TrackingDeleter, T> > + TrackingDeleter(T&&) : arg_type(&makeArgumentID<T&&>()) {} + + TrackingDeleter& operator=(TrackingDeleter const&) { + arg_type = &makeArgumentID<TrackingDeleter const&>(); + return *this; + } + + TrackingDeleter& operator=(TrackingDeleter &&) { + arg_type = &makeArgumentID<TrackingDeleter &&>(); + return *this; + } + + template <class T, class = EnableIfSpecialization<TrackingDeleter, T> > + TrackingDeleter& operator=(T&&) { + arg_type = &makeArgumentID<T&&>(); + return *this; + } + + void operator()(void*) const {} + +public: + TypeID const* reset() const { + TypeID const* tmp = arg_type; + arg_type = nullptr; + return tmp; + } + + mutable TypeID const* arg_type; +}; + +template <int ID> +struct ConstTrackingDeleter { + ConstTrackingDeleter() : arg_type(&makeArgumentID<>()) {} + + ConstTrackingDeleter(ConstTrackingDeleter const&) + : arg_type(&makeArgumentID<ConstTrackingDeleter const&>()) {} + + ConstTrackingDeleter(ConstTrackingDeleter&&) + : arg_type(&makeArgumentID<ConstTrackingDeleter &&>()) {} + + template <class T, class = EnableIfSpecialization<ConstTrackingDeleter, T> > + ConstTrackingDeleter(T&&) : arg_type(&makeArgumentID<T&&>()) {} + + const ConstTrackingDeleter& operator=(ConstTrackingDeleter const&) const { + arg_type = &makeArgumentID<ConstTrackingDeleter const&>(); + return *this; + } + + const ConstTrackingDeleter& operator=(ConstTrackingDeleter &&) const { + arg_type = &makeArgumentID<ConstTrackingDeleter &&>(); + return *this; + } + + template <class T, class = EnableIfSpecialization<ConstTrackingDeleter, T> > + const ConstTrackingDeleter& operator=(T&&) const { + arg_type = &makeArgumentID<T&&>(); + return *this; + } + + void operator()(void*) const {} + +public: + TypeID const* reset() const { + TypeID const* tmp = arg_type; + arg_type = nullptr; + return tmp; + } + + mutable TypeID const* arg_type; +}; + +template <class ExpectT, int ID> +bool checkArg(TrackingDeleter<ID> const& d) { + return d.arg_type && *d.arg_type == makeArgumentID<ExpectT>(); +} + +template <class ExpectT, int ID> +bool checkArg(ConstTrackingDeleter<ID> const& d) { + return d.arg_type && *d.arg_type == makeArgumentID<ExpectT>(); +} + +template <class From, bool AssignIsConst = false> +struct AssignDeleter { + AssignDeleter() = default; + AssignDeleter(AssignDeleter const&) = default; + AssignDeleter(AssignDeleter&&) = default; + + AssignDeleter& operator=(AssignDeleter const&) = delete; + AssignDeleter& operator=(AssignDeleter &&) = delete; + + template <class T> AssignDeleter& operator=(T&&) && = delete; + template <class T> AssignDeleter& operator=(T&&) const && = delete; + + template <class T, class = typename std::enable_if< + std::is_same<T&&, From>::value && !AssignIsConst + >::type> + AssignDeleter& operator=(T&&) & { return *this; } + + template <class T, class = typename std::enable_if< + std::is_same<T&&, From>::value && AssignIsConst + >::type> + const AssignDeleter& operator=(T&&) const & { return *this; } + + template <class T> + void operator()(T) const {} +}; + +template <class VT, class DDest, class DSource> + void doDeleterTest() { + using U1 = std::unique_ptr<VT, DDest>; + using U2 = std::unique_ptr<VT, DSource>; + static_assert(std::is_nothrow_assignable<U1, U2&&>::value, ""); + typename std::decay<DDest>::type ddest; + typename std::decay<DSource>::type dsource; + U1 u1(nullptr, ddest); + U2 u2(nullptr, dsource); + u1 = std::move(u2); +} + +template <bool IsArray> +void test_sfinae() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + + { // Test that different non-reference deleter types are allowed so long + // as they convert to each other. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + static_assert(std::is_assignable<U1, U2&&>::value, ""); + } + { // Test that different non-reference deleter types are disallowed when + // they cannot convert. + using U1 = std::unique_ptr<VT, GenericDeleter<0> >; + using U2 = std::unique_ptr<VT, GenericDeleter<1> >; + static_assert(!std::is_assignable<U1, U2&&>::value, ""); + } + { // Test that if the deleter assignment is not valid the assignment operator + // SFINAEs. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> const& >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U3 = std::unique_ptr<VT, GenericConvertingDeleter<0> &>; + using U4 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + using U5 = std::unique_ptr<VT, GenericConvertingDeleter<1> const&>; + static_assert(!std::is_assignable<U1, U2&&>::value, ""); + static_assert(!std::is_assignable<U1, U3&&>::value, ""); + static_assert(!std::is_assignable<U1, U4&&>::value, ""); + static_assert(!std::is_assignable<U1, U5&&>::value, ""); + + using U1C = std::unique_ptr<const VT, GenericConvertingDeleter<0> const&>; + static_assert(std::is_nothrow_assignable<U1C, U1&&>::value, ""); + } + { // Test that if the deleter assignment is not valid the assignment operator + // SFINAEs. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> & >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U3 = std::unique_ptr<VT, GenericConvertingDeleter<0> &>; + using U4 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + using U5 = std::unique_ptr<VT, GenericConvertingDeleter<1> const&>; + + static_assert(std::is_nothrow_assignable<U1, U2&&>::value, ""); + static_assert(std::is_nothrow_assignable<U1, U3&&>::value, ""); + static_assert(std::is_nothrow_assignable<U1, U4&&>::value, ""); + static_assert(std::is_nothrow_assignable<U1, U5&&>::value, ""); + + using U1C = std::unique_ptr<const VT, GenericConvertingDeleter<0> &>; + static_assert(std::is_nothrow_assignable<U1C, U1&&>::value, ""); + } + { // Test that non-reference destination deleters can be assigned + // from any source deleter type with a sutible conversion. Including + // reference types. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<0> &>; + using U3 = std::unique_ptr<VT, GenericConvertingDeleter<0> const &>; + using U4 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + using U5 = std::unique_ptr<VT, GenericConvertingDeleter<1> &>; + using U6 = std::unique_ptr<VT, GenericConvertingDeleter<1> const&>; + static_assert(std::is_assignable<U1, U2&&>::value, ""); + static_assert(std::is_assignable<U1, U3&&>::value, ""); + static_assert(std::is_assignable<U1, U4&&>::value, ""); + static_assert(std::is_assignable<U1, U5&&>::value, ""); + static_assert(std::is_assignable<U1, U6&&>::value, ""); + } + ///////////////////////////////////////////////////////////////////////////// + { + using Del = GenericDeleter<0>; + using AD = AssignDeleter<Del&&>; + using ADC = AssignDeleter<Del&&, /*AllowConstAssign*/true>; + doDeleterTest<VT, AD, Del>(); + doDeleterTest<VT, AD&, Del>(); + doDeleterTest<VT, ADC const&, Del>(); + } + { + using Del = GenericDeleter<0>; + using AD = AssignDeleter<Del&>; + using ADC = AssignDeleter<Del&, /*AllowConstAssign*/true>; + doDeleterTest<VT, AD, Del&>(); + doDeleterTest<VT, AD&, Del&>(); + doDeleterTest<VT, ADC const&, Del&>(); + } + { + using Del = GenericDeleter<0>; + using AD = AssignDeleter<Del const&>; + using ADC = AssignDeleter<Del const&, /*AllowConstAssign*/true>; + doDeleterTest<VT, AD, Del const&>(); + doDeleterTest<VT, AD&, Del const&>(); + doDeleterTest<VT, ADC const&, Del const&>(); + } +} + + +template <bool IsArray> +void test_noexcept() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + { + typedef std::unique_ptr<const VT> APtr; + typedef std::unique_ptr<VT> BPtr; + static_assert(std::is_nothrow_assignable<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<const VT, CDeleter<const VT> > APtr; + typedef std::unique_ptr<VT, CDeleter<VT> > BPtr; + static_assert(std::is_nothrow_assignable<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<const VT, NCDeleter<const VT>&> APtr; + typedef std::unique_ptr<VT, NCDeleter<const VT>&> BPtr; + static_assert(std::is_nothrow_assignable<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<const VT, const NCConstDeleter<const VT>&> APtr; + typedef std::unique_ptr<VT, const NCConstDeleter<const VT>&> BPtr; + static_assert(std::is_nothrow_assignable<APtr, BPtr>::value, ""); + } +} + +template <bool IsArray> +void test_deleter_value_category() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + using TD1 = TrackingDeleter<1>; + using TD2 = TrackingDeleter<2>; + TD1 d1; + TD2 d2; + using CD1 = ConstTrackingDeleter<1>; + using CD2 = ConstTrackingDeleter<2>; + CD1 cd1; + CD2 cd2; + + { // Test non-reference deleter conversions + using U1 = std::unique_ptr<VT, TD1 >; + using U2 = std::unique_ptr<VT, TD2 >; + U1 u1; + U2 u2; + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<TD2&&>(u1.get_deleter())); + } + { // Test assignment to non-const ref + using U1 = std::unique_ptr<VT, TD1& >; + using U2 = std::unique_ptr<VT, TD2 >; + U1 u1(nullptr, d1); + U2 u2; + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<TD2&&>(u1.get_deleter())); + } + { // Test assignment to const&. + using U1 = std::unique_ptr<VT, CD1 const& >; + using U2 = std::unique_ptr<VT, CD2 >; + U1 u1(nullptr, cd1); + U2 u2; + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<CD2&&>(u1.get_deleter())); + } + + { // Test assignment from non-const ref + using U1 = std::unique_ptr<VT, TD1 >; + using U2 = std::unique_ptr<VT, TD2& >; + U1 u1; + U2 u2(nullptr, d2); + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<TD2&>(u1.get_deleter())); + } + { // Test assignment from const ref + using U1 = std::unique_ptr<VT, TD1 >; + using U2 = std::unique_ptr<VT, TD2 const& >; + U1 u1; + U2 u2(nullptr, d2); + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<TD2 const&>(u1.get_deleter())); + } + + { // Test assignment from non-const ref + using U1 = std::unique_ptr<VT, TD1& >; + using U2 = std::unique_ptr<VT, TD2& >; + U1 u1(nullptr, d1); + U2 u2(nullptr, d2); + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<TD2&>(u1.get_deleter())); + } + { // Test assignment from const ref + using U1 = std::unique_ptr<VT, TD1& >; + using U2 = std::unique_ptr<VT, TD2 const& >; + U1 u1(nullptr, d1); + U2 u2(nullptr, d2); + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<TD2 const&>(u1.get_deleter())); + } + + { // Test assignment from non-const ref + using U1 = std::unique_ptr<VT, CD1 const& >; + using U2 = std::unique_ptr<VT, CD2 & >; + U1 u1(nullptr, cd1); + U2 u2(nullptr, cd2); + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<CD2 &>(u1.get_deleter())); + } + { // Test assignment from const ref + using U1 = std::unique_ptr<VT, CD1 const& >; + using U2 = std::unique_ptr<VT, CD2 const& >; + U1 u1(nullptr, cd1); + U2 u2(nullptr, cd2); + u1.get_deleter().reset(); + u1 = std::move(u2); + assert(checkArg<CD2 const&>(u1.get_deleter())); + } +} + +int main() { + { + test_sfinae</*IsArray*/false>(); + test_noexcept<false>(); + test_deleter_value_category<false>(); + } + { + test_sfinae</*IsArray*/true>(); + test_noexcept<true>(); + test_deleter_value_category<true>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp new file mode 100644 index 0000000000000..9b946a733fea6 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.runtime.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +#include "unique_ptr_test_helper.h" + +template <class APtr, class BPtr> +void testAssign(APtr& aptr, BPtr& bptr) { + A* p = bptr.get(); + assert(A::count == 2); + aptr = std::move(bptr); + assert(aptr.get() == p); + assert(bptr.get() == 0); + assert(A::count == 1); + assert(B::count == 1); +} + +template <class LHS, class RHS> +void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { + assert(lhs.get_deleter().state() == LHSState); + assert(rhs.get_deleter().state() == RHSState); +} + +template <class T> +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template <class U> + NCConvertingDeleter(NCConvertingDeleter<U>&&) {} + + void operator()(T*) const {} +}; + +template <class T> +struct NCConvertingDeleter<T[]> { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template <class U> + NCConvertingDeleter(NCConvertingDeleter<U>&&) {} + + void operator()(T*) const {} +}; + +struct GenericDeleter { + void operator()(void*) const; +}; + +struct NCGenericDeleter { + NCGenericDeleter() = default; + NCGenericDeleter(NCGenericDeleter const&) = delete; + NCGenericDeleter(NCGenericDeleter&&) = default; + + void operator()(void*) const {} +}; + +void test_sfinae() { + using DA = NCConvertingDeleter<A[]>; // non-copyable deleters + using DAC = NCConvertingDeleter<const A[]>; // non-copyable deleters + + using DB = NCConvertingDeleter<B[]>; + using UA = std::unique_ptr<A[]>; + using UAC = std::unique_ptr<const A[]>; + using UB = std::unique_ptr<B[]>; + using UAD = std::unique_ptr<A[], DA>; + using UACD = std::unique_ptr<const A[], DAC>; + + using UBD = std::unique_ptr<B[], DB>; + { // cannot move from an lvalue + static_assert(std::is_assignable<UAC, UA&&>::value, ""); + static_assert(!std::is_assignable<UAC, UA&>::value, ""); + static_assert(!std::is_assignable<UAC, const UA&>::value, ""); + } + { // cannot move if the deleter-types cannot convert + static_assert(std::is_assignable<UACD, UAD&&>::value, ""); + static_assert(!std::is_assignable<UACD, UAC&&>::value, ""); + static_assert(!std::is_assignable<UAC, UACD&&>::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr<A[], DA&>; + using UA2 = std::unique_ptr<A[], DAC&>; + static_assert(!std::is_assignable<UA1, UA2&&>::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr<A[], const DA&>; + using UA2 = std::unique_ptr<A[], const DAC&>; + static_assert(!std::is_assignable<UA1, UA2&&>::value, ""); + } + { // cannot move-convert from unique_ptr<Single> + using UA1 = std::unique_ptr<A[]>; + using UA2 = std::unique_ptr<A>; + static_assert(!std::is_assignable<UA1, UA2&&>::value, ""); + } + { // cannot move-convert from unique_ptr<Array[]> + using UA1 = std::unique_ptr<A[], NCGenericDeleter>; + using UA2 = std::unique_ptr<A, NCGenericDeleter>; + static_assert(!std::is_assignable<UA1, UA2&&>::value, ""); + } +} + +int main() { + test_sfinae(); + // FIXME: add tests +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp new file mode 100644 index 0000000000000..3f2ea422dab33 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/move_convert.single.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move assignment + +#include <memory> +#include <utility> +#include <cassert> + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +template <class APtr, class BPtr> +void testAssign(APtr& aptr, BPtr& bptr) { + A* p = bptr.get(); + assert(A::count == 2); + aptr = std::move(bptr); + assert(aptr.get() == p); + assert(bptr.get() == 0); + assert(A::count == 1); + assert(B::count == 1); +} + +template <class LHS, class RHS> +void checkDeleter(LHS& lhs, RHS& rhs, int LHSState, int RHSState) { + assert(lhs.get_deleter().state() == LHSState); + assert(rhs.get_deleter().state() == RHSState); +} + +template <class T> +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template <class U> + NCConvertingDeleter(NCConvertingDeleter<U>&&) {} + + void operator()(T*) const {} +}; + +template <class T> +struct NCConvertingDeleter<T[]> { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template <class U> + NCConvertingDeleter(NCConvertingDeleter<U>&&) {} + + void operator()(T*) const {} +}; + +struct NCGenericDeleter { + NCGenericDeleter() = default; + NCGenericDeleter(NCGenericDeleter const&) = delete; + NCGenericDeleter(NCGenericDeleter&&) = default; + + void operator()(void*) const {} +}; + +void test_sfinae() { + using DA = NCConvertingDeleter<A>; // non-copyable deleters + using DB = NCConvertingDeleter<B>; + using UA = std::unique_ptr<A>; + using UB = std::unique_ptr<B>; + using UAD = std::unique_ptr<A, DA>; + using UBD = std::unique_ptr<B, DB>; + { // cannot move from an lvalue + static_assert(std::is_assignable<UA, UB&&>::value, ""); + static_assert(!std::is_assignable<UA, UB&>::value, ""); + static_assert(!std::is_assignable<UA, const UB&>::value, ""); + } + { // cannot move if the deleter-types cannot convert + static_assert(std::is_assignable<UAD, UBD&&>::value, ""); + static_assert(!std::is_assignable<UAD, UB&&>::value, ""); + static_assert(!std::is_assignable<UA, UBD&&>::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr<A, DA&>; + using UB1 = std::unique_ptr<B, DB&>; + static_assert(!std::is_assignable<UA1, UB1&&>::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr<A, const DA&>; + using UB1 = std::unique_ptr<B, const DB&>; + static_assert(!std::is_assignable<UA1, UB1&&>::value, ""); + } + { // cannot move-convert from unique_ptr<Array[]> + using UA1 = std::unique_ptr<A>; + using UA2 = std::unique_ptr<A[]>; + using UB1 = std::unique_ptr<B[]>; + static_assert(!std::is_assignable<UA1, UA2&&>::value, ""); + static_assert(!std::is_assignable<UA1, UB1&&>::value, ""); + } + { // cannot move-convert from unique_ptr<Array[]> + using UA1 = std::unique_ptr<A, NCGenericDeleter>; + using UA2 = std::unique_ptr<A[], NCGenericDeleter>; + using UB1 = std::unique_ptr<B[], NCGenericDeleter>; + static_assert(!std::is_assignable<UA1, UA2&&>::value, ""); + static_assert(!std::is_assignable<UA1, UB1&&>::value, ""); + } +} + +int main() { + test_sfinae(); + { + std::unique_ptr<B> bptr(new B); + std::unique_ptr<A> aptr(new A); + testAssign(aptr, bptr); + } + assert(A::count == 0); + assert(B::count == 0); + { + Deleter<B> del(42); + std::unique_ptr<B, Deleter<B> > bptr(new B, std::move(del)); + std::unique_ptr<A, Deleter<A> > aptr(new A); + testAssign(aptr, bptr); + checkDeleter(aptr, bptr, 42, 0); + } + assert(A::count == 0); + assert(B::count == 0); + { + CDeleter<A> adel(6); + CDeleter<B> bdel(42); + std::unique_ptr<B, CDeleter<B>&> bptr(new B, bdel); + std::unique_ptr<A, CDeleter<A>&> aptr(new A, adel); + testAssign(aptr, bptr); + checkDeleter(aptr, bptr, 42, 42); + } + assert(A::count == 0); + assert(B::count == 0); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/null.pass.cpp index e2d7956cda643..165d48a1caa53 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/null.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/null.pass.cpp @@ -16,26 +16,24 @@ #include <memory> #include <cassert> -// test assignment from null - -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - ~A() {--count;} -}; +#include "unique_ptr_test_helper.h" -int A::count = 0; - -int main() -{ - { - std::unique_ptr<A> s2(new A); - assert(A::count == 1); - s2 = 0; +// test assignment from null +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + std::unique_ptr<VT> s2(newValue<VT>(expect_alive)); + assert(A::count == expect_alive); + s2 = NULL; assert(A::count == 0); assert(s2.get() == 0); - } - assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/nullptr.pass.cpp index fb15849519938..e1e2e32e23c48 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.asgn/nullptr.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.asgn/nullptr.pass.cpp @@ -16,26 +16,25 @@ #include <memory> #include <cassert> +#include "unique_ptr_test_helper.h" + // 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); +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + std::unique_ptr<VT> s2(newValue<VT>(expect_alive)); + assert(A::count == expect_alive); s2 = nullptr; assert(A::count == 0); assert(s2.get() == 0); - } - assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); } diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/auto_pointer.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/auto_pointer.pass.cpp new file mode 100644 index 0000000000000..7d5e9bca63c45 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/auto_pointer.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// libc++ cannot safely provide the auto_ptr constructor without rvalue +// references. +// REQUIRES: c++11 || c++14 + +// <memory> + +// unique_ptr + +// template <class U> unique_ptr(auto_ptr<U>&&) noexcept + +#include <memory> +#include <utility> +#include <cassert> + +#include "test_macros.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; + +struct C {}; + +struct Deleter { + void operator()(void*) {} +}; + +void test_sfinae() { + { + // the auto_ptr constructor should be disable with a non-default deleter. + using AP = std::auto_ptr<int>; + using U = std::unique_ptr<int, Deleter>; + static_assert(!std::is_constructible<U, AP&&>::value, ""); + } + { + // the auto_ptr constructor should be disabled when the pointer types are incompatible. + using AP = std::auto_ptr<A>; + using U = std::unique_ptr<C>; + static_assert(!std::is_constructible<U, AP&&>::value, ""); + } +} + +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); +#if TEST_STD_VER >= 11 + { + static_assert(std::is_nothrow_constructible<std::unique_ptr<A>, + std::auto_ptr<B>&&>::value, + ""); + } +#endif + test_sfinae(); +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp new file mode 100644 index 0000000000000..51d9aa708c407 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/default.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +//============================================================================= +// TESTING std::unique_ptr::unique_ptr() +// +// Concerns: +// 1 The default constructor works for any default constructible deleter types. +// 2 The stored type 'T' is allowed to be incomplete. +// +// Plan +// 1 Default construct unique_ptr's with various deleter types (C-1) +// 2 Default construct a unique_ptr with an incomplete element_type and +// various deleter types (C-1,2) + +#include <memory> +#include <cassert> +#include "test_macros.h" + +#include "test_macros.h" +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11 +_LIBCPP_SAFE_STATIC std::unique_ptr<int> global_static_unique_ptr_single; +_LIBCPP_SAFE_STATIC std::unique_ptr<int[]> global_static_unique_ptr_runtime; +#endif + +#if TEST_STD_VER >= 11 +struct NonDefaultDeleter { + NonDefaultDeleter() = delete; + void operator()(void*) const {} +}; +#endif + +template <class ElemType> +void test_sfinae() { +#if TEST_STD_VER >= 11 + { // the constructor does not participate in overload resultion when + // the deleter is a pointer type + using U = std::unique_ptr<ElemType, void (*)(void*)>; + static_assert(!std::is_default_constructible<U>::value, ""); + } + { // the constructor does not participate in overload resolution when + // the deleter is not default constructible + using Del = CDeleter<ElemType>; + using U1 = std::unique_ptr<ElemType, NonDefaultDeleter>; + using U2 = std::unique_ptr<ElemType, Del&>; + using U3 = std::unique_ptr<ElemType, Del const&>; + static_assert(!std::is_default_constructible<U1>::value, ""); + static_assert(!std::is_default_constructible<U2>::value, ""); + static_assert(!std::is_default_constructible<U3>::value, ""); + } +#endif +} + +template <class ElemType> +void test_basic() { +#if TEST_STD_VER >= 11 + { + using U1 = std::unique_ptr<ElemType>; + using U2 = std::unique_ptr<ElemType, Deleter<ElemType> >; + static_assert(std::is_nothrow_default_constructible<U1>::value, ""); + static_assert(std::is_nothrow_default_constructible<U2>::value, ""); + } +#endif + { + std::unique_ptr<ElemType> p; + assert(p.get() == 0); + } + { + std::unique_ptr<ElemType, NCDeleter<ElemType> > p; + assert(p.get() == 0); + assert(p.get_deleter().state() == 0); + p.get_deleter().set_state(5); + assert(p.get_deleter().state() == 5); + } +} + +DEFINE_AND_RUN_IS_INCOMPLETE_TEST({ + doIncompleteTypeTest(0); + doIncompleteTypeTest<IncompleteType, Deleter<IncompleteType> >(0); +} { + doIncompleteTypeTest<IncompleteType[]>(0); + doIncompleteTypeTest<IncompleteType[], Deleter<IncompleteType[]> >(0); +}) + +int main() { + { + test_sfinae<int>(); + test_basic<int>(); + } + { + test_sfinae<int[]>(); + test_basic<int[]>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp new file mode 100644 index 0000000000000..c102f27fb8e6d --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move.pass.cpp @@ -0,0 +1,174 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr move ctor + +#include <memory> +#include <utility> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +//============================================================================= +// TESTING unique_ptr(unique_ptr&&) +// +// Concerns +// 1 The moved from pointer is empty and the new pointer stores the old value. +// 2 The only requirement on the deleter is that it is MoveConstructible +// or a reference. +// 3 The constructor works for explicitly moved values (ie std::move(x)) +// 4 The constructor works for true temporaries (ie a return value) +// +// Plan +// 1 Explicitly construct unique_ptr<T, D> for various deleter types 'D'. +// check that the value and deleter have been properly moved. (C-1,2,3) +// +// 2 Use the expression 'sink(source())' to move construct a unique_ptr<T, D> +// from a temporary. 'source' should return the unique_ptr by value and +// 'sink' should accept the unique_ptr by value. (C-1,2,4) + +template <class VT> +std::unique_ptr<VT> source1() { + return std::unique_ptr<VT>(newValue<VT>(1)); +} + +template <class VT> +std::unique_ptr<VT, Deleter<VT> > source2() { + return std::unique_ptr<VT, Deleter<VT> >(newValue<VT>(1), Deleter<VT>(5)); +} + +template <class VT> +std::unique_ptr<VT, NCDeleter<VT>&> source3() { + static NCDeleter<VT> d(5); + return std::unique_ptr<VT, NCDeleter<VT>&>(newValue<VT>(1), d); +} + +template <class VT> +void sink1(std::unique_ptr<VT> p) { + assert(p.get() != nullptr); +} + +template <class VT> +void sink2(std::unique_ptr<VT, Deleter<VT> > p) { + assert(p.get() != nullptr); + assert(p.get_deleter().state() == 5); +} + +template <class VT> +void sink3(std::unique_ptr<VT, NCDeleter<VT>&> p) { + assert(p.get() != nullptr); + assert(p.get_deleter().state() == 5); + assert(&p.get_deleter() == &source3<VT>().get_deleter()); +} + +template <class ValueT> +void test_sfinae() { + typedef std::unique_ptr<ValueT> U; + { // Ensure unique_ptr is non-copyable + static_assert((!std::is_constructible<U, U const&>::value), ""); + static_assert((!std::is_constructible<U, U&>::value), ""); + } +} + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<!IsArray, A, A[]>::type VT; + const int expect_alive = IsArray ? 5 : 1; + { + typedef std::unique_ptr<VT> APtr; + APtr s(newValue<VT>(expect_alive)); + A* p = s.get(); + APtr s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == expect_alive); + } + assert(A::count == 0); + { + typedef Deleter<VT> MoveDel; + typedef std::unique_ptr<VT, MoveDel> APtr; + MoveDel d(5); + APtr s(newValue<VT>(expect_alive), std::move(d)); + assert(d.state() == 0); + assert(s.get_deleter().state() == 5); + A* p = s.get(); + APtr s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == expect_alive); + assert(s2.get_deleter().state() == 5); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + { + typedef NCDeleter<VT> NonCopyDel; + typedef std::unique_ptr<VT, NonCopyDel&> APtr; + + NonCopyDel d; + APtr s(newValue<VT>(expect_alive), d); + A* p = s.get(); + APtr s2 = std::move(s); + assert(s2.get() == p); + assert(s.get() == 0); + assert(A::count == expect_alive); + d.set_state(6); + assert(s2.get_deleter().state() == d.state()); + assert(s.get_deleter().state() == d.state()); + } + assert(A::count == 0); + { + sink1<VT>(source1<VT>()); + assert(A::count == 0); + sink2<VT>(source2<VT>()); + assert(A::count == 0); + sink3<VT>(source3<VT>()); + assert(A::count == 0); + } + assert(A::count == 0); +} + +template <class VT> +void test_noexcept() { +#if TEST_STD_VER >= 11 + { + typedef std::unique_ptr<VT> U; + static_assert(std::is_nothrow_move_constructible<U>::value, ""); + } + { + typedef std::unique_ptr<VT, Deleter<VT> > U; + static_assert(std::is_nothrow_move_constructible<U>::value, ""); + } + { + typedef std::unique_ptr<VT, NCDeleter<VT> &> U; + static_assert(std::is_nothrow_move_constructible<U>::value, ""); + } + { + typedef std::unique_ptr<VT, const NCConstDeleter<VT> &> U; + static_assert(std::is_nothrow_move_constructible<U>::value, ""); + } +#endif +} + +int main() { + { + test_basic</*IsArray*/ false>(); + test_sfinae<int>(); + test_noexcept<int>(); + } + { + test_basic</*IsArray*/ true>(); + test_sfinae<int[]>(); + test_noexcept<int[]>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.pass.cpp new file mode 100644 index 0000000000000..6e5db86c97fc4 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.pass.cpp @@ -0,0 +1,124 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template <int ID = 0> +struct GenericDeleter { + void operator()(void*) const {} +}; + +template <int ID = 0> +struct GenericConvertingDeleter { + template <int OID> + GenericConvertingDeleter(GenericConvertingDeleter<OID>) {} + void operator()(void*) const {} +}; + +template <bool IsArray> +void test_sfinae() { +#if TEST_STD_VER >= 11 + typedef typename std::conditional<IsArray, A[], A>::type VT; + + { // Test that different non-reference deleter types are allowed so long + // as they convert to each other. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + static_assert(std::is_constructible<U1, U2&&>::value, ""); + } + { // Test that different non-reference deleter types are disallowed when + // they cannot convert. + using U1 = std::unique_ptr<VT, GenericDeleter<0> >; + using U2 = std::unique_ptr<VT, GenericDeleter<1> >; + static_assert(!std::is_constructible<U1, U2&&>::value, ""); + } + { // Test that if the destination deleter is a reference type then only + // exact matches are allowed. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> const& >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U3 = std::unique_ptr<VT, GenericConvertingDeleter<0> &>; + using U4 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + using U5 = std::unique_ptr<VT, GenericConvertingDeleter<1> const&>; + static_assert(!std::is_constructible<U1, U2&&>::value, ""); + static_assert(!std::is_constructible<U1, U3&&>::value, ""); + static_assert(!std::is_constructible<U1, U4&&>::value, ""); + static_assert(!std::is_constructible<U1, U5&&>::value, ""); + + using U1C = std::unique_ptr<const VT, GenericConvertingDeleter<0> const&>; + static_assert(std::is_nothrow_constructible<U1C, U1&&>::value, ""); + } + { // Test that non-reference destination deleters can be constructed + // from any source deleter type with a sutible conversion. Including + // reference types. + using U1 = std::unique_ptr<VT, GenericConvertingDeleter<0> >; + using U2 = std::unique_ptr<VT, GenericConvertingDeleter<0> &>; + using U3 = std::unique_ptr<VT, GenericConvertingDeleter<0> const &>; + using U4 = std::unique_ptr<VT, GenericConvertingDeleter<1> >; + using U5 = std::unique_ptr<VT, GenericConvertingDeleter<1> &>; + using U6 = std::unique_ptr<VT, GenericConvertingDeleter<1> const&>; + static_assert(std::is_constructible<U1, U2&&>::value, ""); + static_assert(std::is_constructible<U1, U3&&>::value, ""); + static_assert(std::is_constructible<U1, U4&&>::value, ""); + static_assert(std::is_constructible<U1, U5&&>::value, ""); + static_assert(std::is_constructible<U1, U6&&>::value, ""); + } +#endif +} + + +template <bool IsArray> +void test_noexcept() { +#if TEST_STD_VER >= 11 + typedef typename std::conditional<IsArray, A[], A>::type VT; + { + typedef std::unique_ptr<const VT> APtr; + typedef std::unique_ptr<VT> BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<const VT, CDeleter<const VT> > APtr; + typedef std::unique_ptr<VT, CDeleter<VT> > BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<const VT, NCDeleter<const VT>&> APtr; + typedef std::unique_ptr<VT, NCDeleter<const VT>&> BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<const VT, const NCConstDeleter<const VT>&> APtr; + typedef std::unique_ptr<VT, const NCConstDeleter<const VT>&> BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } +#endif +} + + +int main() { + { + test_sfinae</*IsArray*/false>(); + test_noexcept<false>(); + } + { + test_sfinae</*IsArray*/true>(); + test_noexcept<true>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp new file mode 100644 index 0000000000000..09e842b5987f5 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.runtime.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +#include <memory> +#include <cassert> + +#include "deleter_types.h" +#include "unique_ptr_test_helper.h" + +template <int ID = 0> +struct GenericDeleter { + void operator()(void*) const {} +}; + +template <int ID = 0> +struct GenericConvertingDeleter { + template <int OID> + GenericConvertingDeleter(GenericConvertingDeleter<OID>) {} + void operator()(void*) const {} +}; + +void test_sfinae() { + { // Disallow copying + using U1 = std::unique_ptr<A[], GenericConvertingDeleter<0> >; + using U2 = std::unique_ptr<A[], GenericConvertingDeleter<1> >; + static_assert(std::is_constructible<U1, U2&&>::value, ""); + static_assert(!std::is_constructible<U1, U2&>::value, ""); + static_assert(!std::is_constructible<U1, const U2&>::value, ""); + static_assert(!std::is_constructible<U1, const U2&&>::value, ""); + } + { // Disallow illegal qualified conversions + using U1 = std::unique_ptr<const A[]>; + using U2 = std::unique_ptr<A[]>; + static_assert(std::is_constructible<U1, U2&&>::value, ""); + static_assert(!std::is_constructible<U2, U1&&>::value, ""); + } + { // Disallow base-to-derived conversions. + using UA = std::unique_ptr<A[]>; + using UB = std::unique_ptr<B[]>; + static_assert(!std::is_constructible<UA, UB&&>::value, ""); + } + { // Disallow base-to-derived conversions. + using UA = std::unique_ptr<A[], GenericConvertingDeleter<0> >; + using UB = std::unique_ptr<B[], GenericConvertingDeleter<1> >; + static_assert(!std::is_constructible<UA, UB&&>::value, ""); + } + { // Disallow invalid deleter initialization + using U1 = std::unique_ptr<A[], GenericDeleter<0> >; + using U2 = std::unique_ptr<A[], GenericDeleter<1> >; + static_assert(!std::is_constructible<U1, U2&&>::value, ""); + } + { // Disallow reference deleters with different qualifiers + using U1 = std::unique_ptr<A[], Deleter<A[]>&>; + using U2 = std::unique_ptr<A[], const Deleter<A[]>&>; + static_assert(!std::is_constructible<U1, U2&&>::value, ""); + static_assert(!std::is_constructible<U2, U1&&>::value, ""); + } + { + using U1 = std::unique_ptr<A[]>; + using U2 = std::unique_ptr<A>; + static_assert(!std::is_constructible<U1, U2&&>::value, ""); + static_assert(!std::is_constructible<U2, U1&&>::value, ""); + } +} + + +int main() { + test_sfinae(); +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp new file mode 100644 index 0000000000000..4e2a6dfa3dd11 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/move_convert.single.pass.cpp @@ -0,0 +1,248 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// + +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// Test unique_ptr converting move ctor + +// NOTE: unique_ptr does not provide converting constructors in c++03 +// UNSUPPORTED: c++98, c++03 + +#include <memory> +#include <type_traits> +#include <utility> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +// test converting move ctor. Should only require a MoveConstructible deleter, or if +// deleter is a reference, not even that. +// Explicit version + +template <class LHS, class RHS> +void checkReferenceDeleter(LHS& lhs, RHS& rhs) { + typedef typename LHS::deleter_type NewDel; + static_assert(std::is_reference<NewDel>::value, ""); + rhs.get_deleter().set_state(42); + assert(rhs.get_deleter().state() == 42); + assert(lhs.get_deleter().state() == 42); + lhs.get_deleter().set_state(99); + assert(lhs.get_deleter().state() == 99); + assert(rhs.get_deleter().state() == 99); +} + +template <class LHS, class RHS> +void checkDeleter(LHS& lhs, RHS& rhs, int LHSVal, int RHSVal) { + assert(lhs.get_deleter().state() == LHSVal); + assert(rhs.get_deleter().state() == RHSVal); +} + +template <class LHS, class RHS> +void checkCtor(LHS& lhs, RHS& rhs, A* RHSVal) { + assert(lhs.get() == RHSVal); + assert(rhs.get() == nullptr); + assert(A::count == 1); + assert(B::count == 1); +} + +void checkNoneAlive() { + assert(A::count == 0); + assert(B::count == 0); +} + +template <class T> +struct NCConvertingDeleter { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template <class U> + NCConvertingDeleter(NCConvertingDeleter<U>&&) {} + + void operator()(T*) const {} +}; + +template <class T> +struct NCConvertingDeleter<T[]> { + NCConvertingDeleter() = default; + NCConvertingDeleter(NCConvertingDeleter const&) = delete; + NCConvertingDeleter(NCConvertingDeleter&&) = default; + + template <class U> + NCConvertingDeleter(NCConvertingDeleter<U>&&) {} + + void operator()(T*) const {} +}; + +struct NCGenericDeleter { + NCGenericDeleter() = default; + NCGenericDeleter(NCGenericDeleter const&) = delete; + NCGenericDeleter(NCGenericDeleter&&) = default; + + void operator()(void*) const {} +}; + +void test_sfinae() { + using DA = NCConvertingDeleter<A>; // non-copyable deleters + using DB = NCConvertingDeleter<B>; + using UA = std::unique_ptr<A>; + using UB = std::unique_ptr<B>; + using UAD = std::unique_ptr<A, DA>; + using UBD = std::unique_ptr<B, DB>; + { // cannot move from an lvalue + static_assert(std::is_constructible<UA, UB&&>::value, ""); + static_assert(!std::is_constructible<UA, UB&>::value, ""); + static_assert(!std::is_constructible<UA, const UB&>::value, ""); + } + { // cannot move if the deleter-types cannot convert + static_assert(std::is_constructible<UAD, UBD&&>::value, ""); + static_assert(!std::is_constructible<UAD, UB&&>::value, ""); + static_assert(!std::is_constructible<UA, UBD&&>::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr<A, DA&>; + using UB1 = std::unique_ptr<B, DB&>; + static_assert(!std::is_constructible<UA1, UB1&&>::value, ""); + } + { // cannot move-convert with reference deleters of different types + using UA1 = std::unique_ptr<A, const DA&>; + using UB1 = std::unique_ptr<B, const DB&>; + static_assert(!std::is_constructible<UA1, UB1&&>::value, ""); + } + { // cannot move-convert from unique_ptr<Array[]> + using UA1 = std::unique_ptr<A>; + using UA2 = std::unique_ptr<A[]>; + using UB1 = std::unique_ptr<B[]>; + static_assert(!std::is_constructible<UA1, UA2&&>::value, ""); + static_assert(!std::is_constructible<UA1, UB1&&>::value, ""); + } + { // cannot move-convert from unique_ptr<Array[]> + using UA1 = std::unique_ptr<A, NCGenericDeleter>; + using UA2 = std::unique_ptr<A[], NCGenericDeleter>; + using UB1 = std::unique_ptr<B[], NCGenericDeleter>; + static_assert(!std::is_constructible<UA1, UA2&&>::value, ""); + static_assert(!std::is_constructible<UA1, UB1&&>::value, ""); + } +} + +void test_noexcept() { + { + typedef std::unique_ptr<A> APtr; + typedef std::unique_ptr<B> BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<A, Deleter<A> > APtr; + typedef std::unique_ptr<B, Deleter<B> > BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<A, NCDeleter<A>&> APtr; + typedef std::unique_ptr<B, NCDeleter<A>&> BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } + { + typedef std::unique_ptr<A, const NCConstDeleter<A>&> APtr; + typedef std::unique_ptr<B, const NCConstDeleter<A>&> BPtr; + static_assert(std::is_nothrow_constructible<APtr, BPtr>::value, ""); + } +} + +int main() { + { + test_sfinae(); + test_noexcept(); + } + { + typedef std::unique_ptr<A> APtr; + typedef std::unique_ptr<B> BPtr; + { // explicit + BPtr b(new B); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + } + checkNoneAlive(); + { // implicit + BPtr b(new B); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + } + checkNoneAlive(); + } + { // test with moveable deleters + typedef std::unique_ptr<A, Deleter<A> > APtr; + typedef std::unique_ptr<B, Deleter<B> > BPtr; + { + Deleter<B> del(5); + BPtr b(new B, std::move(del)); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 0); + } + checkNoneAlive(); + { + Deleter<B> del(5); + BPtr b(new B, std::move(del)); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 0); + } + checkNoneAlive(); + } + { // test with reference deleters + typedef std::unique_ptr<A, NCDeleter<A>&> APtr; + typedef std::unique_ptr<B, NCDeleter<A>&> BPtr; + NCDeleter<A> del(5); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + checkReferenceDeleter(a, b); + } + checkNoneAlive(); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + checkReferenceDeleter(a, b); + } + checkNoneAlive(); + } + { + typedef std::unique_ptr<A, CDeleter<A> > APtr; + typedef std::unique_ptr<B, CDeleter<B>&> BPtr; + CDeleter<B> del(5); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a(std::move(b)); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 5); + } + checkNoneAlive(); + { + BPtr b(new B, del); + A* p = b.get(); + APtr a = std::move(b); + checkCtor(a, b, p); + checkDeleter(a, b, 5, 5); + } + checkNoneAlive(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp new file mode 100644 index 0000000000000..8bc8a57c1c8d8 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/null.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <memory> + +// unique_ptr + +// FIXME(EricWF): This test contains tests for constructing a unique_ptr from NULL. +// The behavior demonstrated in this test is not meant to be standard; It simply +// tests the current status quo in libc++. + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template <class VT> +void test_pointer_ctor() { + { + std::unique_ptr<VT> p(0); + assert(p.get() == 0); + } + { + std::unique_ptr<VT, Deleter<VT> > p(0); + assert(p.get() == 0); + assert(p.get_deleter().state() == 0); + } +} + +template <class VT> +void test_pointer_deleter_ctor() { + { + std::default_delete<VT> d; + std::unique_ptr<VT> p(0, d); + assert(p.get() == 0); + } + { + std::unique_ptr<VT, Deleter<VT> > p(0, Deleter<VT>(5)); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } + { + NCDeleter<VT> d(5); + std::unique_ptr<VT, NCDeleter<VT>&> p(0, d); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } + { + NCConstDeleter<VT> d(5); + std::unique_ptr<VT, NCConstDeleter<VT> const&> p(0, d); + assert(p.get() == 0); + assert(p.get_deleter().state() == 5); + } +} + +int main() { + { + // test_pointer_ctor<int>(); + test_pointer_deleter_ctor<int>(); + } + { + test_pointer_ctor<int[]>(); + test_pointer_deleter_ctor<int[]>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp new file mode 100644 index 0000000000000..6764935fee14c --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/nullptr.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// unique_ptr(nullptr_t); + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + + +#if defined(_LIBCPP_VERSION) && TEST_STD_VER >= 11 +_LIBCPP_SAFE_STATIC std::unique_ptr<int> global_static_unique_ptr_single(nullptr); +_LIBCPP_SAFE_STATIC std::unique_ptr<int[]> global_static_unique_ptr_runtime(nullptr); +#endif + + +#if TEST_STD_VER >= 11 +struct NonDefaultDeleter { + NonDefaultDeleter() = delete; + void operator()(void*) const {} +}; +#endif + +template <class VT> +void test_basic() { +#if TEST_STD_VER >= 11 + { + using U1 = std::unique_ptr<VT>; + using U2 = std::unique_ptr<VT, Deleter<VT> >; + static_assert(std::is_nothrow_constructible<U1, decltype(nullptr)>::value, + ""); + static_assert(std::is_nothrow_constructible<U2, decltype(nullptr)>::value, + ""); + } +#endif + { + std::unique_ptr<VT> p(nullptr); + assert(p.get() == 0); + } + { + std::unique_ptr<VT, NCDeleter<VT> > p(nullptr); + assert(p.get() == 0); + assert(p.get_deleter().state() == 0); + } +} + +template <class VT> +void test_sfinae() { +#if TEST_STD_VER >= 11 + { // the constructor does not participate in overload resultion when + // the deleter is a pointer type + using U = std::unique_ptr<VT, void (*)(void*)>; + static_assert(!std::is_constructible<U, decltype(nullptr)>::value, ""); + } + { // the constructor does not participate in overload resolution when + // the deleter is not default constructible + using Del = CDeleter<VT>; + using U1 = std::unique_ptr<VT, NonDefaultDeleter>; + using U2 = std::unique_ptr<VT, Del&>; + using U3 = std::unique_ptr<VT, Del const&>; + static_assert(!std::is_constructible<U1, decltype(nullptr)>::value, ""); + static_assert(!std::is_constructible<U2, decltype(nullptr)>::value, ""); + static_assert(!std::is_constructible<U3, decltype(nullptr)>::value, ""); + } +#endif +} + +DEFINE_AND_RUN_IS_INCOMPLETE_TEST({ + { doIncompleteTypeTest(0, nullptr); } + checkNumIncompleteTypeAlive(0); + { + doIncompleteTypeTest<IncompleteType, NCDeleter<IncompleteType> >(0, + nullptr); + } + checkNumIncompleteTypeAlive(0); + { doIncompleteTypeTest<IncompleteType[]>(0, nullptr); } + checkNumIncompleteTypeAlive(0); + { + doIncompleteTypeTest<IncompleteType[], NCDeleter<IncompleteType[]> >( + 0, nullptr); + } + checkNumIncompleteTypeAlive(0); +}) + +int main() { + { + test_basic<int>(); + test_sfinae<int>(); + } + { + test_basic<int[]>(); + test_sfinae<int[]>(); + } +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp new file mode 100644 index 0000000000000..8df259bd4e1d1 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer.pass.cpp @@ -0,0 +1,171 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +//============================================================================= +// TESTING std::unique_ptr::unique_ptr(pointer) +// +// Concerns: +// 1 The pointer constructor works for any default constructible deleter types. +// 2 The pointer constructor accepts pointers to derived types. +// 2 The stored type 'T' is allowed to be incomplete. +// +// Plan +// 1 Construct unique_ptr<T, D>'s with a pointer to 'T' and various deleter +// types (C-1) +// 2 Construct unique_ptr<T, D>'s with a pointer to 'D' and various deleter +// types where 'D' is derived from 'T'. (C-1,2) +// 3 Construct a unique_ptr<T, D> with a pointer to 'T' and various deleter +// types where 'T' is an incomplete type (C-1,3) + +// Test unique_ptr(pointer) ctor + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +// unique_ptr(pointer) ctor should only require default Deleter ctor + +template <bool IsArray> +void test_pointer() { + typedef typename std::conditional<!IsArray, A, A[]>::type ValueT; + const int expect_alive = IsArray ? 5 : 1; +#if TEST_STD_VER >= 11 + { + using U1 = std::unique_ptr<ValueT>; + using U2 = std::unique_ptr<ValueT, Deleter<ValueT> >; + + // Test for noexcept + static_assert(std::is_nothrow_constructible<U1, A*>::value, ""); + static_assert(std::is_nothrow_constructible<U2, A*>::value, ""); + + // Test for explicit + static_assert(!std::is_convertible<A*, U1>::value, ""); + static_assert(!std::is_convertible<A*, U2>::value, ""); + } +#endif + { + A* p = newValue<ValueT>(expect_alive); + assert(A::count == expect_alive); + std::unique_ptr<ValueT> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + { + A* p = newValue<ValueT>(expect_alive); + assert(A::count == expect_alive); + std::unique_ptr<ValueT, NCDeleter<ValueT> > s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); +} + +void test_derived() { + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A> s(p); + assert(s.get() == p); + } + assert(A::count == 0); + assert(B::count == 0); + { + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A, NCDeleter<A> > s(p); + assert(s.get() == p); + assert(s.get_deleter().state() == 0); + } + assert(A::count == 0); + assert(B::count == 0); +} + +#if TEST_STD_VER >= 11 +struct NonDefaultDeleter { + NonDefaultDeleter() = delete; + void operator()(void*) const {} +}; + +struct GenericDeleter { + void operator()(void*) const; +}; +#endif + +template <class T> +void test_sfinae() { +#if TEST_STD_VER >= 11 + { // the constructor does not participate in overload resultion when + // the deleter is a pointer type + using U = std::unique_ptr<T, void (*)(void*)>; + static_assert(!std::is_constructible<U, T*>::value, ""); + } + { // the constructor does not participate in overload resolution when + // the deleter is not default constructible + using Del = CDeleter<T>; + using U1 = std::unique_ptr<T, NonDefaultDeleter>; + using U2 = std::unique_ptr<T, Del&>; + using U3 = std::unique_ptr<T, Del const&>; + static_assert(!std::is_constructible<U1, T*>::value, ""); + static_assert(!std::is_constructible<U2, T*>::value, ""); + static_assert(!std::is_constructible<U3, T*>::value, ""); + } +#endif +} + +static void test_sfinae_runtime() { +#if TEST_STD_VER >= 11 + { // the constructor does not participate in overload resolution when + // a base <-> derived conversion would occur. + using UA = std::unique_ptr<A[]>; + using UAD = std::unique_ptr<A[], GenericDeleter>; + using UAC = std::unique_ptr<const A[]>; + using UB = std::unique_ptr<B[]>; + using UBD = std::unique_ptr<B[], GenericDeleter>; + using UBC = std::unique_ptr<const B[]>; + + static_assert(!std::is_constructible<UA, B*>::value, ""); + static_assert(!std::is_constructible<UB, A*>::value, ""); + static_assert(!std::is_constructible<UAD, B*>::value, ""); + static_assert(!std::is_constructible<UBD, A*>::value, ""); + static_assert(!std::is_constructible<UAC, const B*>::value, ""); + static_assert(!std::is_constructible<UBC, const A*>::value, ""); + } +#endif +} + +DEFINE_AND_RUN_IS_INCOMPLETE_TEST({ + { doIncompleteTypeTest(1, getNewIncomplete()); } + checkNumIncompleteTypeAlive(0); + { + doIncompleteTypeTest<IncompleteType, NCDeleter<IncompleteType> >( + 1, getNewIncomplete()); + } + checkNumIncompleteTypeAlive(0); +}) + +int main() { + { + test_pointer</*IsArray*/ false>(); + test_derived(); + test_sfinae<int>(); + } + { + test_pointer</*IsArray*/ true>(); + test_sfinae<int[]>(); + test_sfinae_runtime(); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.fail.cpp index ad64b5e4ea395..b4cd3f36ab573 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor/pointer_deleter04.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.fail.cpp @@ -20,11 +20,10 @@ #include <memory> struct Deleter { - void operator()(int* p) const {delete p;} + void operator()(int* p) const { delete p; } }; -int main() -{ - // expected-error@memory:* {{static_assert failed "rvalue deleter bound to reference"}} - std::unique_ptr<int, const Deleter&> s((int*)nullptr, Deleter()); // expected-note {{requested here}} +int main() { + // expected-error@+1 {{call to deleted constructor of 'std::unique_ptr<int, const Deleter &>}} + std::unique_ptr<int, const Deleter&> s((int*)nullptr, Deleter()); } diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp new file mode 100644 index 0000000000000..781794d41b5e3 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.ctor/pointer_deleter.pass.cpp @@ -0,0 +1,328 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +//============================================================================= +// TESTING unique_ptr(pointer, deleter) +// +// Concerns: +// 1 unique_ptr(pointer, deleter&&) only requires a MoveConstructible deleter. +// 2 unique_ptr(pointer, deleter&) requires a CopyConstructible deleter. +// 3 unique_ptr<T, D&>(pointer, deleter) does not require a CopyConstructible deleter. +// 4 unique_ptr<T, D const&>(pointer, deleter) does not require a CopyConstructible deleter. +// 5 unique_ptr(pointer, deleter) should work for derived pointers. +// 6 unique_ptr(pointer, deleter) should work with function pointers. +// 7 unique_ptr<void> should work. + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +bool my_free_called = false; + +void my_free(void*) { my_free_called = true; } + +#if TEST_STD_VER >= 11 +struct DeleterBase { + void operator()(void*) const {} +}; +struct CopyOnlyDeleter : DeleterBase { + CopyOnlyDeleter() = default; + CopyOnlyDeleter(CopyOnlyDeleter const&) = default; + CopyOnlyDeleter(CopyOnlyDeleter&&) = delete; +}; +struct MoveOnlyDeleter : DeleterBase { + MoveOnlyDeleter() = default; + MoveOnlyDeleter(MoveOnlyDeleter&&) = default; +}; +struct NoCopyMoveDeleter : DeleterBase { + NoCopyMoveDeleter() = default; + NoCopyMoveDeleter(NoCopyMoveDeleter const&) = delete; +}; +#endif + +template <bool IsArray> +void test_sfinae() { +#if TEST_STD_VER >= 11 + typedef typename std::conditional<!IsArray, int, int[]>::type VT; + { + using D = CopyOnlyDeleter; + using U = std::unique_ptr<VT, D>; + static_assert(std::is_constructible<U, int*, D const&>::value, ""); + static_assert(std::is_constructible<U, int*, D&>::value, ""); + static_assert(std::is_constructible<U, int*, D&&>::value, ""); + // FIXME: __libcpp_compressed_pair attempts to perform a move even though + // it should only copy. + //D d; + //U u(nullptr, std::move(d)); + } + { + using D = MoveOnlyDeleter; + using U = std::unique_ptr<VT, D>; + static_assert(!std::is_constructible<U, int*, D const&>::value, ""); + static_assert(!std::is_constructible<U, int*, D&>::value, ""); + static_assert(std::is_constructible<U, int*, D&&>::value, ""); + D d; + U u(nullptr, std::move(d)); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<VT, D>; + static_assert(!std::is_constructible<U, int*, D const&>::value, ""); + static_assert(!std::is_constructible<U, int*, D&>::value, ""); + static_assert(!std::is_constructible<U, int*, D&&>::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<VT, D&>; + static_assert(!std::is_constructible<U, int*, D const&>::value, ""); + static_assert(std::is_constructible<U, int*, D&>::value, ""); + static_assert(!std::is_constructible<U, int*, D&&>::value, ""); + static_assert(!std::is_constructible<U, int*, const D&&>::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<VT, const D&>; + static_assert(std::is_constructible<U, int*, D const&>::value, ""); + static_assert(std::is_constructible<U, int*, D&>::value, ""); + static_assert(!std::is_constructible<U, int*, D&&>::value, ""); + static_assert(!std::is_constructible<U, int*, const D&&>::value, ""); + } +#endif +} + +template <bool IsArray> +void test_noexcept() { +#if TEST_STD_VER >= 11 + typedef typename std::conditional<!IsArray, int, int[]>::type VT; + { + using D = CopyOnlyDeleter; + using U = std::unique_ptr<VT, D>; + static_assert(std::is_nothrow_constructible<U, int*, D const&>::value, ""); + static_assert(std::is_nothrow_constructible<U, int*, D&>::value, ""); + static_assert(std::is_nothrow_constructible<U, int*, D&&>::value, ""); + } + { + using D = MoveOnlyDeleter; + using U = std::unique_ptr<VT, D>; + static_assert(std::is_nothrow_constructible<U, int*, D&&>::value, ""); + D d; + U u(nullptr, std::move(d)); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<VT, D&>; + static_assert(std::is_nothrow_constructible<U, int*, D&>::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<VT, const D&>; + static_assert(std::is_nothrow_constructible<U, int*, D const&>::value, ""); + static_assert(std::is_nothrow_constructible<U, int*, D&>::value, ""); + } +#endif +} + +void test_sfinae_runtime() { +#if TEST_STD_VER >= 11 + { + using D = CopyOnlyDeleter; + using U = std::unique_ptr<A[], D>; + static_assert(std::is_nothrow_constructible<U, A*, D const&>::value, ""); + static_assert(std::is_nothrow_constructible<U, A*, D&>::value, ""); + static_assert(std::is_nothrow_constructible<U, A*, D&&>::value, ""); + + static_assert(!std::is_constructible<U, B*, D const&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&&>::value, ""); + // FIXME: __libcpp_compressed_pair attempts to perform a move even though + // it should only copy. + //D d; + //U u(nullptr, std::move(d)); + } + { + using D = MoveOnlyDeleter; + using U = std::unique_ptr<A[], D>; + static_assert(!std::is_constructible<U, A*, D const&>::value, ""); + static_assert(!std::is_constructible<U, A*, D&>::value, ""); + static_assert(std::is_nothrow_constructible<U, A*, D&&>::value, ""); + + static_assert(!std::is_constructible<U, B*, D const&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&&>::value, ""); + D d; + U u(nullptr, std::move(d)); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<A[], D>; + static_assert(!std::is_constructible<U, A*, D const&>::value, ""); + static_assert(!std::is_constructible<U, A*, D&>::value, ""); + static_assert(!std::is_constructible<U, A*, D&&>::value, ""); + + static_assert(!std::is_constructible<U, B*, D const&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&&>::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<A[], D&>; + static_assert(!std::is_constructible<U, A*, D const&>::value, ""); + static_assert(std::is_nothrow_constructible<U, A*, D&>::value, ""); + static_assert(!std::is_constructible<U, A*, D&&>::value, ""); + static_assert(!std::is_constructible<U, A*, const D&&>::value, ""); + + static_assert(!std::is_constructible<U, B*, D const&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&&>::value, ""); + static_assert(!std::is_constructible<U, B*, const D&&>::value, ""); + } + { + using D = NoCopyMoveDeleter; + using U = std::unique_ptr<A[], const D&>; + static_assert(std::is_nothrow_constructible<U, A*, D const&>::value, ""); + static_assert(std::is_nothrow_constructible<U, A*, D&>::value, ""); + static_assert(!std::is_constructible<U, A*, D&&>::value, ""); + static_assert(!std::is_constructible<U, A*, const D&&>::value, ""); + + static_assert(!std::is_constructible<U, B*, D const&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&>::value, ""); + static_assert(!std::is_constructible<U, B*, D&&>::value, ""); + static_assert(!std::is_constructible<U, B*, const D&&>::value, ""); + } +#endif +} + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<!IsArray, A, A[]>::type VT; + const int expect_alive = IsArray ? 5 : 1; + { // MoveConstructible deleter (C-1) + A* p = newValue<VT>(expect_alive); + assert(A::count == expect_alive); + std::unique_ptr<VT, Deleter<VT> > s(p, Deleter<VT>(5)); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + { // CopyConstructible deleter (C-2) + A* p = newValue<VT>(expect_alive); + assert(A::count == expect_alive); + CopyDeleter<VT> d(5); + std::unique_ptr<VT, CopyDeleter<VT> > s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + { // Reference deleter (C-3) + A* p = newValue<VT>(expect_alive); + assert(A::count == expect_alive); + NCDeleter<VT> d(5); + std::unique_ptr<VT, NCDeleter<VT>&> s(p, d); + assert(s.get() == p); + assert(&s.get_deleter() == &d); + assert(s.get_deleter().state() == 5); + d.set_state(6); + assert(s.get_deleter().state() == 6); + } + assert(A::count == 0); + { // Const Reference deleter (C-4) + A* p = newValue<VT>(expect_alive); + assert(A::count == expect_alive); + NCConstDeleter<VT> d(5); + std::unique_ptr<VT, NCConstDeleter<VT> const&> s(p, d); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + assert(&s.get_deleter() == &d); + } + assert(A::count == 0); + { // Void and function pointers (C-6,7) + typedef typename std::conditional<IsArray, int[], int>::type VT2; + my_free_called = false; + { + int i = 0; + std::unique_ptr<VT2, void (*)(void*)> s(&i, my_free); + assert(s.get() == &i); + assert(s.get_deleter() == my_free); + assert(!my_free_called); + } + assert(my_free_called); + } +} + +void test_basic_single() { + assert(A::count == 0); + assert(B::count == 0); + { // Derived pointers (C-5) + B* p = new B; + assert(A::count == 1); + assert(B::count == 1); + std::unique_ptr<A, Deleter<A> > s(p, Deleter<A>(5)); + assert(s.get() == p); + assert(s.get_deleter().state() == 5); + } + assert(A::count == 0); + assert(B::count == 0); + { // Void and function pointers (C-6,7) + my_free_called = false; + { + 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); + } +} + +template <bool IsArray> +void test_nullptr() { +#if TEST_STD_VER >= 11 + typedef typename std::conditional<!IsArray, A, A[]>::type VT; + { + std::unique_ptr<VT, Deleter<VT> > u(nullptr, Deleter<VT>{}); + assert(u.get() == nullptr); + } + { + NCDeleter<VT> d; + std::unique_ptr<VT, NCDeleter<VT>& > u(nullptr, d); + assert(u.get() == nullptr); + } + { + NCConstDeleter<VT> d; + std::unique_ptr<VT, NCConstDeleter<VT> const& > u(nullptr, d); + assert(u.get() == nullptr); + } +#endif +} + +int main() { + { + test_basic</*IsArray*/ false>(); + test_nullptr<false>(); + test_basic_single(); + test_sfinae<false>(); + test_noexcept<false>(); + } + { + test_basic</*IsArray*/ true>(); + test_nullptr<true>(); + test_sfinae<true>(); + test_sfinae_runtime(); + test_noexcept<true>(); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.dtor/null.pass.cpp index 064f38c5f167f..fa10ade512064 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.dtor/null.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.dtor/null.pass.cpp @@ -16,29 +16,33 @@ #include <memory> #include <cassert> -class Deleter -{ - int state_; +class Deleter { + int state_; - Deleter(Deleter&); - Deleter& operator=(Deleter&); + Deleter(Deleter&); + Deleter& operator=(Deleter&); public: - Deleter() : state_(0) {} + Deleter() : state_(0) {} - int state() const {return state_;} + int state() const { return state_; } - void operator()(void*) {++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); +template <class T> +void test_basic() { + Deleter d; + assert(d.state() == 0); + { + std::unique_ptr<T, Deleter&> p(nullptr, d); + assert(p.get() == nullptr); assert(&p.get_deleter() == &d); - } - assert(d.state() == 0); + } + assert(d.state() == 0); +} + +int main() { + test_basic<int>(); + test_basic<int[]>(); } diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp new file mode 100644 index 0000000000000..f7f20945094e8 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/release.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test release + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 3 : 1; +#if TEST_STD_VER >= 11 + { + using U = std::unique_ptr<VT>; + U u; ((void)u); + ASSERT_NOEXCEPT(u.release()); + } +#endif + { + std::unique_ptr<VT> p(newValue<VT>(expect_alive)); + assert(A::count == expect_alive); + A* ap = p.get(); + A* a = p.release(); + assert(A::count == expect_alive); + assert(p.get() == nullptr); + assert(ap == a); + assert(a != nullptr); + + if (IsArray) + delete[] a; + else + delete a; + + assert(A::count == 0); + } + assert(A::count == 0); +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp new file mode 100644 index 0000000000000..c95c55b4adf88 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test reset + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template <bool IsArray> +void test_reset_pointer() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 3 : 1; +#if TEST_STD_VER >= 11 + { + using U = std::unique_ptr<VT>; + U u; ((void)u); + ASSERT_NOEXCEPT(u.reset((A*)nullptr)); + } +#endif + { + std::unique_ptr<VT> p(newValue<VT>(expect_alive)); + assert(A::count == expect_alive); + A* i = p.get(); + assert(i != nullptr); + A* new_value = newValue<VT>(expect_alive); + assert(A::count == (expect_alive * 2)); + p.reset(new_value); + assert(A::count == expect_alive); + assert(p.get() == new_value); + } + assert(A::count == 0); + { + std::unique_ptr<const VT> p(newValue<const VT>(expect_alive)); + assert(A::count == expect_alive); + const A* i = p.get(); + assert(i != nullptr); + A* new_value = newValue<VT>(expect_alive); + assert(A::count == (expect_alive * 2)); + p.reset(new_value); + assert(A::count == expect_alive); + assert(p.get() == new_value); + } + assert(A::count == 0); +} + +template <bool IsArray> +void test_reset_nullptr() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 3 : 1; +#if TEST_STD_VER >= 11 + { + using U = std::unique_ptr<VT>; + U u; ((void)u); + ASSERT_NOEXCEPT(u.reset(nullptr)); + } +#endif + { + std::unique_ptr<VT> p(newValue<VT>(expect_alive)); + assert(A::count == expect_alive); + A* i = p.get(); + assert(i != nullptr); + p.reset(nullptr); + assert(A::count == 0); + assert(p.get() == nullptr); + } + assert(A::count == 0); +} + + +template <bool IsArray> +void test_reset_no_arg() { + typedef typename std::conditional<IsArray, A[], A>::type VT; + const int expect_alive = IsArray ? 3 : 1; +#if TEST_STD_VER >= 11 + { + using U = std::unique_ptr<VT>; + U u; ((void)u); + ASSERT_NOEXCEPT(u.reset()); + } +#endif + { + std::unique_ptr<VT> p(newValue<VT>(expect_alive)); + assert(A::count == expect_alive); + A* i = p.get(); + assert(i != nullptr); + p.reset(); + assert(A::count == 0); + assert(p.get() == nullptr); + } + assert(A::count == 0); +} + +int main() { + { + test_reset_pointer</*IsArray*/ false>(); + test_reset_nullptr<false>(); + test_reset_no_arg<false>(); + } + { + test_reset_pointer</*IsArray*/true>(); + test_reset_nullptr<true>(); + test_reset_no_arg<true>(); + } +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.runtime.fail.cpp index 9ec9b9527e8ab..0d067b9abff5b 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/explicit_bool.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.runtime.fail.cpp @@ -11,29 +11,20 @@ // unique_ptr -// test op*() +// test reset #include <memory> #include <cassert> -int main() -{ - { - std::unique_ptr<int[]> p(new int [3]); - if (p) - ; - else - assert(false); - if (!p) - assert(false); - } - { +#include "unique_ptr_test_helper.h" + +int main() { + { + std::unique_ptr<A[]> p; + p.reset(static_cast<B*>(nullptr)); // expected-error {{no matching member function for call to 'reset'}} + } + { std::unique_ptr<int[]> p; - if (!p) - ; - else - assert(false); - if (p) - assert(false); - } + p.reset(static_cast<const int*>(nullptr)); // expected-error {{no matching member function for call to 'reset'}} + } } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp index 2de7787b267e4..8f2a69913dde0 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset2.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset.single.pass.cpp @@ -16,30 +16,10 @@ #include <memory> #include <cassert> -struct A -{ - static int count; - A() {++count;} - A(const A&) {++count;} - virtual ~A() {--count;} -}; +#include "unique_ptr_test_helper.h" -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() -{ - { +int main() { + { std::unique_ptr<A> p(new A); assert(A::count == 1); assert(B::count == 0); @@ -48,10 +28,10 @@ int main() p.reset(new B); assert(A::count == 1); assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); - { + } + assert(A::count == 0); + assert(B::count == 0); + { std::unique_ptr<A> p(new B); assert(A::count == 1); assert(B::count == 1); @@ -60,7 +40,7 @@ int main() p.reset(new B); assert(A::count == 1); assert(B::count == 1); - } - assert(A::count == 0); - assert(B::count == 0); + } + assert(A::count == 0); + assert(B::count == 0); } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset_self.pass.cpp index 58b05efa25f61..f838661c53f0e 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.modifiers/reset_self.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/reset_self.pass.cpp @@ -15,15 +15,11 @@ #include <memory> -struct A -{ - std::unique_ptr<A> ptr_; +struct A { + std::unique_ptr<A> ptr_; - A() : ptr_(this) {} - void reset() {ptr_.reset();} + A() : ptr_(this) {} + void reset() { ptr_.reset(); } }; -int main() -{ - (new A)->reset(); -} +int main() { (new A)->reset(); } diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp new file mode 100644 index 0000000000000..de18865c50aec --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.modifiers/swap.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test swap + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +struct TT { + int state_; + static int count; + TT() : state_(-1) { ++count; } + explicit TT(int i) : state_(i) { ++count; } + TT(const TT& a) : state_(a.state_) { ++count; } + TT& operator=(const TT& a) { + state_ = a.state_; + return *this; + } + ~TT() { --count; } + + friend bool operator==(const TT& x, const TT& y) { + return x.state_ == y.state_; + } +}; + +int TT::count = 0; + +template <class T> +typename std::remove_all_extents<T>::type* newValueInit(int size, + int new_value) { + typedef typename std::remove_all_extents<T>::type VT; + VT* p = newValue<T>(size); + for (int i = 0; i < size; ++i) + (p + i)->state_ = new_value; + return p; +} + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, TT[], TT>::type VT; + const int expect_alive = IsArray ? 5 : 1; +#if TEST_STD_VER >= 11 + { + using U = std::unique_ptr<VT, Deleter<VT> >; + U u; ((void)u); + ASSERT_NOEXCEPT(u.swap(u)); + } +#endif + { + TT* p1 = newValueInit<VT>(expect_alive, 1); + std::unique_ptr<VT, Deleter<VT> > s1(p1, Deleter<VT>(1)); + TT* p2 = newValueInit<VT>(expect_alive, 2); + std::unique_ptr<VT, Deleter<VT> > s2(p2, Deleter<VT>(2)); + assert(s1.get() == p1); + assert(*s1.get() == TT(1)); + assert(s1.get_deleter().state() == 1); + assert(s2.get() == p2); + assert(*s2.get() == TT(2)); + assert(s2.get_deleter().state() == 2); + s1.swap(s2); + assert(s1.get() == p2); + assert(*s1.get() == TT(2)); + assert(s1.get_deleter().state() == 2); + assert(s2.get() == p1); + assert(*s2.get() == TT(1)); + assert(s2.get_deleter().state() == 1); + assert(TT::count == (expect_alive * 2)); + } + assert(TT::count == 0); +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.runtime.fail.cpp index d5c7445b0d86f..b05fb71cdc677 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/explicit_bool.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.runtime.fail.cpp @@ -16,24 +16,9 @@ #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); - } +int main() { + std::unique_ptr<int[]> p(new int(3)); + const std::unique_ptr<int[]>& cp = p; + (void)(*p); // expected-error {{indirection requires pointer operand ('std::unique_ptr<int []>' invalid)}} + (void)(*cp); // expected-error {{indirection requires pointer operand ('const std::unique_ptr<int []>' invalid)}} } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp index 9d0cfcaaf353d..b2d3da48daee5 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/dereference.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/dereference.single.pass.cpp @@ -16,8 +16,7 @@ #include <memory> #include <cassert> -int main() -{ - std::unique_ptr<int> p(new int(3)); - assert(*p == 3); +int main() { + std::unique_ptr<int> p(new int(3)); + assert(*p == 3); } diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp new file mode 100644 index 0000000000000..9a6d6c65fa810 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/explicit_bool.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test op*() + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template <class UPtr> +void doTest(UPtr& p, bool ExpectTrue) { + if (p) + assert(ExpectTrue); + else + assert(!ExpectTrue); + + if (!p) + assert(!ExpectTrue); + else + assert(ExpectTrue); +} + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, int[], int>::type VT; + typedef std::unique_ptr<VT> U; + { + static_assert((std::is_constructible<bool, U>::value), ""); + static_assert((std::is_constructible<bool, U const&>::value), ""); + } +#if TEST_STD_VER >= 11 + { + static_assert(!std::is_convertible<U, bool>::value, ""); + static_assert(!std::is_convertible<U const&, bool>::value, ""); + } +#endif + { + U p(newValue<VT>(1)); + U const& cp = p; + doTest(p, true); + doTest(cp, true); + } + { + U p; + const U& cp = p; + doTest(p, false); + doTest(cp, false); + } +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp new file mode 100644 index 0000000000000..518e31cf94872 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test get + +#include <memory> +#include <cassert> + +#include "test_macros.h" +#include "unique_ptr_test_helper.h" + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, int[], int>::type VT; + typedef const VT CVT; + { + typedef std::unique_ptr<VT> U; + int* p = newValue<VT>(1); + U s(p); + U const& sc = s; + ASSERT_SAME_TYPE(decltype(s.get()), int*); + ASSERT_SAME_TYPE(decltype(sc.get()), int*); + assert(s.get() == p); + assert(sc.get() == s.get()); + } + { + typedef std::unique_ptr<CVT> U; + const int* p = newValue<VT>(1); + U s(p); + U const& sc = s; + ASSERT_SAME_TYPE(decltype(s.get()), const int*); + ASSERT_SAME_TYPE(decltype(sc.get()), const int*); + assert(s.get() == p); + assert(sc.get() == s.get()); + } +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); +} diff --git a/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get_deleter.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get_deleter.pass.cpp new file mode 100644 index 0000000000000..6a00d14a2cae4 --- /dev/null +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/get_deleter.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <memory> + +// unique_ptr + +// test get_deleter() + +#include <memory> +#include <cassert> +#include "test_macros.h" + +struct Deleter { + Deleter() {} + + void operator()(void*) const {} + + int test() { return 5; } + int test() const { return 6; } +}; + +template <bool IsArray> +void test_basic() { + typedef typename std::conditional<IsArray, int[], int>::type VT; + { + std::unique_ptr<int, Deleter> p; + assert(p.get_deleter().test() == 5); + } + { + const std::unique_ptr<VT, Deleter> p; + assert(p.get_deleter().test() == 6); + } + { + typedef std::unique_ptr<VT, const Deleter&> UPtr; + const Deleter d; + UPtr p(nullptr, d); + const UPtr& cp = p; + ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&); + ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&); + assert(p.get_deleter().test() == 6); + assert(cp.get_deleter().test() == 6); + } + { + typedef std::unique_ptr<VT, Deleter&> UPtr; + Deleter d; + UPtr p(nullptr, d); + const UPtr& cp = p; + ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&); + ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&); + assert(p.get_deleter().test() == 5); + assert(cp.get_deleter().test() == 5); + } +} + +int main() { + test_basic</*IsArray*/ false>(); + test_basic<true>(); +} diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.runtime.fail.cpp index 1c90ba76af393..d66af054ce649 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/op_arrow.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.runtime.fail.cpp @@ -16,15 +16,17 @@ #include <memory> #include <cassert> -struct A -{ - int i_; - - A() : i_(7) {} +struct V { + int member; }; -int main() -{ - std::unique_ptr<A[]> p(new A); - assert(p->i_ == 7); +int main() { + std::unique_ptr<V[]> p; + std::unique_ptr<V[]> const& cp = p; + + p->member; // expected-error {{member reference type 'std::unique_ptr<V []>' is not a pointer}} + // expected-error@-1 {{no member named 'member'}} + + cp->member; // expected-error {{member reference type 'const std::unique_ptr<V []>' is not a pointer}} + // expected-error@-1 {{no member named 'member'}} } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.single.pass.cpp index 47de8f66ed2e4..8bed9dda2ead3 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/op_arrow.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_arrow.single.pass.cpp @@ -16,15 +16,13 @@ #include <memory> #include <cassert> -struct A -{ - int i_; +struct A { + int i_; - A() : i_(7) {} + A() : i_(7) {} }; -int main() -{ - std::unique_ptr<A> p(new A); - assert(p->i_ == 7); +int main() { + std::unique_ptr<A> p(new A); + assert(p->i_ == 7); } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp index 21e829cbc4442..b47c35afb4f58 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.observers/index.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.runtime.pass.cpp @@ -16,32 +16,33 @@ #include <memory> #include <cassert> -class A -{ - int state_; - static int next_; +class A { + int state_; + static int next_; + public: - A() : state_(++next_) {} - int get() const {return state_;} + A() : state_(++next_) {} + int get() const { return state_; } - friend bool operator==(const A& x, int y) - {return x.state_ == y;} + friend bool operator==(const A& x, int y) { return x.state_ == y; } - A& operator=(int i) {state_ = i; return *this;} + 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); +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/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.single.fail.cpp index 2ae0659adc260..529749da67e99 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.observers/get.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.class/unique.ptr.observers/op_subscript.single.fail.cpp @@ -11,14 +11,14 @@ // unique_ptr -// test get +// test op[](size_t) #include <memory> #include <cassert> -int main() -{ - int* p = new int[3]; - std::unique_ptr<int[]> s(p); - assert(s.get() == p); +int main() { + std::unique_ptr<int> p(new int[3]); + std::unique_ptr<int> const& cp = p; + p[0]; // expected-error {{type 'std::unique_ptr<int>' does not provide a subscript operator}} + cp[1]; // expected-error {{type 'const std::unique_ptr<int>' does not provide a subscript operator}} } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp index 30b4ecb94e18f..30b4ecb94e18f 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp index 00987919413bb..00987919413bb 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array1.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp index cc94e9ab3aaab..cc94e9ab3aaab 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array2.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp index cfdc2e1d886b0..cfdc2e1d886b0 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array3.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp index 07aa659bd9b02..07aa659bd9b02 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.array4.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp index ace2e4fc71370..ace2e4fc71370 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.create/make_unique.single.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp index b58f5c55b643a..b58f5c55b643a 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/nothing_to_do.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp index 9bf794caeda27..9bf794caeda27 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/convert_ctor.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp index f686e9f01f113..f686e9f01f113 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/default.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp index 255e5cd39c69b..255e5cd39c69b 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/incomplete.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp index 5d1cf1ff4981e..5d1cf1ff4981e 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt/void.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp index 41209d977b71e..41209d977b71e 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp index 2949d6310c598..2949d6310c598 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/convert_ctor.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp index 7a409766412fd..7a409766412fd 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/default.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp index 528b10e9085d6..528b10e9085d6 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.dflt1/incomplete.fail.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp index b58f5c55b643a..b58f5c55b643a 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.dltr/unique.ptr.dltr.general/nothing_to_do.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp index 22ae217a61d64..22ae217a61d64 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/cmp_nullptr.pass.cpp diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/eq.pass.cpp index 37886548e7212..88a1e04ba4ec5 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.special/eq.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/eq.pass.cpp @@ -22,7 +22,7 @@ #include <memory> #include <cassert> -#include "../deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/rel.pass.cpp index 80653cf707c3e..94ae89ba92b39 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.special/rel.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/rel.pass.cpp @@ -30,7 +30,7 @@ #include <memory> #include <cassert> -#include "../deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/swap.pass.cpp index c525137d48417..7ac0ba490e970 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.special/swap.pass.cpp +++ b/test/std/utilities/smartptr/unique.ptr/unique.ptr.special/swap.pass.cpp @@ -17,7 +17,7 @@ #include <cassert> #include "test_macros.h" -#include "../deleter.h" +#include "deleter_types.h" struct A { diff --git a/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp b/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp index bc65078911b2c..8eab082cf676e 100644 --- a/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.hash/bitset.pass.cpp @@ -30,6 +30,8 @@ test() typedef std::hash<T> H; static_assert((std::is_same<typename H::argument_type, T>::value), "" ); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + ASSERT_NOEXCEPT(H()(T())); + H h; T bs(static_cast<unsigned long long>(N)); const std::size_t result = h(bs); diff --git a/test/std/utilities/template.bitset/bitset.hash/enabled_hash.pass.cpp b/test/std/utilities/template.bitset/bitset.hash/enabled_hash.pass.cpp new file mode 100644 index 0000000000000..1d8bff41ae531 --- /dev/null +++ b/test/std/utilities/template.bitset/bitset.hash/enabled_hash.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <bitset> + +// Test that <bitset> provides all of the arithmetic, enum, and pointer +// hash specializations. + +#include <bitset> + +#include "poisoned_hash_helper.hpp" + +int main() { + test_library_hash_specializations_available(); + { + test_hash_enabled_for_type<std::bitset<0> >(); + test_hash_enabled_for_type<std::bitset<1> >(); + test_hash_enabled_for_type<std::bitset<1024> >(); + test_hash_enabled_for_type<std::bitset<100000> >(); + } +} diff --git a/test/std/utilities/template.bitset/bitset.members/all.pass.cpp b/test/std/utilities/template.bitset/bitset.members/all.pass.cpp index 5387b733918fe..de1cddb5b1ae8 100644 --- a/test/std/utilities/template.bitset/bitset.members/all.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/all.pass.cpp @@ -10,6 +10,7 @@ // test bool all() const; #include <bitset> +#include <type_traits> #include <cassert> template <std::size_t N> @@ -20,7 +21,8 @@ void test_all() assert(v.all() == (N == 0)); v.set(); assert(v.all() == true); - if (N > 1) + const bool greater_than_1 = std::integral_constant<bool, (N > 1)>::value; // avoid compiler warnings + if (greater_than_1) { v[N/2] = false; assert(v.all() == false); diff --git a/test/std/utilities/template.bitset/bitset.members/any.pass.cpp b/test/std/utilities/template.bitset/bitset.members/any.pass.cpp index aa6384a49df1d..7ee83dd074822 100644 --- a/test/std/utilities/template.bitset/bitset.members/any.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/any.pass.cpp @@ -10,6 +10,7 @@ // test bool any() const; #include <bitset> +#include <type_traits> #include <cassert> template <std::size_t N> @@ -20,7 +21,8 @@ void test_any() assert(v.any() == false); v.set(); assert(v.any() == (N != 0)); - if (N > 1) + const bool greater_than_1 = std::integral_constant<bool, (N > 1)>::value; // avoid compiler warnings + if (greater_than_1) { v[N/2] = false; assert(v.any() == true); diff --git a/test/std/utilities/template.bitset/bitset.members/index.pass.cpp b/test/std/utilities/template.bitset/bitset.members/index.pass.cpp index 02e58a7890c54..f352475fc1996 100644 --- a/test/std/utilities/template.bitset/bitset.members/index.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/index.pass.cpp @@ -10,6 +10,7 @@ // test bitset<N>::reference operator[](size_t pos); #include <bitset> +#include <type_traits> #include <cstdlib> #include <cassert> @@ -31,7 +32,8 @@ template <std::size_t N> void test_index_const() { std::bitset<N> v1 = make_bitset<N>(); - if (N > 0) + const bool greater_than_0 = std::integral_constant<bool, (N > 0)>::value; // avoid compiler warnings + if (greater_than_0) { assert(v1[N/2] == v1.test(N/2)); typename std::bitset<N>::reference r = v1[N/2]; diff --git a/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp b/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp index 870a504c2d751..fbde54859f19e 100644 --- a/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp @@ -10,6 +10,7 @@ // test constexpr bool operator[](size_t pos) const; #include <bitset> +#include <type_traits> #include <cstdlib> #include <cassert> @@ -31,7 +32,8 @@ template <std::size_t N> void test_index_const() { const std::bitset<N> v1 = make_bitset<N>(); - if (N > 0) + const bool greater_than_0 = std::integral_constant<bool, (N > 0)>::value; // avoid compiler warnings + if (greater_than_0) { assert(v1[N/2] == v1.test(N/2)); } diff --git a/test/std/utilities/template.bitset/bitset.members/none.pass.cpp b/test/std/utilities/template.bitset/bitset.members/none.pass.cpp index b65c636f3c560..1358eaa62d593 100644 --- a/test/std/utilities/template.bitset/bitset.members/none.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/none.pass.cpp @@ -10,6 +10,7 @@ // test bool none() const; #include <bitset> +#include <type_traits> #include <cassert> template <std::size_t N> @@ -20,7 +21,8 @@ void test_none() assert(v.none() == true); v.set(); assert(v.none() == (N == 0)); - if (N > 1) + const bool greater_than_1 = std::integral_constant<bool, (N > 1)>::value; // avoid compiler warnings + if (greater_than_1) { v[N/2] = false; assert(v.none() == false); diff --git a/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp b/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp index 24761c628c03e..5b7e10d677ee3 100644 --- a/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp @@ -13,6 +13,7 @@ // bool operator!=(const bitset<N>& rhs) const; #include <bitset> +#include <type_traits> #include <cstdlib> #include <cassert> @@ -36,7 +37,8 @@ void test_equality() const std::bitset<N> v1 = make_bitset<N>(); std::bitset<N> v2 = v1; assert(v1 == v2); - if (N > 0) + const bool greater_than_0 = std::integral_constant<bool, (N > 0)>::value; // avoid compiler warnings + if (greater_than_0) { v2[N/2].flip(); assert(v1 != v2); diff --git a/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp index 27d8480d10cfe..a2c9df6b4a22e 100644 --- a/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/to_ullong.pass.cpp @@ -11,6 +11,7 @@ #include <bitset> #include <algorithm> +#include <type_traits> #include <climits> #include <cassert> @@ -18,8 +19,9 @@ template <std::size_t N> void test_to_ullong() { const std::size_t M = sizeof(unsigned long long) * CHAR_BIT < N ? sizeof(unsigned long long) * CHAR_BIT : N; - const std::size_t X = M == 0 ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M; - const unsigned long long max = M == 0 ? 0 : (unsigned long long)(-1) >> X; + const bool is_M_zero = std::integral_constant<bool, M == 0>::value; // avoid compiler warnings + const std::size_t X = is_M_zero ? sizeof(unsigned long long) * CHAR_BIT - 1 : sizeof(unsigned long long) * CHAR_BIT - M; + const unsigned long long max = is_M_zero ? 0 : (unsigned long long)(-1) >> X; unsigned long long tests[] = {0, std::min<unsigned long long>(1, max), std::min<unsigned long long>(2, max), diff --git a/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp b/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp index 3ad1abade9f48..7cabd06e5f322 100644 --- a/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp +++ b/test/std/utilities/template.bitset/bitset.members/to_ulong.pass.cpp @@ -11,6 +11,7 @@ #include <bitset> #include <algorithm> +#include <type_traits> #include <limits> #include <climits> #include <cassert> @@ -19,8 +20,9 @@ template <std::size_t N> void test_to_ulong() { const std::size_t M = sizeof(unsigned long) * CHAR_BIT < N ? sizeof(unsigned long) * CHAR_BIT : N; - const std::size_t X = M == 0 ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M; - const std::size_t max = M == 0 ? 0 : std::size_t(std::numeric_limits<unsigned long>::max()) >> X; + const bool is_M_zero = std::integral_constant<bool, M == 0>::value; // avoid compiler warnings + const std::size_t X = is_M_zero ? sizeof(unsigned long) * CHAR_BIT - 1 : sizeof(unsigned long) * CHAR_BIT - M; + const std::size_t max = is_M_zero ? 0 : std::size_t(std::numeric_limits<unsigned long>::max()) >> X; std::size_t tests[] = {0, std::min<std::size_t>(1, max), std::min<std::size_t>(2, max), diff --git a/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp index b6b3aeea94f85..bf2a2e5891379 100644 --- a/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp +++ b/test/std/utilities/time/time.clock/time.clock.hires/consistency.pass.cpp @@ -9,8 +9,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // Due to C++17 inline variables ASAN flags this test as containing an ODR // violation because Clock::is_steady is defined in both the dylib and this TU. diff --git a/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp index 6302ce6efb34b..b836c0dc00e6d 100644 --- a/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp +++ b/test/std/utilities/time/time.clock/time.clock.steady/consistency.pass.cpp @@ -9,8 +9,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // UNSUPPORTED: libcpp-has-no-monotonic-clock // Due to C++17 inline variables ASAN flags this test as containing an ODR diff --git a/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp b/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp index cfbe9bd570329..a4058e5ab97b2 100644 --- a/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp +++ b/test/std/utilities/time/time.clock/time.clock.system/consistency.pass.cpp @@ -9,8 +9,8 @@ // // This test uses new symbols that were not defined in the libc++ shipped on // darwin11 and darwin12: -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin11 -// XFAIL: with_system_cxx_lib=x86_64-apple-darwin12 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.7 +// XFAIL: with_system_cxx_lib=x86_64-apple-macosx10.8 // Due to C++17 inline variables ASAN flags this test as containing an ODR // violation because Clock::is_steady is defined in both the dylib and this TU. diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp index c0f10147ee893..b85f039526a4b 100644 --- a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_+.pass.cpp @@ -11,11 +11,13 @@ // duration -// duration operator+() const; +// constexpr common_type_t<duration> operator+() const; #include <chrono> #include <cassert> +#include <test_macros.h> + int main() { { @@ -23,11 +25,22 @@ int main() std::chrono::minutes m2 = +m; assert(m.count() == m2.count()); } -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#if TEST_STD_VER >= 11 { constexpr std::chrono::minutes m(3); constexpr std::chrono::minutes m2 = +m; static_assert(m.count() == m2.count(), ""); } #endif + +// P0548 + { + typedef std::chrono::duration<int, std::ratio<10,10> > D10; + typedef std::chrono::duration<int, std::ratio< 1, 1> > D1; + D10 zero(0); + D10 one(1); + static_assert( (std::is_same< decltype(+one), decltype(zero-one) >::value), ""); + static_assert( (std::is_same< decltype(zero+one), D1>::value), ""); + static_assert( (std::is_same< decltype(+one), D1>::value), ""); + } } diff --git a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp index 00da6f69ca530..347cc1980e819 100644 --- a/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp +++ b/test/std/utilities/time/time.duration/time.duration.arithmetic/op_-.pass.cpp @@ -11,11 +11,13 @@ // duration -// duration operator-() const; +// constexpr common_type_t<duration> operator-() const; #include <chrono> #include <cassert> +#include <test_macros.h> + int main() { { @@ -23,11 +25,23 @@ int main() std::chrono::minutes m2 = -m; assert(m2.count() == -m.count()); } -#ifndef _LIBCPP_HAS_NO_CONSTEXPR +#if TEST_STD_VER >= 11 { constexpr std::chrono::minutes m(3); constexpr std::chrono::minutes m2 = -m; static_assert(m2.count() == -m.count(), ""); } #endif + +// P0548 + { + typedef std::chrono::duration<int, std::ratio<10,10> > D10; + typedef std::chrono::duration<int, std::ratio< 1, 1> > D1; + D10 zero(0); + D10 one(1); + static_assert( (std::is_same< decltype(-one), decltype(zero-one) >::value), ""); + static_assert( (std::is_same< decltype(zero-one), D1>::value), ""); + static_assert( (std::is_same< decltype(-one), D1>::value), ""); + static_assert( (std::is_same< decltype(+one), D1>::value), ""); + } } diff --git a/test/std/utilities/tuple/tuple.general/ignore.pass.cpp b/test/std/utilities/tuple/tuple.general/ignore.pass.cpp new file mode 100644 index 0000000000000..8dae3a5dcb0e9 --- /dev/null +++ b/test/std/utilities/tuple/tuple.general/ignore.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <tuple> + +// constexpr unspecified ignore; + +// UNSUPPORTED: c++98, c++03 + +#include <tuple> +#include <cassert> + +#include "test_macros.h" + +constexpr bool test_ignore_constexpr() +{ +#if TEST_STD_VER > 11 + { // Test that std::ignore provides constexpr converting assignment. + auto& res = (std::ignore = 42); + assert(&res == &std::ignore); + } + { // Test that std::ignore provides constexpr copy/move constructors + auto copy = std::ignore; + auto moved = std::move(copy); + ((void)moved); + } + { // Test that std::ignore provides constexpr copy/move assignment + auto copy = std::ignore; + copy = std::ignore; + auto moved = std::ignore; + moved = std::move(copy); + } +#endif + return true; +} + +int main() { + { + constexpr auto& ignore_v = std::ignore; + ((void)ignore_v); + } + { + static_assert(test_ignore_constexpr(), ""); + } +#if defined(_LIBCPP_VERSION) + { + static_assert(std::is_trivial<decltype(std::ignore)>::value, ""); + } +#endif +} diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp index eee1dd88253c9..bd91ce61b4ec8 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp @@ -66,7 +66,7 @@ constexpr bool do_constexpr_test(Tuple&& tup) { return std::make_from_tuple<Tp>(std::forward<Tuple>(tup)).args == tup; } -// Needed by do_forwarding_test() since it compare pairs of different types. +// Needed by do_forwarding_test() since it compares pairs of different types. template <class T1, class T2, class U1, class U2> inline bool operator==(const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs) { return lhs.first == rhs.first && lhs.second == rhs.second; diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR22806_constrain_tuple_like_ctor.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR22806_constrain_tuple_like_ctor.pass.cpp index 4ddfb463385c7..0d3b7ff24edb1 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR22806_constrain_tuple_like_ctor.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR22806_constrain_tuple_like_ctor.pass.cpp @@ -89,7 +89,7 @@ int main() // when both #1 and #2 participate in partial ordering #2 will always // be chosen over #1. // See PR22806 and LWG issue #2549 for more information. - // (https://llvm.org/bugs/show_bug.cgi?id=22806) + // (https://bugs.llvm.org/show_bug.cgi?id=22806) using T = std::tuple<int>; std::allocator<int> A; { // rvalue reference @@ -144,8 +144,8 @@ int main() assert(&std::get<0>(t2) == &t1); } // Test constructing a 1-tuple of the form tuple<UDT> from another 1-tuple - // 'tuple<T>' where UDT *can* be constructed from 'tuple<T>' In this case - // the 'tuple(UTypes...)' ctor should be choosen and 'UDT' constructed frow + // 'tuple<T>' where UDT *can* be constructed from 'tuple<T>'. In this case + // the 'tuple(UTypes...)' ctor should be chosen and 'UDT' constructed from // 'tuple<T>'. { using VT = ConstructibleFromTupleAndInt; diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp index 4da5fc7f83979..b262f3cacecf7 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/alloc.pass.cpp @@ -18,7 +18,7 @@ // NOTE: this constructor does not currently support tags derived from // allocator_arg_t because libc++ has to deduce the parameter as a template -// argument. See PR27684 (https://llvm.org/bugs/show_bug.cgi?id=27684) +// argument. See PR27684 (https://bugs.llvm.org/show_bug.cgi?id=27684) #include <tuple> #include <cassert> @@ -96,7 +96,7 @@ int main() } { // Test that the uses-allocator default constructor does not evaluate - // it's SFINAE when it otherwise shouldn't be selected. Do this by + // its SFINAE when it otherwise shouldn't be selected. Do this by // using 'NonDefaultConstructible' which will cause a compile error // if std::is_default_constructible is evaluated on it. using T = NonDefaultConstructible<>; diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp index d282c9c68a42d..eeaa8a24ee68c 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/default.pass.cpp @@ -100,8 +100,8 @@ int main() assert(std::get<1>(t) == nullptr); } { - // Check that the SFINAE on the default constructor is not evaluted when - // it isn't needed. If the default constructor is evaluted then this test + // Check that the SFINAE on the default constructor is not evaluated when + // it isn't needed. If the default constructor is evaluated then this test // should fail to compile. IllFormedDefault v(0); std::tuple<IllFormedDefault> t(v); diff --git a/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp index c4c3c242d8f82..5dc98afe66106 100644 --- a/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp +++ b/test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp @@ -22,6 +22,24 @@ #include "test_macros.h" +#if TEST_STD_VER > 11 +constexpr bool test_tie_constexpr() { + { + int i = 42; + double f = 1.1; + using ExpectT = std::tuple<int&, decltype(std::ignore)&, double&>; + auto res = std::tie(i, std::ignore, f); + static_assert(std::is_same<ExpectT, decltype(res)>::value, ""); + assert(&std::get<0>(res) == &i); + assert(&std::get<1>(res) == &std::ignore); + assert(&std::get<2>(res) == &f); + // FIXME: If/when tuple gets constexpr assignment + //res = std::make_tuple(101, nullptr, -1.0); + } + return true; +} +#endif + int main() { { @@ -39,5 +57,8 @@ int main() static_assert ( std::get<0>(t) == 42, "" ); static_assert ( std::get<1>(t) == 1.1, "" ); } + { + static_assert(test_tie_constexpr(), ""); + } #endif } diff --git a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp b/test/std/utilities/type.index/type.index.hash/enabled_hash.pass.cpp index 74d24fd488b65..26bada38fdd55 100644 --- a/test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/default03.fail.cpp +++ b/test/std/utilities/type.index/type.index.hash/enabled_hash.pass.cpp @@ -7,17 +7,17 @@ // //===----------------------------------------------------------------------===// -// <memory> +// UNSUPPORTED: c++98, c++03 -// unique_ptr +// <typeindex> -// Test unique_ptr default ctor +// Test that <typeindex> provides all of the arithmetic, enum, and pointer +// hash specializations. -// default unique_ptr ctor should require non-pointer Deleter +#include <typeindex> -#include <memory> +#include "poisoned_hash_helper.hpp" -int main() -{ - std::unique_ptr<int[], void (*)(void*)> p; +int main() { + test_library_hash_specializations_available(); } diff --git a/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp b/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp index 6d353f1d30574..9ab58ea6c3aa6 100644 --- a/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp +++ b/test/std/utilities/type.index/type.index.synopsis/hash_type_index.pass.cpp @@ -18,9 +18,21 @@ #include <typeindex> #include <type_traits> +#include "test_macros.h" +#if TEST_STD_VER >= 11 +#include "poisoned_hash_helper.hpp" +#endif + int main() { + { typedef std::hash<std::type_index> H; static_assert((std::is_same<typename H::argument_type, std::type_index>::value), "" ); static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" ); + } +#if TEST_STD_VER >= 11 + { + test_hash_enabled_for_type<std::type_index>(std::type_index(typeid(int))); + } +#endif } diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp index 2623b800fff7b..cf1afff90cdae 100644 --- a/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// -// REQUIRES-ANY: c++98, c++03 +// REQUIRES: c++98 || c++03 // <utility> diff --git a/test/std/utilities/utility/pairs/pairs.pair/default-sfinae.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/default-sfinae.pass.cpp index 8f9fc669251a5..d5e1e232f86f6 100644 --- a/test/std/utilities/utility/pairs/pairs.pair/default-sfinae.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.pair/default-sfinae.pass.cpp @@ -32,7 +32,7 @@ struct DeletedDefault { // A class with a deleted default constructor. Used to test the SFINAE - // on std::pairs default constructor. + // on std::pair's default constructor. constexpr explicit DeletedDefault(int x) : value(x) {} constexpr DeletedDefault() = delete; int value; diff --git a/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp index ace00a16f21e0..af91abe74e1ee 100644 --- a/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp +++ b/test/std/utilities/utility/pairs/pairs.pair/default.pass.cpp @@ -15,7 +15,7 @@ // This test doesn't pass due to a constexpr bug in GCC 4.9 that fails // to initialize any type without a user provided constructor in a constant -// expression (ie float). +// expression (e.g. float). // XFAIL: gcc-4.9 // NOTE: The SFINAE on the default constructor is tested in @@ -49,7 +49,7 @@ int main() using P = std::pair<int, NoDefault>; static_assert(!std::is_default_constructible<P>::value, ""); using P2 = std::pair<NoDefault, int>; - static_assert(!std::is_default_constructible<P>::value, ""); + static_assert(!std::is_default_constructible<P2>::value, ""); } #endif } diff --git a/test/std/utilities/variant/variant.get/get_index.pass.cpp b/test/std/utilities/variant/variant.get/get_index.pass.cpp index 72d17b0ed971a..bc7a566040eb1 100644 --- a/test/std/utilities/variant/variant.get/get_index.pass.cpp +++ b/test/std/utilities/variant/variant.get/get_index.pass.cpp @@ -36,7 +36,7 @@ void test_const_lvalue_get() { { using V = std::variant<int, const long>; constexpr V v(42); -#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481 +#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481 ASSERT_NOEXCEPT(std::get<0>(v)); #endif ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &); @@ -52,7 +52,7 @@ void test_const_lvalue_get() { { using V = std::variant<int, const long>; constexpr V v(42l); -#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481 +#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481 ASSERT_NOEXCEPT(std::get<1>(v)); #endif ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &); diff --git a/test/std/utilities/variant/variant.get/get_type.pass.cpp b/test/std/utilities/variant/variant.get/get_type.pass.cpp index fc355378a21a3..013a081f5c770 100644 --- a/test/std/utilities/variant/variant.get/get_type.pass.cpp +++ b/test/std/utilities/variant/variant.get/get_type.pass.cpp @@ -30,7 +30,7 @@ void test_const_lvalue_get() { { using V = std::variant<int, const long>; constexpr V v(42); -#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481 +#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481 ASSERT_NOEXCEPT(std::get<int>(v)); #endif ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &); @@ -46,7 +46,7 @@ void test_const_lvalue_get() { { using V = std::variant<int, const long>; constexpr V v(42l); -#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481 +#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481 ASSERT_NOEXCEPT(std::get<const long>(v)); #endif ASSERT_SAME_TYPE(decltype(std::get<const long>(v)), const long &); diff --git a/test/std/utilities/variant/variant.hash/enabled_hash.pass.cpp b/test/std/utilities/variant/variant.hash/enabled_hash.pass.cpp new file mode 100644 index 0000000000000..826dcbae6b9f4 --- /dev/null +++ b/test/std/utilities/variant/variant.hash/enabled_hash.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03, c++11, c++14 + +// <variant> + +// Test that <variant> provides all of the arithmetic, enum, and pointer +// hash specializations. + +#include <variant> + +#include "poisoned_hash_helper.hpp" + +int main() { + test_library_hash_specializations_available(); +} diff --git a/test/std/utilities/variant/variant.hash/hash.pass.cpp b/test/std/utilities/variant/variant.hash/hash.pass.cpp index d807a7c7e2eaf..2ad2184f4db11 100644 --- a/test/std/utilities/variant/variant.hash/hash.pass.cpp +++ b/test/std/utilities/variant/variant.hash/hash.pass.cpp @@ -21,6 +21,7 @@ #include "test_macros.h" #include "variant_test_helpers.hpp" +#include "poisoned_hash_helper.hpp" #ifndef TEST_HAS_NO_EXCEPTIONS namespace std { @@ -101,8 +102,12 @@ void test_hash_monostate() { assert(h(m1) == h(m2)); { ASSERT_SAME_TYPE(decltype(h(m1)), std::size_t); + ASSERT_NOEXCEPT(h(m1)); static_assert(std::is_copy_constructible<H>::value, ""); } + { + test_hash_enabled_for_type<std::monostate>(); + } } void test_hash_variant_duplicate_elements() { @@ -117,8 +122,38 @@ void test_hash_variant_duplicate_elements() { LIBCPP_ASSERT(h(v1) != h(v2)); } +struct A {}; +struct B {}; + +namespace std { + +template <> +struct hash<B> { + size_t operator()(B const&) const { + return 0; + } +}; + +} + +void test_hash_variant_enabled() { + { + test_hash_enabled_for_type<std::variant<int> >(); + test_hash_enabled_for_type<std::variant<int*, long, double, const int> >(); + } + { + test_hash_disabled_for_type<std::variant<int, A>>(); + test_hash_disabled_for_type<std::variant<const A, void*>>(); + } + { + test_hash_enabled_for_type<std::variant<int, B>>(); + test_hash_enabled_for_type<std::variant<const B, int>>(); + } +} + int main() { test_hash_variant(); test_hash_variant_duplicate_elements(); test_hash_monostate(); + test_hash_variant_enabled(); } diff --git a/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp b/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp index 8f694cfd5eda6..0d0b978e3959d 100644 --- a/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_args.pass.cpp @@ -14,7 +14,8 @@ // template <class ...Types> class variant; -// template <size_t I, class ...Args> void emplace(Args&&... args); +// template <size_t I, class ...Args> +// variant_alternative_t<I, variant<Types...>>& emplace(Args&&... args); #include <cassert> #include <string> @@ -85,10 +86,14 @@ void test_basic() { { using V = std::variant<int>; V v(42); - v.emplace<0>(); + auto& ref1 = v.emplace<0>(); + static_assert(std::is_same_v<int&, decltype(ref1)>, ""); assert(std::get<0>(v) == 0); - v.emplace<0>(42); + assert(&ref1 == &std::get<0>(v)); + auto& ref2 = v.emplace<0>(42); + static_assert(std::is_same_v<int&, decltype(ref2)>, ""); assert(std::get<0>(v) == 42); + assert(&ref2 == &std::get<0>(v)); } { using V = @@ -96,13 +101,19 @@ void test_basic() { const int x = 100; V v(std::in_place_index<0>, -1); // default emplace a value - v.emplace<1>(); + auto& ref1 = v.emplace<1>(); + static_assert(std::is_same_v<long&, decltype(ref1)>, ""); assert(std::get<1>(v) == 0); - v.emplace<2>(&x); + assert(&ref1 == &std::get<1>(v)); + auto& ref2 = v.emplace<2>(&x); + static_assert(std::is_same_v<const void*&, decltype(ref2)>, ""); assert(std::get<2>(v) == &x); + assert(&ref2 == &std::get<2>(v)); // emplace with multiple args - v.emplace<4>(3, 'a'); + auto& ref3 = v.emplace<4>(3, 'a'); + static_assert(std::is_same_v<std::string&, decltype(ref3)>, ""); assert(std::get<4>(v) == "aaa"); + assert(&ref3 == &std::get<4>(v)); } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { @@ -113,20 +124,30 @@ void test_basic() { int z = 43; V v(std::in_place_index<0>, -1); // default emplace a value - v.emplace<1>(); + auto& ref1 = v.emplace<1>(); + static_assert(std::is_same_v<long&, decltype(ref1)>, ""); assert(std::get<1>(v) == 0); + assert(&ref1 == &std::get<1>(v)); // emplace a reference - v.emplace<2>(x); + auto& ref2 = v.emplace<2>(x); + static_assert(std::is_same_v<&, decltype(ref)>, ""); assert(&std::get<2>(v) == &x); + assert(&ref2 == &std::get<2>(v)); // emplace an rvalue reference - v.emplace<3>(std::move(y)); + auto& ref3 = v.emplace<3>(std::move(y)); + static_assert(std::is_same_v<&, decltype(ref)>, ""); assert(&std::get<3>(v) == &y); + assert(&ref3 == &std::get<3>(v)); // re-emplace a new reference over the active member - v.emplace<3>(std::move(z)); + auto& ref4 = v.emplace<3>(std::move(z)); + static_assert(std::is_same_v<&, decltype(ref)>, ""); assert(&std::get<3>(v) == &z); + assert(&ref4 == &std::get<3>(v)); // emplace with multiple args - v.emplace<5>(3, 'a'); + auto& ref5 = v.emplace<5>(3, 'a'); + static_assert(std::is_same_v<std::string&, decltype(ref5)>, ""); assert(std::get<5>(v) == "aaa"); + assert(&ref5 == &std::get<5>(v)); } #endif } diff --git a/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_init_list_args.pass.cpp b/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_init_list_args.pass.cpp index f466b160cb4f2..e69988a08e963 100644 --- a/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_init_list_args.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.mod/emplace_index_init_list_args.pass.cpp @@ -15,7 +15,7 @@ // template <class ...Types> class variant; // template <size_t I, class U, class ...Args> -// void emplace(initializer_list<U> il,Args&&... args); +// variant_alternative_t<I, variant<Types...>>& emplace(initializer_list<U> il,Args&&... args); #include <cassert> #include <string> @@ -70,13 +70,19 @@ void test_emplace_sfinae() { void test_basic() { using V = std::variant<int, InitList, InitListArg, TestTypes::NoCtors>; V v; - v.emplace<1>({1, 2, 3}); + auto& ref1 = v.emplace<1>({1, 2, 3}); + static_assert(std::is_same_v<InitList&, decltype(ref1)>, ""); assert(std::get<1>(v).size == 3); - v.emplace<2>({1, 2, 3, 4}, 42); + assert(&ref1 == &std::get<1>(v)); + auto& ref2 = v.emplace<2>({1, 2, 3, 4}, 42); + static_assert(std::is_same_v<InitListArg&, decltype(ref2)>, ""); assert(std::get<2>(v).size == 4); assert(std::get<2>(v).value == 42); - v.emplace<1>({1}); + assert(&ref2 == &std::get<2>(v)); + auto& ref3 = v.emplace<1>({1}); + static_assert(std::is_same_v<InitList&, decltype(ref3)>, ""); assert(std::get<1>(v).size == 1); + assert(&ref3 == &std::get<1>(v)); } int main() { diff --git a/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp b/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp index 4ca2cc4803e3d..8e329024b9df6 100644 --- a/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_args.pass.cpp @@ -14,7 +14,7 @@ // template <class ...Types> class variant; -// template <class T, class ...Args> void emplace(Args&&... args); +// template <class T, class ...Args> T& emplace(Args&&... args); #include <cassert> #include <string> @@ -86,10 +86,14 @@ void test_basic() { { using V = std::variant<int>; V v(42); - v.emplace<int>(); + auto& ref1 = v.emplace<int>(); + static_assert(std::is_same_v<int&, decltype(ref1)>, ""); assert(std::get<0>(v) == 0); - v.emplace<int>(42); + assert(&ref1 == &std::get<0>(v)); + auto& ref2 = v.emplace<int>(42); + static_assert(std::is_same_v<int&, decltype(ref2)>, ""); assert(std::get<0>(v) == 42); + assert(&ref2 == &std::get<0>(v)); } { using V = @@ -97,13 +101,19 @@ void test_basic() { const int x = 100; V v(std::in_place_type<int>, -1); // default emplace a value - v.emplace<long>(); + auto& ref1 = v.emplace<long>(); + static_assert(std::is_same_v<long&, decltype(ref1)>, ""); assert(std::get<1>(v) == 0); - v.emplace<const void *>(&x); + assert(&ref1 == &std::get<1>(v)); + auto& ref2 = v.emplace<const void *>(&x); + static_assert(std::is_same_v<const void *&, decltype(ref2)>, ""); assert(std::get<2>(v) == &x); + assert(&ref2 == &std::get<2>(v)); // emplace with multiple args - v.emplace<std::string>(3, 'a'); + auto& ref3 = v.emplace<std::string>(3, 'a'); + static_assert(std::is_same_v<std::string&, decltype(ref3)>, ""); assert(std::get<4>(v) == "aaa"); + assert(&ref3 == &std::get<4>(v)); } #if !defined(TEST_VARIANT_HAS_NO_REFERENCES) { @@ -114,20 +124,30 @@ void test_basic() { int z = 43; V v(std::in_place_index<0>, -1); // default emplace a value - v.emplace<long>(); + auto& ref1 = v.emplace<long>(); + static_assert(std::is_same_v<long&, decltype(ref1)>, ""); assert(std::get<long>(v) == 0); + assert(&ref1 == &std::get<long>(v)); // emplace a reference - v.emplace<const int &>(x); + auto& ref2 = v.emplace<const int &>(x); + static_assert(std::is_same_v<const int&, decltype(ref2)>, ""); assert(&std::get<const int &>(v) == &x); + assert(&ref2 == &std::get<const int &>(v)); // emplace an rvalue reference - v.emplace<int &&>(std::move(y)); + auto& ref3 = v.emplace<int &&>(std::move(y)); + static_assert(std::is_same_v<int &&, decltype(ref3)>, ""); assert(&std::get<int &&>(v) == &y); + assert(&ref3 == &std::get<int &&>(v)); // re-emplace a new reference over the active member - v.emplace<int &&>(std::move(z)); + auto& ref4 = v.emplace<int &&>(std::move(z)); + static_assert(std::is_same_v<int &, decltype(ref4)>, ""); assert(&std::get<int &&>(v) == &z); + assert(&ref4 == &std::get<int &&>(v)); // emplace with multiple args - v.emplace<std::string>(3, 'a'); + auto& ref5 = v.emplace<std::string>(3, 'a'); + static_assert(std::is_same_v<std::string&, decltype(ref5)>, ""); assert(std::get<std::string>(v) == "aaa"); + assert(&ref5 == &std::get<std::string>(v)); } #endif } diff --git a/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp b/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp index b2be8ac5b3fd1..da1658cb88f66 100644 --- a/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp @@ -15,7 +15,7 @@ // template <class ...Types> class variant; // template <class T, class U, class ...Args> -// void emplace(initializer_list<U> il,Args&&... args); +// T& emplace(initializer_list<U> il,Args&&... args); #include <cassert> #include <string> @@ -70,13 +70,19 @@ void test_emplace_sfinae() { void test_basic() { using V = std::variant<int, InitList, InitListArg, TestTypes::NoCtors>; V v; - v.emplace<InitList>({1, 2, 3}); + auto& ref1 = v.emplace<InitList>({1, 2, 3}); + static_assert(std::is_same_v<InitList&,decltype(ref1)>, ""); assert(std::get<InitList>(v).size == 3); - v.emplace<InitListArg>({1, 2, 3, 4}, 42); + assert(&ref1 == &std::get<InitList>(v)); + auto& ref2 = v.emplace<InitListArg>({1, 2, 3, 4}, 42); + static_assert(std::is_same_v<InitListArg&,decltype(ref2)>, ""); assert(std::get<InitListArg>(v).size == 4); assert(std::get<InitListArg>(v).value == 42); - v.emplace<InitList>({1}); + assert(&ref2 == &std::get<InitListArg>(v)); + auto& ref3 = v.emplace<InitList>({1}); + static_assert(std::is_same_v<InitList&,decltype(ref3)>, ""); assert(std::get<InitList>(v).size == 1); + assert(&ref3 == &std::get<InitList>(v)); } int main() { diff --git a/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp b/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp index 6675b5f2b2ba3..8025b9e0774eb 100644 --- a/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp @@ -10,10 +10,13 @@ // UNSUPPORTED: c++98, c++03, c++11, c++14 -// The following compilers don't allow constexpr variables of non-literal type. +// The following compilers don't consider a type an aggregate type (and +// consequently not a literal type) if it has a base class at all. +// In C++17, an aggregate type is allowed to have a base class if it's not +// virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors). // XFAIL: gcc-5, gcc-6 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8 -// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8 +// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0 // <variant> diff --git a/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp b/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp index a0c57e132403c..660a21c4f31d3 100644 --- a/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp +++ b/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp @@ -10,10 +10,13 @@ // UNSUPPORTED: c++98, c++03, c++11, c++14 -// The following compilers don't allow constexpr variables of non-literal type. +// The following compilers don't consider a type an aggregate type (and +// consequently not a literal type) if it has a base class at all. +// In C++17, an aggregate type is allowed to have a base class if it's not +// virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors). // XFAIL: gcc-5, gcc-6 // XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8 -// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8 +// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0 // <variant> |