1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2007-2013 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 20.6.6.2 Template class shared_ptr [util.smartptr.shared]
23 #include <testsuite_hooks.h>
39 void deletefunc(A* p) { delete p; }
41 // 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const]
43 // Aliasing constructors
47 bool test __attribute__((unused)) = true;
50 std::shared_ptr<bool> b1(a, &test);
51 VERIFY( b1.use_count() == 0 );
52 VERIFY( a.get() == 0 );
53 VERIFY( b1.get() == &test );
55 std::shared_ptr<bool> b2(b1);
56 VERIFY( b2.use_count() == 0 );
57 VERIFY( b1.get() == b2.get() );
65 bool test __attribute__((unused)) = true;
67 std::shared_ptr<A> a(new A);
68 std::shared_ptr<int> i1(a, &a->i);
69 VERIFY( i1.use_count() == 2 );
71 std::shared_ptr<int> i2(i1);
72 VERIFY( i2.use_count() == 3 );
73 VERIFY( i2.get() == &a->i );
81 bool test __attribute__((unused)) = true;
83 std::shared_ptr<B> b(new B);
84 std::shared_ptr<A> a1(b, b.get());
85 std::shared_ptr<A> a2(b, &b->a);
86 VERIFY( a2.use_count() == 3 );
89 VERIFY( a1.get() != a2.get() );
91 std::shared_ptr<A> a3(a1);
95 VERIFY( a3.get() == &b->a );