1 // { dg-do run { target c++14 } }
2 
3 // Copyright (C) 2014-2021 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/any>
21 #include <testsuite_hooks.h>
22 
23 using std::experimental::any;
24 using std::experimental::any_cast;
25 
26 bool moved = false;
27 bool copied = false;
28 
29 
30 struct X
31 {
32   X() = default;
XX33   X(const X&) { copied = true; }
XX34   X(X&&) { moved = true; }
35 };
36 
37 struct X2
38 {
39   X2() = default;
X2X240   X2(const X2&) { copied = true; }
X2X241   X2(X2&&) noexcept { moved = true; }
42 };
43 
test01()44 void test01()
45 {
46   moved = false;
47   X x;
48   any a1;
49   a1 = x;
50   VERIFY(moved == false);
51   any a2;
52   copied = false;
53   a2 = std::move(x);
54   VERIFY(moved == true);
55   VERIFY(copied == false);
56 }
57 
test02()58 void test02()
59 {
60   moved = false;
61   X x;
62   any a1;
63   a1 = x;
64   VERIFY(moved == false);
65   any a2;
66   copied = false;
67   a2 = std::move(a1);
68   VERIFY(moved == false);
69   VERIFY(copied == false);
70 }
71 
test03()72 void test03()
73 {
74   moved = false;
75   X2 x;
76   any a1;
77   a1 = x;
78   VERIFY(copied && moved);
79   any a2;
80   moved = false;
81   copied = false;
82   a2 = std::move(a1);
83   VERIFY(moved == true);
84   VERIFY(copied == false);
85  }
86 
main()87 int main()
88 {
89   test01();
90   test02();
91   test03();
92 }
93