1 // { dg-options "-std=gnu++0x" }
3 // Copyright (C) 2007 Free Software Foundation
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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // 20.6.6.2 Template class shared_ptr [util.smartptr.shared]
24 #include <testsuite_hooks.h>
40 void deletefunc(A
* p
) { delete p
; }
42 // 20.6.6.2.1 shared_ptr constructors [util.smartptr.shared.const]
44 // Aliasing constructors
48 bool test
__attribute__((unused
)) = true;
51 std::shared_ptr
<bool> b1(a
, &test
);
52 VERIFY( b1
.use_count() == 0 );
53 VERIFY( a
.get() == 0 );
54 VERIFY( b1
.get() == &test
);
56 std::shared_ptr
<bool> b2(b1
);
57 VERIFY( b2
.use_count() == 0 );
58 VERIFY( b1
.get() == b2
.get() );
66 bool test
__attribute__((unused
)) = true;
68 std::shared_ptr
<A
> a(new A
);
69 std::shared_ptr
<int> i1(a
, &a
->i
);
70 VERIFY( i1
.use_count() == 2 );
72 std::shared_ptr
<int> i2(i1
);
73 VERIFY( i2
.use_count() == 3 );
74 VERIFY( i2
.get() == &a
->i
);
82 bool test
__attribute__((unused
)) = true;
84 std::shared_ptr
<B
> b(new B
);
85 std::shared_ptr
<A
> a1(b
, b
.get());
86 std::shared_ptr
<A
> a2(b
, &b
->a
);
87 VERIFY( a2
.use_count() == 3 );
90 VERIFY( a1
.get() != a2
.get() );
92 std::shared_ptr
<A
> a3(a1
);
96 VERIFY( a3
.get() == &b
->a
);