| 1 | // { dg-do run { target c++14 } } |
| 2 | |
| 3 | // Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 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 | #include <experimental/memory> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | using std::experimental::observer_ptr; |
| 24 | |
| 25 | struct B {}; |
| 26 | struct D : B {}; |
| 27 | |
| 28 | void test01() |
| 29 | { |
| 30 | observer_ptr<int> a, b; |
| 31 | VERIFY(a == b); |
| 32 | swap(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); |
| 42 | VERIFY(b); |
| 43 | swap(a, b); |
| 44 | VERIFY(a); |
| 45 | VERIFY(!b); |
| 46 | } |
| 47 | |
| 48 | void test03() |
| 49 | { |
| 50 | int x[2]{1,2}; |
| 51 | observer_ptr<int> a{&x[0]}; |
| 52 | observer_ptr<int> b{&x[1]}; |
| 53 | VERIFY(*a == 1); |
| 54 | VERIFY(*b == 2); |
| 55 | swap(a, b); |
| 56 | VERIFY(*a == 2); |
| 57 | VERIFY(*b == 1); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | int main() |
| 62 | { |
| 63 | test01(); |
| 64 | test02(); |
| 65 | test03(); |
| 66 | } |