summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/memory
diff options
context:
space:
mode:
authorFan You <youfan.noey@gmail.com>2015-11-13 11:05:28 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2015-11-13 11:05:28 +0000
commit930d560203039875c4da07a01f579f56f5f2c636 (patch)
treeeb90f7cf60efb62b0d81e4ce24af95491ce9aff9 /libstdc++-v3/testsuite/experimental/memory
parent755fdaab8ed0d1c1f954c21a2a4a8d6830165bda (diff)
downloadgcc-930d560203039875c4da07a01f579f56f5f2c636.tar.gz
Implement std::experimental::shared_ptr with array support
2015-11-13 Fan You <youfan.noey@gmail.com> Jonathan Wakely <jwakely@redhat.com> * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/experimental/bits/shared_ptr.h: New. * include/experimental/memory: Include new header. * testsuite/experimental/memory/shared_ptr/assign/assign.cc: New. * testsuite/experimental/memory/shared_ptr/cast/cast.cc: New. * testsuite/experimental/memory/shared_ptr/comparison/comparison.cc: New. * testsuite/experimental/memory/shared_ptr/cons/alias_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/alloc_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/copy_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/copy_ctor_neg.cc: New. * testsuite/experimental/memory/shared_ptr/cons/default_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/move_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/pointer_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc: New. * testsuite/experimental/memory/shared_ptr/dest/dest.cc: New. * testsuite/experimental/memory/shared_ptr/modifiers/reset.cc: New. * testsuite/experimental/memory/shared_ptr/modifiers/swap.cc: New. * testsuite/experimental/memory/shared_ptr/observers/bool_conv.cc: New. * testsuite/experimental/memory/shared_ptr/observers/operators.cc: New. * testsuite/experimental/memory/shared_ptr/observers/owner_before.cc: New. * testsuite/experimental/memory/shared_ptr/observers/use_count.cc: New. Co-Authored-By: Jonathan Wakely <jwakely@redhat.com> From-SVN: r230300
Diffstat (limited to 'libstdc++-v3/testsuite/experimental/memory')
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/assign/assign.cc120
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cast/cast.cc44
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/comparison/comparison.cc84
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alias_ctor.cc100
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/alloc_ctor.cc73
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor.cc178
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/copy_ctor_neg.cc59
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/default_ctor.cc46
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/move_ctor.cc146
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/pointer_ctor.cc75
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/unique_ptr_ctor.cc60
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/cons/weak_ptr_ctor.cc54
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/dest/dest.cc129
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/reset.cc89
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/modifiers/swap.cc53
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/bool_conv.cc74
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/operators.cc93
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/owner_before.cc86
-rw-r--r--libstdc++-v3/testsuite/experimental/memory/shared_ptr/observers/use_count.cc73
19 files changed, 1636 insertions, 0 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;
+}