]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/unique_ptr/54351.cc
b296b245f8e6773ea1cbb4c2e0af682e9409dd28
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / unique_ptr / 54351.cc
1 // { dg-options "-std=gnu++0x" }
2 // { dg-do run }
3
4 // Copyright (C) 2012-2014 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 20.7.1 Template class unique_ptr [unique.ptr]
22
23 #include <memory>
24 #include <testsuite_hooks.h>
25
26 struct A;
27
28 struct B
29 {
30 std::unique_ptr<A> a;
31 };
32
33 struct A
34 {
35 B* b;
36 ~A() { VERIFY(b->a != nullptr); }
37 };
38
39 void test01()
40 {
41 B b;
42 b.a.reset(new A);
43 b.a->b = &b;
44 }
45
46 struct C;
47
48 struct D
49 {
50 std::unique_ptr<C[]> c;
51 };
52
53 struct C
54 {
55 D* d;
56 ~C() { VERIFY(d->c != nullptr); }
57 };
58
59 void test02()
60 {
61 D d;
62 d.c.reset(new C[1]);
63 d.c[0].d = &d;
64 }
65
66 int main()
67 {
68 test01();
69 test02();
70 }