]>
Commit | Line | Data |
---|---|---|
0402a64a | 1 | // { dg-options "-std=gnu++14" } |
2 | // { dg-do run } | |
3 | ||
f1717362 | 4 | // Copyright (C) 2015-2016 Free Software Foundation, Inc. |
0402a64a | 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 moved_to 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 | #include <experimental/memory> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
24 | using std::experimental::observer_ptr; | |
25 | ||
26 | struct B {}; | |
27 | struct D : B {}; | |
28 | ||
29 | void test01() | |
30 | { | |
31 | observer_ptr<int> a, b; | |
32 | a = b; | |
33 | VERIFY(a == b); | |
34 | } | |
35 | ||
36 | void test02() | |
37 | { | |
38 | int x{}; | |
39 | observer_ptr<int> a; | |
40 | observer_ptr<int> b{&x}; | |
41 | VERIFY(a != b); | |
42 | a = b; | |
43 | VERIFY(a == b); | |
44 | } | |
45 | ||
46 | void test03() | |
47 | { | |
48 | int x{}; | |
49 | observer_ptr<const int> a; | |
50 | observer_ptr<int> b{&x}; | |
51 | VERIFY(a != b); | |
52 | a = b; | |
53 | VERIFY(a == b); | |
54 | } | |
55 | ||
56 | void test04() | |
57 | { | |
58 | D x{}; | |
59 | observer_ptr<B> a; | |
60 | observer_ptr<D> b{&x}; | |
61 | VERIFY(a != b); | |
62 | a = b; | |
63 | VERIFY(a == b); | |
64 | } | |
65 | ||
66 | constexpr bool test05_helper(observer_ptr<const int> a, | |
67 | observer_ptr<const int> b) | |
68 | { | |
69 | a = b; | |
70 | return (a.get() == b.get()); | |
71 | } | |
72 | ||
73 | void test05() | |
74 | { | |
75 | static constexpr int x{}; | |
76 | constexpr observer_ptr<const int> a; | |
77 | constexpr observer_ptr<const int> b{&x}; | |
78 | constexpr bool assigned = test05_helper(a, b); | |
79 | VERIFY(assigned); | |
80 | } | |
81 | ||
82 | int main() | |
83 | { | |
84 | test01(); | |
85 | test02(); | |
86 | test03(); | |
87 | test04(); | |
88 | test05(); | |
89 | } |