diff options
Diffstat (limited to 'libstdc++-v3/testsuite/experimental')
25 files changed, 2150 insertions, 1 deletions
diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/assign/assign.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/assign/assign.cc new file mode 100644 index 00000000000..7656c98c327 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/assign/assign.cc @@ -0,0 +1,120 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// C++14 §20.8.2.2.3 shared_ptr assignment + +void +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a; + std::experimental::shared_ptr<A[]> a1; + std::experimental::shared_ptr<B[5]> a2; + + a = std::experimental::shared_ptr<A[5]> (); + VERIFY( a.get() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + a = std::experimental::shared_ptr<A[5]> (new A[5]); + VERIFY( a.get() != 0 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + a1 = std::experimental::shared_ptr<A[5]> (new A[5]); + VERIFY( a1.get() != 0 ); + VERIFY( A::ctor_count == 10 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + a2 = std::experimental::shared_ptr<B[5]> (new B[5]); + VERIFY( a2.get() != 0 ); + VERIFY( A::ctor_count == 15 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 5 ); + VERIFY( B::dtor_count == 0 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> p(new A[5]); + std::experimental::shared_ptr<A[5]> p1; + std::experimental::shared_ptr<A[]> p2; + + p1 = p; + VERIFY( p.get() == p1.get() ); + + p2 = p1; + VERIFY( p1.get() == p2.get() ); +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cast/cast.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cast/cast.cc new file mode 100644 index 00000000000..18c2ba4a4ec --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cast/cast.cc @@ -0,0 +1,44 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1.3 shared_ptr casts [memory.smartptr.shared.cast] + +#include <experimental/memory> +#include <testsuite_tr1.h> + +// { dg-do compile } + +struct A { }; + +int +main() +{ + using __gnu_test::check_ret_type; + using std::experimental::shared_ptr; + using std::experimental::static_pointer_cast; + using std::experimental::const_pointer_cast; + using std::experimental::dynamic_pointer_cast; + + shared_ptr<A[5]> spa; + shared_ptr<const A[5]> spa1; + + check_ret_type<shared_ptr<A[]> >(static_pointer_cast<A[]>(spa)); + check_ret_type<shared_ptr<A[]> >(const_pointer_cast<A[]>(spa1)); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/comparison/comparison.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/comparison/comparison.cc new file mode 100644 index 00000000000..52fc1934ed2 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/comparison/comparison.cc @@ -0,0 +1,84 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + virtual ~A() { } +}; + +struct B : A +{ +}; + +// 20.8.2.2.7 shared_ptr comparison + +int +test01() +{ + bool test __attribute__((unused)) = true; + + // test empty shared_ptrs compare equivalent + std::experimental::shared_ptr<A[5]> p1; + std::experimental::shared_ptr<B[5]> p2; + VERIFY( p1 == p2 ); + VERIFY( !(p1 != p2) ); + VERIFY( !(p1 < p2) && !(p2 < p1) ); + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> A_default; + + std::experimental::shared_ptr<A[5]> A_from_A(new A[5]); + VERIFY( A_default != A_from_A ); + VERIFY( !(A_default == A_from_A) ); + VERIFY( (A_default < A_from_A) || (A_from_A < A_default) ); + + std::experimental::shared_ptr<B[5]> B_from_B(new B[5]); + VERIFY( B_from_B != A_from_A ); + VERIFY( !(B_from_B == A_from_A) ); + VERIFY( (B_from_B < A_from_A) || (A_from_A < B_from_B) ); + + A_from_A.reset(); + VERIFY( A_default == A_from_A ); + VERIFY( !(A_default != A_from_A) ); + VERIFY( !(A_default < A_from_A) && !(A_from_A < A_default)); + + B_from_B.reset(); + VERIFY( B_from_B == A_from_A ); + VERIFY( !(B_from_B != A_from_A) ); + VERIFY( !(B_from_B < A_from_A) && !(A_from_A < B_from_B) ); + + return 0; +} + +int +main() +{ + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alias_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alias_ctor.cc new file mode 100644 index 00000000000..15d1de8e12a --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alias_ctor.cc @@ -0,0 +1,100 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + A() : i() { } + virtual ~A() { } + int i; +}; + +struct B : A +{ + B() : A(), a() { } + virtual ~B() { } + A a; +}; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Aliasing constructors + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a; + std::experimental::shared_ptr<bool> b1(a, &test); + VERIFY( b1.use_count() == 0 ); + VERIFY( a.get() == 0 ); + VERIFY( b1.get() == &test ); + + std::experimental::shared_ptr<bool> b2(b1); + VERIFY( b2.use_count() == 0 ); + VERIFY( b1.get() == b2.get() ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a(new A[5]); + std::experimental::shared_ptr<int> i1(a, &a[0].i); + VERIFY( i1.use_count() == 2 ); + + std::experimental::shared_ptr<int> i2(i1); + VERIFY( i2.use_count() == 3 ); + VERIFY( i2.get() == &a[0].i ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<B> b(new B); + std::experimental::shared_ptr<A> a1(b, b.get()); + std::experimental::shared_ptr<A> a2(b, &b->a); + VERIFY( a2.use_count() == 3 ); + VERIFY( a1 == b ); + VERIFY( a2 != b ); + VERIFY( a1.get() != a2.get() ); + + std::experimental::shared_ptr<A> a3(a1); + VERIFY( a3 == b ); + + a3 = a2; + VERIFY( a3.get() == &b->a ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alloc_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alloc_ctor.cc new file mode 100644 index 00000000000..12eb15ccef6 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alloc_ctor.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using __gnu_test::tracker_allocator_counter; +using __gnu_test::tracker_allocator; + +struct A { }; +void deletefunc(A* p) { delete [] p; } +struct D +{ + void operator()(A* p) { delete [] p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Construction with allocator + +int +test01() +{ + bool test __attribute__((unused)) = true; + tracker_allocator_counter::reset(); + + std::experimental::shared_ptr<A[5]> p1(new A[5], deletefunc, tracker_allocator<A[5]>()); + std::size_t const sz = tracker_allocator_counter::get_allocation_count(); + VERIFY( sz > 0 ); + { + std::experimental::shared_ptr<A[5]> p2(p1); + VERIFY( p2.use_count() == 2 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 ); + } + VERIFY( p1.use_count() == 1 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz); + VERIFY( tracker_allocator_counter::get_deallocation_count() == 0 ); + p1.reset(); + VERIFY( p1.use_count() == 0 ); + VERIFY( tracker_allocator_counter::get_allocation_count() == sz ); + VERIFY( tracker_allocator_counter::get_deallocation_count() == sz ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor.cc new file mode 100644 index 00000000000..4c3680ed156 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor.cc @@ -0,0 +1,178 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + virtual ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +void deleter(A* p) { delete [] p; } + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + } +}; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Copy construction + +int +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1; + std::experimental::shared_ptr<A[5]> a2(a1); + VERIFY( a2.use_count() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1(new A[5]); + std::experimental::shared_ptr<A[5]> a2(a1); + VERIFY( a2.use_count() == 2 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1(new A[5], &deleter); + std::experimental::shared_ptr<A[5]> a2(a1); + VERIFY( a2.use_count() == 2 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test04() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1(std::experimental::shared_ptr<A[5]> + (new A[5])); + VERIFY( a1.use_count() == 1 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test05() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1(new A[5]); + std::experimental::shared_ptr<A[]> a2(a1); + + VERIFY( a2.use_count() == 2 ); + VERIFY( a2.get() == a1.get() ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +test06() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<B> a1(new B); + std::experimental::shared_ptr<A> a2(a1); + + VERIFY( a2.use_count() == 2 ); + VERIFY( a2.get() == a1.get() ); + VERIFY( A::ctor_count == 1 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 1 ); + VERIFY( B::dtor_count == 0 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor_neg.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor_neg.cc new file mode 100644 index 00000000000..d3c94cf3405 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor_neg.cc @@ -0,0 +1,59 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + + +#include <experimental/memory> +#include <testsuite_hooks.h> + + +struct A { virtual ~A() { } }; +struct B : A { }; + + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Copy construction + +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[3]> a; + a = std::experimental::shared_ptr<B[3]> (new B[3]); // { dg-excess-errors "no matching" } +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[]> a(new A[3]); + std::experimental::shared_ptr<A[2]> spa(a); // { dg-excess-errors "no matching" } +} + +int +main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/default_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/default_ctor.cc new file mode 100644 index 00000000000..794e86528c0 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/default_ctor.cc @@ -0,0 +1,46 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Default construction +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a; + VERIFY( a.get() == 0 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/move_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/move_ctor.cc new file mode 100644 index 00000000000..3c070fe669e --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/move_ctor.cc @@ -0,0 +1,146 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + virtual ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct D +{ + void operator()(A* p) const { delete [] p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + D::delete_count = 0; + } +}; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Rvalue construction +int test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1; + std::experimental::shared_ptr<A[5]> a2(std::move(a1)); + VERIFY( a1.use_count() == 0 ); + VERIFY( a2.use_count() == 0 ); + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + + return 0; +} + +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a1(new A[5]); + std::experimental::shared_ptr<A[5]> a2(std::move(a1)); + VERIFY( a2.use_count() == 1 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + + return 0; +} + +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> b(new A[5], D()); + std::experimental::shared_ptr<A[5]> b1(std::move(b)); + VERIFY( b.use_count() == 0 ); + VERIFY( b1.use_count() == 1 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); + + b1 = std::move(std::experimental::shared_ptr<A[5]> ()); + + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 5 ); + VERIFY( D::delete_count == 1 ); + + return 0; +} + +void +test04() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a(std::move(std::experimental + ::shared_ptr<A[5]> + (new A[5]))); + + VERIFY( a.use_count() == 1 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); +} + +void +test05() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[]> a(std::move(std::experimental + ::shared_ptr<A[5]> + (new A[5]))); + + VERIFY( a.use_count() == 1 ); + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 0 ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/pointer_ctor.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/pointer_ctor.cc new file mode 100644 index 00000000000..d9ae591a41d --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/pointer_ctor.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B : A { }; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Construction from pointer +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = 0; + std::experimental::shared_ptr<A> p(a); + VERIFY( p.get() == 0 ); + VERIFY( p.use_count() == 1 ); + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A[5]; + std::experimental::shared_ptr<A[5]> p(a); + VERIFY( p.get() == a ); + VERIFY( p.use_count() == 1 ); + return 0; +} + +int +test03() +{ + bool test __attribute__((unused)) = true; + + B * const b = new B[5]; + std::experimental::shared_ptr<A[5]> p(b); + VERIFY( p.get() == b ); + VERIFY( p.use_count() == 1 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} 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 new file mode 100644 index 00000000000..35fb82f36bf --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc @@ -0,0 +1,60 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +int destroyed = 0; + +struct A : std::experimental::enable_shared_from_this<A> +{ + ~A() { ++destroyed; } +}; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Construction from unique_ptr<A[]> + +int +test01() +{ + bool test __attribute__((unused)) = true; + + std::unique_ptr<A[]> up(new A[5]); + std::experimental::shared_ptr<A> sp(std::move(up)); + VERIFY( up.get() == 0 ); + VERIFY( sp.get() != 0 ); + VERIFY( sp.use_count() == 1 ); + + VERIFY( sp->shared_from_this() != nullptr ); + + sp.reset(); + VERIFY( destroyed == 5 ); + + return 0; +} + +int +main() +{ + test01(); + return 0; +} 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 new file mode 100644 index 00000000000..342b37baa0d --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc @@ -0,0 +1,54 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 8.2.1.1 shared_ptr constructors [memory.smartptr.shared.const] + +// Construction from weak_ptr +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * a = new A[5]; + std::experimental::shared_ptr<A[5]> a1(a); + std::experimental::weak_ptr<A[5]> wa(a1); + std::experimental::shared_ptr<A[5]> a2(wa); + std::experimental::shared_ptr<A[5]> a3 = wa.lock(); + VERIFY( a2.get() == a ); + 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; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/dest/dest.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/dest/dest.cc new file mode 100644 index 00000000000..989121df909 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/dest/dest.cc @@ -0,0 +1,129 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + A() { ++ctor_count; } + ~A() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long A::ctor_count = 0; +long A::dtor_count = 0; + +struct B : A +{ + B() { ++ctor_count; } + ~B() { ++dtor_count; } + static long ctor_count; + static long dtor_count; +}; +long B::ctor_count = 0; +long B::dtor_count = 0; + +struct D +{ + void operator()(const B* p) { delete [] p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +struct reset_count_struct +{ + ~reset_count_struct() + { + A::ctor_count = 0; + A::dtor_count = 0; + B::ctor_count = 0; + B::dtor_count = 0; + D::delete_count = 0; + } +}; + +// 20.8.2.2.2 shared_ptr destructor + +int +test01() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + { + std::experimental::shared_ptr<A[5]> a; + } + VERIFY( A::ctor_count == 0 ); + VERIFY( A::dtor_count == 0 ); + VERIFY( B::ctor_count == 0 ); + VERIFY( B::dtor_count == 0 ); + VERIFY( D::delete_count == 0 ); + + return 0; +} + +int +test02() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + { + std::experimental::shared_ptr<B[5]> a; + a = std::experimental::shared_ptr<B[5]>(new B[5], D()); + } + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 5 ); + VERIFY( B::ctor_count == 5 ); + VERIFY( B::dtor_count == 5 ); + VERIFY( D::delete_count == 1 ); + + return 0; +} + +int +test03() +{ + reset_count_struct __attribute__((unused)) reset; + bool test __attribute__((unused)) = true; + + { + std::experimental::shared_ptr<B[]> a; + a = std::experimental::shared_ptr<B[5]>(new B[5], D()); + } + VERIFY( A::ctor_count == 5 ); + VERIFY( A::dtor_count == 5 ); + VERIFY( B::ctor_count == 5 ); + VERIFY( B::dtor_count == 5 ); + VERIFY( D::delete_count == 1 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/reset.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/reset.cc new file mode 100644 index 00000000000..bd1ce1d24b9 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/reset.cc @@ -0,0 +1,89 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B : A { }; +struct D +{ + void operator()(B* p) { delete [] p; ++delete_count; } + static long delete_count; +}; +long D::delete_count = 0; + +// C++14 §20.8.2.2.4 + +// reset +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A[5]; + std::experimental::shared_ptr<A[5]> p1(a); + std::experimental::shared_ptr<A[5]> p2(p1); + p1.reset(); + VERIFY( p1.get() == 0 ); + VERIFY( p2.get() == a ); + + return 0; +} + +int +test02() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A[5]; + B * const b = new B[5]; + std::experimental::shared_ptr<A[5]> p1(a); + std::experimental::shared_ptr<A[5]> p2(p1); + p1.reset(b); + VERIFY( p1.get() == b ); + VERIFY( p2.get() == a ); + + return 0; +} + +int +test03() +{ + bool test __attribute__((unused)) = true; + + { + std::experimental::shared_ptr<A[5]> p1; + p1.reset(new B[5], D()); + } + VERIFY( D::delete_count == 1 ); + + return 0; +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/swap.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/swap.cc new file mode 100644 index 00000000000..758042caf3a --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/swap.cc @@ -0,0 +1,53 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; + +// C++14 §20.8.2.2.4 + +// swap +int +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a1 = new A[5]; + A * const a2 = new A[5]; + std::experimental::shared_ptr<A[5]> p1(a1); + std::experimental::shared_ptr<A[5]> p2(a2); + p1.swap(p2); + VERIFY( p1.get() == a2 ); + VERIFY( p2.get() == a1 ); + + return 0; +} + + + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/bool_conv.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/bool_conv.cc new file mode 100644 index 00000000000..7e4c750a3cf --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/bool_conv.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; + +// 8.2.1.2 shared_ptr observers [memory.smartptr.shared.obs] + +// Conversion to bool +void +test01() +{ + bool test __attribute__((unused)) = true; + + const std::experimental::shared_ptr<A[5]> p1; + VERIFY( static_cast<bool>(p1) == false ); + const std::experimental::shared_ptr<A[5]> p2(p1); + VERIFY( static_cast<bool>(p2) == false ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> p1(new A[5]); + VERIFY( static_cast<bool>(p1) ); + std::experimental::shared_ptr<A[5]> p2(p1); + VERIFY( static_cast<bool>(p2) ); + p1.reset(); + VERIFY( !static_cast<bool>(p1) ); + VERIFY( static_cast<bool>(p2) ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> p1(new A[5]); + std::experimental::shared_ptr<A[5]> p2(p1); + p2.reset(new A[5]); + VERIFY( static_cast<bool>(p1) ); + VERIFY( static_cast<bool>(p2) ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/operators.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/operators.cc new file mode 100644 index 00000000000..d32c89978aa --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/operators.cc @@ -0,0 +1,93 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + A() : i() {} + int i; +}; + +// 8.2.1.2 shared_ptr observers [memory.smartptr.shared.obs] + +// get +void +test01() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A[5]; + const std::experimental::shared_ptr<A[5]> p(a); + VERIFY( p.get() == a ); +} + +// operator [] +int +test02() +{ + A * p = new A[5]; + std::experimental::shared_ptr<A[5]> a(p); + + for(int j = 0; j < 5; j++) + { a[j].i = j; } + + VERIFY(a.get() == p); + VERIFY(a.use_count() == 1); + + for(int j = 0; j < 5; j++) + { VERIFY(a[j].i == j); } + + return 0; +} + +// operator* +void +test03() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A[5]; + const std::experimental::shared_ptr<A[5]> p(a); + VERIFY( p.get() == a ); +} + +// operator-> +void +test04() +{ + bool test __attribute__((unused)) = true; + + A * const a = new A[5]; + const std::experimental::shared_ptr<A[5]> p(a); + VERIFY( &p[0].i == &a[0].i ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/owner_before.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/owner_before.cc new file mode 100644 index 00000000000..24a658a96f8 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/owner_before.cc @@ -0,0 +1,86 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A +{ + int i; + virtual ~A() { } +}; + +struct B : A { }; + +// 8.2.1.2 shared_ptr observers [memory.smartptr.shared.obs] + +// owner_before +void +test01() +{ + bool test __attribute__((unused)) = true; + + // test empty shared_ptrs compare equivalent + std::experimental::shared_ptr<A[5]> p1; + std::experimental::shared_ptr<B[5]> p2; + VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> a0; + + std::experimental::shared_ptr<A[5]> a1(new A[5]); + VERIFY( a1.owner_before(a0) || a0.owner_before(a1) ); + VERIFY( !(a1.owner_before(a0) && a0.owner_before(a1)) ); + + std::experimental::shared_ptr<B[5]> b1(new B[5]); + VERIFY( a1.owner_before(b1) || b1.owner_before(a1) ); + VERIFY( !(a1.owner_before(b1) && b1.owner_before(a1)) ); + + std::experimental::shared_ptr<A[5]> a2(a1); + VERIFY( !a1.owner_before(a2) && !a2.owner_before(a1) ); + + std::experimental::weak_ptr<A[5]> w1(a1); + VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> p1(new A[5]); + std::experimental::shared_ptr<int> p2(p1, &p1[0].i); + VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/use_count.cc b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/use_count.cc new file mode 100644 index 00000000000..fc48bf2160d --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/use_count.cc @@ -0,0 +1,73 @@ +// { dg-options "-std=gnu++1y" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 8.2.1 Class template shared_ptr [memory.smartptr.shared] + +#include <experimental/memory> +#include <testsuite_hooks.h> + +struct A { }; +struct B : A { }; + +// 8.2.1.2 shared_ptr observers [memory.smartptr.shared.obs] + +// use_count +void +test01() +{ + bool test __attribute__((unused)) = true; + + const std::experimental::shared_ptr<A[5]> p1; + VERIFY( p1.use_count() == 0 ); + const std::experimental::shared_ptr<A[5]> p2(p1); + VERIFY( p1.use_count() == 0 ); +} + +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> p1(new A[5]); + std::experimental::shared_ptr<A[5]> p2(p1); + p1.reset(); + VERIFY( p1.use_count() == 0 ); + VERIFY( p2.use_count() == 1 ); +} + +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::experimental::shared_ptr<A[5]> p1(new A[5]); + std::experimental::shared_ptr<A[5]> p2(p1); + p2.reset(new B[5]); + VERIFY( p1.use_count() == 1 ); + VERIFY( p2.use_count() == 1 ); +} + +int +main() +{ + test01(); + test02(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/random/randint.cc b/libstdc++-v3/testsuite/experimental/random/randint.cc new file mode 100644 index 00000000000..d5238361f7f --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/random/randint.cc @@ -0,0 +1,84 @@ +// { dg-options "-std=gnu++14" } +// { dg-require-effective-target tls_runtime } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a moved_to of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/random> +#include <testsuite_hooks.h> + +void +test01() +{ + for (int i = 0; i < 100; ++i) + { + const int n = std::experimental::randint(-10, i); + VERIFY( -10 <= n && n <= i ); + } + + std::experimental::reseed(99u); + const long n1[] = { + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100) + }; + std::experimental::reseed(99u); + const long n2[] = { + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100) + }; + for (int i = 0; i < 5; ++i) + VERIFY( n1[i] == n2[i] ); + + std::experimental::reseed(); + const long n3[] = { + std::experimental::randint(0, 100), + std::experimental::randint(0, 100), + std::experimental::randint(0, 100) + }; + VERIFY( !(n3[0] == n1[0] && n3[1] == n1[1] && n3[2] == n1[2]) ); +} + +void +test02() +{ + auto check = [](auto v) { + auto n = std::experimental::randint(decltype(v)(0), v); + static_assert(std::is_same<decltype(n), decltype(v)>::value, + "return type is correct"); + VERIFY(0 <= n && n <= v); + }; + check( (short)10 ); + check( 100 ); + check( 1000L ); + check( 10000LL ); + check( (unsigned short)10 ); + check( 100U ); + check( 1000UL ); + check( 10000ULL ); +} + +int main() +{ + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/experimental/type_erased_allocator/1.cc b/libstdc++-v3/testsuite/experimental/type_erased_allocator/1.cc new file mode 100644 index 00000000000..9545edff54d --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/type_erased_allocator/1.cc @@ -0,0 +1,147 @@ +// { dg-options "-std=gnu++14" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <memory> +#include <experimental/memory_resource> +#include <vector> +#include <bits/uses_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using std::experimental::pmr::polymorphic_allocator; +using std::experimental::pmr::memory_resource; +using std::experimental::pmr::new_delete_resource; +using std::experimental::pmr::get_default_resource; +using std::experimental::pmr::set_default_resource; + +struct A +{ + A() { ++ctor_count; } + ~A() { ++dtor_count; } + static int ctor_count; + static int dtor_count; +}; +int A::ctor_count = 0; +int A::dtor_count = 0; + +struct CountedResource : public memory_resource +{ +public: + CountedResource() = default; + ~ CountedResource() = default; + + static size_t get_alloc_count() { return alloc_count; } + static size_t get_dalloc_count() { return dalloc_count; } + + static size_t alloc_count; + static size_t dalloc_count; +protected: + void* do_allocate(size_t bytes, size_t alignment) + { + alloc_count += bytes; + if (auto ptr = std::malloc(bytes)) { + return ptr; + } + throw std::bad_alloc(); + } + + void do_deallocate(void *p, size_t bytes, size_t alignment) + { + dalloc_count += bytes; + free(p); + } + + bool do_is_equal(const memory_resource& __other) const noexcept + { return this == &__other; } +}; + size_t CountedResource::alloc_count = 0; + size_t CountedResource::dalloc_count = 0; + +void clear() +{ + CountedResource::alloc_count = 0; + CountedResource::dalloc_count = 0; + A::ctor_count = 0; + A::dtor_count = 0; +} + +// memory resource +void test01() +{ + memory_resource* r = new_delete_resource(); + VERIFY(get_default_resource() == r); + void *p = get_default_resource()->allocate(5); + VERIFY(p); + get_default_resource()->deallocate(p, 5); + + clear(); + CountedResource* cr = new CountedResource(); + set_default_resource(cr); + VERIFY(get_default_resource() == cr); + void *pc = get_default_resource()->allocate(5); + VERIFY(pc); + get_default_resource()->deallocate(pc, 5); + VERIFY(CountedResource::get_alloc_count() == 5); + VERIFY(CountedResource::get_dalloc_count() == 5); +} + +// polymorphic_allocator +void test02() +{ + clear(); + { + CountedResource cr; + polymorphic_allocator<A> pa(&cr); + std::vector<A, polymorphic_allocator<A>> v(5, A(), pa); + } + VERIFY(A::ctor_count == 1); + VERIFY(A::dtor_count == 6); + VERIFY(CountedResource::get_alloc_count() == 5); + VERIFY(CountedResource::get_dalloc_count() == 5); +} + +void test03() { + clear(); + CountedResource cr; + polymorphic_allocator<A> pa(&cr); + A* p = pa.allocate(1); + pa.construct(p); + pa.destroy(p); + pa.deallocate(p, 1); + VERIFY(A::ctor_count == 1); + VERIFY(A::dtor_count == 1); + VERIFY(CountedResource::get_alloc_count() == 1); + VERIFY(CountedResource::get_dalloc_count() == 1); +} + +void test04() { + polymorphic_allocator<A> pa1(get_default_resource()); + polymorphic_allocator<A> pa2(get_default_resource()); + VERIFY(pa1 == pa2); + polymorphic_allocator<A> pa3 = pa2.select_on_container_copy_construction(); + VERIFY(pa1 == pa3); +} + +int main() { + test01(); + test02(); + test03(); + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/type_erased_allocator/1_neg.cc b/libstdc++-v3/testsuite/experimental/type_erased_allocator/1_neg.cc new file mode 100644 index 00000000000..b85e0ea469f --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/type_erased_allocator/1_neg.cc @@ -0,0 +1,37 @@ +// { dg-do run { xfail *-*-* } } +// { dg-options "-std=gnu++14" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <experimental/memory_resource> +#include <bits/uses_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using std::experimental::pmr::polymorphic_allocator; +using std::experimental::pmr::null_memory_resource; +using std::experimental::pmr::memory_resource; + +void test01() { + memory_resource* r = null_memory_resource(); + auto p = r->allocate(1); +} + +int main() { + test01(); +} diff --git a/libstdc++-v3/testsuite/experimental/type_erased_allocator/2.cc b/libstdc++-v3/testsuite/experimental/type_erased_allocator/2.cc new file mode 100644 index 00000000000..014c357e5fa --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/type_erased_allocator/2.cc @@ -0,0 +1,202 @@ +// { dg-options "-std=gnu++14" } + +// Copyright (C) 2015 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <memory> +#include <experimental/memory_resource> +#include <experimental/utility> +#include <bits/uses_allocator.h> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> + +using std::experimental::pmr::polymorphic_allocator; +using std::experimental::pmr::memory_resource; +using std::experimental::pmr::new_delete_resource; +using std::experimental::pmr::get_default_resource; +using std::experimental::pmr::set_default_resource; +using std::allocator_arg_t; + +enum CtorType { Default, Copy, Move, Other, Tuple, Piecewise_Default, Piecewise_Copy}; + +// type that takes a memory_resource before other ctor args +struct A +{ + using allocator_type = std::experimental::erased_type; + + CtorType type; + memory_resource* alloc = nullptr; + + A() : type(Default) { } + A(allocator_arg_t, memory_resource* a) : type(Default), alloc(a) { } + A(const A&) : type(Copy) { } + A(allocator_arg_t, memory_resource* a, const A&) : type(Copy), alloc(a) { } + A(A&&) : type (Move) { } + A(allocator_arg_t, memory_resource* a, A&&) : type (Move), alloc(a) { } + A(int) : type(Other) { } + A(allocator_arg_t, memory_resource* a, int) : type(Other), alloc(a) { } +}; + +// type that takes a memory_resource after other ctor args +struct B +{ + using allocator_type = std::experimental::erased_type; + + CtorType type; + memory_resource* alloc = nullptr; + + B() : type(Default) { } + B(memory_resource* a) : type(Default), alloc(a) { } + B(const B&) : type(Copy) { } + B(const B&, memory_resource* a) : type(Copy), alloc(a) { } + B(B&&) : type (Move) { } + B(B&&, memory_resource* a) : type(Move), alloc(a) { } + B(int) : type(Other) { } + B(int, memory_resource* a) : type(Other), alloc(a) { } +}; + +// type that takes no memory_resource +struct C +{ + CtorType type; + C() : type(Default) { } + C(const C&) : type(Copy) { } + C(C&&) : type(Move) { } + C(int) : type(Other) { } +}; + +// test construct for type that +// uses memory_resource* as allocator +template<typename A> +void test_uses_alloc() { + polymorphic_allocator<A> pa; + A* p = pa.allocate(1); + A a; + + pa.construct(p); + VERIFY(p->alloc == get_default_resource()); + VERIFY(p->type == Default); + pa.destroy(p); + + pa.construct(p, a); + VERIFY(p->type == Copy); + pa.destroy(p); + + pa.construct(p, A()); + VERIFY(p->type == Move); + pa.destroy(p); + + pa.construct(p, 1); + VERIFY(p->type == Other); + pa.destroy(p); + + pa.deallocate(p, 1); +} + +// test construct for type that not using allocator +template <typename C> +void test_non_alloc() { + polymorphic_allocator<C> pa; + C* p = pa.allocate(1); + C b; + + pa.construct(p); + VERIFY(p->type == Default); + pa.destroy(p); + + pa.construct(p, b); + VERIFY(p->type == Copy); + pa.destroy(p); + + pa.construct(p, C()); + VERIFY(p->type == Move); + pa.destroy(p); + + pa.construct(p, 1); + VERIFY(p->type == Other); + pa.destroy(p); + + pa.deallocate(p, 1); +} + +// test piecewise_construct +template <typename A, typename B> +void test_pair() { + polymorphic_allocator<std::pair<A, B>> pa; + std::pair<A, B>* p = pa.allocate(1); + std::tuple<> t; + + // construct(pair<T1, T2>* p, piecewise_construct_t, tuple<...>, tuple<...>) + pa.construct(p, std::piecewise_construct, t, t); + VERIFY(p->first.type == Default); + VERIFY(p->second.type == Default); + pa.destroy(p); + + // construct(pair<T1, T2>* __p) + pa.construct(p); + VERIFY(p->first.type == Default); + VERIFY(p->second.type == Default); + pa.destroy(p); + + // construct(pair<T1, T2>* p, U&& x, V&& y) + A a; B b; + pa.construct(p, a, b); + VERIFY(p->first.type == Copy); + VERIFY(p->second.type == Copy); + pa.destroy(p); + + pa.construct(p, A(), B()); + VERIFY(p->first.type == Move); + VERIFY(p->second.type == Move); + auto pp = *p; + pa.destroy(p); + + // construct(pair<T1, T2>* p, const pair<U, V>& x) + pa.construct(p, pp); + VERIFY(p->first.type == Copy); + VERIFY(p->second.type == Copy); + pa.destroy(p); + + // construct(pair<T1, T2>* p, pair<U, V>&& x) + pa.construct(p, std::move(pp)); + VERIFY(p->first.type == Move); + VERIFY(p->second.type == Move); + pa.destroy(p); + pa.deallocate(p, 1); +} + +void test01() { + test_uses_alloc<A>(); + test_uses_alloc<B>(); + test_non_alloc<C>(); +} + +void test02() { + test_pair<A, A>(); + test_pair<A, B>(); + test_pair<A, C>(); + test_pair<B, B>(); + test_pair<B, A>(); + test_pair<B, C>(); + test_pair<C, C>(); +} + + +int main() { + test01(); + test02(); +} diff --git a/libstdc++-v3/testsuite/experimental/type_erased_allocator/uses_allocator.cc b/libstdc++-v3/testsuite/experimental/type_erased_allocator/uses_allocator.cc new file mode 100644 index 00000000000..fc8acf16dcd --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/type_erased_allocator/uses_allocator.cc @@ -0,0 +1,22 @@ +#include <bits/uses_allocator.h> +#include <vector> +#include <experimental/utility> +#include <memory> + +using std::vector; +using std::allocator; +using std::uses_allocator; + +struct A { + using allocator_type = std::experimental::erased_type; +}; + +void test01() { + static_assert(uses_allocator<vector<int>, allocator<int>>()); + static_assert(uses_allocator<A, allocator<A>>()); +} + +int main() { + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/experimental/type_traits/value.cc b/libstdc++-v3/testsuite/experimental/type_traits/value.cc index fefe52391a2..d52b454fa69 100644 --- a/libstdc++-v3/testsuite/experimental/type_traits/value.cc +++ b/libstdc++-v3/testsuite/experimental/type_traits/value.cc @@ -21,7 +21,7 @@ #include <experimental/type_traits> using namespace std; -using namespace std::experimental; +using namespace experimental; // These tests are rather simple, the front-end tests already test // variable templates, and the library tests for the underlying @@ -322,3 +322,24 @@ static_assert(is_convertible_v<int&, const int&> && is_convertible<int&, const int&>::value, ""); static_assert(!is_convertible_v<const int&, int&> && !is_convertible<const int&, int&>::value, ""); + +static_assert(negation_v<false_type>); +static_assert(!negation_v<true_type>); +static_assert(conjunction_v<>); +static_assert(!disjunction_v<>); +static_assert(conjunction_v<true_type>); +static_assert(!conjunction_v<false_type>); +static_assert(disjunction_v<true_type>); +static_assert(!disjunction_v<false_type>); +static_assert(conjunction_v<true_type, true_type>); +static_assert(!conjunction_v<true_type, false_type>); +static_assert(disjunction_v<false_type, true_type>); +static_assert(!disjunction_v<false_type, false_type>); +static_assert(conjunction_v<true_type, true_type, + true_type>); +static_assert(!conjunction_v<true_type, true_type, + false_type>); +static_assert(disjunction_v<false_type, false_type, + true_type>); +static_assert(!disjunction_v<false_type, false_type, + false_type>); |