]>
Commit | Line | Data |
---|---|---|
6458742a | 1 | // { dg-do run { target c++17 } } |
52e86221 | 2 | |
7adcbafe | 3 | // Copyright (C) 2014-2022 Free Software Foundation, Inc. |
52e86221 VV |
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 <any> | |
21 | #include <testsuite_hooks.h> | |
22 | ||
23 | using std::any; | |
24 | using std::any_cast; | |
25 | ||
1725d05d VV |
26 | bool moved = false; |
27 | bool copied = false; | |
28 | ||
52e86221 VV |
29 | struct X |
30 | { | |
52e86221 | 31 | X() = default; |
1725d05d | 32 | X(const X&) { copied = true; } |
13feb023 | 33 | X(X&&) { moved = true; } |
1725d05d VV |
34 | }; |
35 | ||
36 | struct X2 | |
37 | { | |
38 | X2() = default; | |
39 | X2(const X2&) { copied = true; } | |
13feb023 | 40 | X2(X2&&) noexcept { moved = true; } |
52e86221 VV |
41 | }; |
42 | ||
43 | void test01() | |
44 | { | |
1725d05d | 45 | moved = false; |
52e86221 VV |
46 | X x; |
47 | any a1; | |
48 | a1 = x; | |
1725d05d | 49 | VERIFY(moved == false); |
52e86221 | 50 | any a2; |
1725d05d | 51 | copied = false; |
52e86221 | 52 | a2 = std::move(x); |
1725d05d VV |
53 | VERIFY(moved == true); |
54 | VERIFY(copied == false); | |
55 | } | |
56 | ||
57 | void test02() | |
58 | { | |
59 | moved = false; | |
60 | X x; | |
61 | any a1; | |
62 | a1 = x; | |
63 | VERIFY(moved == false); | |
64 | any a2; | |
65 | copied = false; | |
66 | a2 = std::move(a1); | |
67 | VERIFY(moved == false); | |
68 | VERIFY(copied == false); | |
69 | } | |
70 | ||
71 | void test03() | |
72 | { | |
73 | moved = false; | |
74 | X2 x; | |
75 | any a1; | |
76 | a1 = x; | |
77 | VERIFY(copied && moved); | |
78 | any a2; | |
79 | moved = false; | |
80 | copied = false; | |
81 | a2 = std::move(a1); | |
82 | VERIFY(moved == true); | |
83 | VERIFY(copied == false); | |
52e86221 VV |
84 | } |
85 | ||
86 | int main() | |
87 | { | |
88 | test01(); | |
1725d05d VV |
89 | test02(); |
90 | test03(); | |
52e86221 | 91 | } |