]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
8dd5e93a | 2 | |
8d9254fc | 3 | // Copyright (C) 2008-2020 Free Software Foundation, Inc. |
8dd5e93a JW |
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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
8dd5e93a JW |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
8dd5e93a JW |
19 | |
20 | // 20.8.13.3 Template class weak_ptr [util.smartptr.weak] | |
21 | ||
22 | #include <memory> | |
23 | #include <testsuite_hooks.h> | |
24 | ||
25 | struct A { }; | |
26 | struct B { }; | |
27 | ||
28 | // 20.6.6.3.5 weak_ptr observers [util.smartptr.weak.obs] | |
29 | ||
d08606ce | 30 | void |
8dd5e93a JW |
31 | test01() |
32 | { | |
33 | // test empty weak_ptrs compare equivalent | |
34 | std::weak_ptr<A> p1; | |
35 | std::weak_ptr<B> p2; | |
36 | VERIFY( !p1.owner_before(p2) && !p2.owner_before(p1) ); | |
37 | ||
38 | std::shared_ptr<B> p3; | |
39 | VERIFY( !p1.owner_before(p3) && !p3.owner_before(p1) ); | |
40 | ||
d08606ce JW |
41 | static_assert( noexcept(p1.owner_before(p1)), "" ); |
42 | static_assert( noexcept(p1.owner_before(p2)), "" ); | |
43 | static_assert( noexcept(p1.owner_before(p3)), "" ); | |
44 | static_assert( noexcept(p2.owner_before(p1)), "" ); | |
8dd5e93a JW |
45 | } |
46 | ||
47 | ||
d08606ce | 48 | void |
8dd5e93a JW |
49 | test02() |
50 | { | |
51 | std::shared_ptr<A> a0; | |
52 | std::weak_ptr<A> w0(a0); | |
53 | ||
54 | std::shared_ptr<A> a1(new A); | |
55 | std::weak_ptr<A> w1(a1); | |
56 | VERIFY( !a1.owner_before(w1) && !w1.owner_before(a1) ); | |
57 | ||
58 | VERIFY( w1.owner_before(w0) || w0.owner_before(w1) ); | |
59 | VERIFY( !(w1.owner_before(w0) && w0.owner_before(w1)) ); | |
60 | ||
61 | VERIFY( w1.owner_before(a0) || a0.owner_before(w1) ); | |
62 | VERIFY( !(w1.owner_before(a0) && a0.owner_before(w1)) ); | |
63 | ||
64 | std::shared_ptr<B> b1(new B); | |
65 | VERIFY( w1.owner_before(b1) || b1.owner_before(w1) ); | |
8dd5e93a JW |
66 | } |
67 | ||
68 | int | |
69 | main() | |
70 | { | |
71 | test01(); | |
72 | test02(); | |
73 | return 0; | |
74 | } |