From a04df2babb16c70ba02f1f44bc92bd723d84a11f Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Wed, 19 Oct 2016 12:57:22 +0100 Subject: [PATCH] Test experimental::shared_ptr construction from other smart pointers * testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc: Add tests for valid and invalid conversions. * testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc: Likewise. From-SVN: r241340 --- libstdc++-v3/ChangeLog | 5 +++ .../memory/shared_ptr/cons/unique_ptr_ctor.cc | 25 +++++++++++ .../memory/shared_ptr/cons/weak_ptr_ctor.cc | 41 ++++++++++++++++--- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f2a143ea106..565b32cbeae 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2016-10-19 Jonathan Wakely + * testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc: + Add tests for valid and invalid conversions. + * testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc: + Likewise. + * testsuite/20_util/unique_ptr/cons/cv_qual.cc: Move negative tests to new file. * testsuite/20_util/unique_ptr/cons/cv_qual_neg.cc: New file. Fix diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc index 631212fc4cd..0e61a3c662a 100644 --- a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc @@ -29,10 +29,35 @@ struct A : std::experimental::enable_shared_from_this ~A() { ++destroyed; } }; +struct B : A { }; + // 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] // Construction from unique_ptr +template +constexpr bool constructible() +{ + using std::experimental::shared_ptr; + using std::experimental::is_constructible_v; + using std::unique_ptr; + return is_constructible_v, unique_ptr>; +} + +static_assert( constructible< A, A >(), "A -> A compatible" ); +static_assert( !constructible< A, A[] >(), "A -> A[] not compatible" ); +static_assert( !constructible< A, A[1] >(), "A -> A[1] not compatible" ); +static_assert( !constructible< A[], A >(), "A[] -> A not compatible" ); +static_assert( constructible< A[], A[] >(), "A[] -> A[] compatible" ); +static_assert( !constructible< A[], A[1] >(), "A[] -> A[1] not compatible" ); + +static_assert( constructible< B, A >(), "B -> A compatible" ); +static_assert( !constructible< B, A[] >(), "B -> A[] not compatible" ); +static_assert( !constructible< B, A[1] >(), "B -> A[1] not compatible" ); +static_assert( !constructible< B[], A >(), "B[] -> A not compatible" ); +static_assert( !constructible< B[], A[] >(), "B[] -> A[] not compatible" ); +static_assert( !constructible< B[], A[1] >(), "B[2] -> A[1] not compatible" ); + void test01() { diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc index 71cf583af32..3436c01eea1 100644 --- a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc @@ -23,11 +23,46 @@ #include struct A { }; +struct B : A { }; // 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] +template +constexpr bool constructible() +{ + using std::experimental::shared_ptr; + using std::experimental::weak_ptr; + using std::experimental::is_constructible_v; + return is_constructible_v, weak_ptr> + && is_constructible_v, const weak_ptr&>; +} + +static_assert( constructible< A, A >(), "A -> A compatible" ); +static_assert( !constructible< A, A[] >(), "A -> A[] not compatible" ); +static_assert( !constructible< A, A[1] >(), "A -> A[1] not compatible" ); +static_assert( !constructible< A[], A >(), "A[] -> A not compatible" ); +static_assert( constructible< A[], A[] >(), "A[] -> A[] compatible" ); +static_assert( !constructible< A[], A[1] >(), "A[] -> A[1] not compatible" ); +static_assert( !constructible< A[1], A >(), "A[1] -> A not compatible" ); +static_assert( constructible< A[1], A[] >(), "A[1] -> A[] compatible" ); +static_assert( constructible< A[1], A[1] >(), "A[1] -> A[1] compatible" ); +static_assert( !constructible< A[2], A[1] >(), "A[2] -> A[1] not compatible" ); + +static_assert( constructible< B, A >(), "B -> A compatible" ); +static_assert( !constructible< B, A[] >(), "B -> A[] not compatible" ); +static_assert( !constructible< B, A[1] >(), "B -> A[1] not compatible" ); +static_assert( !constructible< B[], A >(), "B[] -> A not compatible" ); +static_assert( !constructible< B[], A[] >(), "B[] -> A[] not compatible" ); +static_assert( !constructible< B[], A[1] >(), "B[] -> A[1] not compatible" ); +static_assert( !constructible< B[1], A >(), "B[] -> A not compatible" ); +static_assert( !constructible< B[1], A[] >(), "B[] -> A[] not compatible" ); +static_assert( !constructible< B[1], A[1] >(), "B[] -> A[1] not compatible" ); +static_assert( !constructible< B[2], A[1] >(), "B[2] -> A[1] not compatible" ); + + + // Construction from weak_ptr -int +void test01() { A * a = new A[5]; @@ -39,14 +74,10 @@ test01() VERIFY( a3.get() == a ); VERIFY( a2.use_count() == wa.use_count() ); VERIFY( a3.use_count() == wa.use_count() ); - - return 0; } - int main() { test01(); - return 0; } -- 2.30.2