]>
Commit | Line | Data |
---|---|---|
28de604e RL |
1 | // { dg-options "-std=gnu++0x -Wno-deprecated" } |
2 | ||
aa118a03 | 3 | // Copyright (C) 2010-2014 Free Software Foundation, Inc. |
28de604e RL |
4 | // |
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) | |
9 | // any later version. | |
10 | ||
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. | |
15 | ||
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/>. | |
19 | ||
20 | // 20.9.11.2 Template class shared_ptr [util.smartptr.shared] | |
21 | ||
22 | #include <memory> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | struct A | |
26 | { | |
27 | }; | |
28 | ||
29 | std::unique_ptr<A> | |
30 | create_unique_ptr() | |
31 | { | |
32 | return std::unique_ptr<A>(new A()); | |
33 | } | |
34 | ||
35 | std::auto_ptr<A> | |
36 | create_auto_ptr() | |
37 | { | |
38 | return std::auto_ptr<A>(new A()); | |
39 | } | |
40 | ||
41 | void | |
42 | process(std::shared_ptr<A> a) | |
43 | { | |
44 | bool test __attribute__((unused)) = true; | |
45 | ||
46 | VERIFY( a.get() != 0 ); | |
47 | VERIFY( a.use_count() == 1 ); | |
48 | } | |
49 | ||
50 | // 20.9.11.2.1 shared_ptr creation [util.smartptr.shared.const] | |
51 | ||
52 | // Implicit conversion of auto_ptr to shared_ptr is allowed | |
53 | ||
54 | void | |
55 | test01() | |
56 | { | |
57 | process(create_auto_ptr()); | |
58 | } | |
59 | ||
60 | void | |
61 | test02() | |
62 | { | |
63 | std::auto_ptr<A> a = create_auto_ptr(); | |
64 | process(std::move(a)); | |
65 | } | |
66 | ||
67 | // Implicit conversion of unique_ptr to shared_ptr is allowed | |
68 | ||
69 | void | |
70 | test03() | |
71 | { | |
72 | process(create_unique_ptr()); | |
73 | } | |
74 | ||
75 | void | |
76 | test04() | |
77 | { | |
78 | std::unique_ptr<A> a = create_unique_ptr(); | |
79 | process(std::move(a)); | |
80 | } | |
81 | ||
82 | int | |
83 | main() | |
84 | { | |
85 | test01(); | |
86 | test02(); | |
87 | test03(); | |
88 | test04(); | |
89 | return 0; | |
90 | } |