]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/any/cons/nontrivial.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / any / cons / nontrivial.cc
1 // Copyright (C) 2015-2021 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do run { target c++14 } }
19
20 #include <experimental/any>
21 #include <testsuite_hooks.h>
22
23 struct LocationAware
24 {
25 LocationAware() { }
26 ~LocationAware() { VERIFY(self == this); }
27 LocationAware(const LocationAware&) { }
28 LocationAware& operator=(const LocationAware&) { return *this; }
29 LocationAware(LocationAware&&) noexcept { }
30 LocationAware& operator=(LocationAware&&) noexcept { return *this; }
31
32 void* const self = this;
33 };
34 static_assert(std::is_nothrow_move_constructible<LocationAware>::value, "");
35 static_assert(!std::is_trivially_copyable<LocationAware>::value, "");
36
37 using std::experimental::any;
38
39 void
40 test01()
41 {
42
43 LocationAware l;
44 any a = l;
45 }
46
47 void
48 test02()
49 {
50 LocationAware l;
51 any a = l;
52 any b = a;
53 {
54 any tmp = std::move(a);
55 a = std::move(b);
56 b = std::move(tmp);
57 }
58 }
59
60 void
61 test03()
62 {
63 LocationAware l;
64 any a = l;
65 any b = a;
66 swap(a, b);
67 }
68
69 int
70 main()
71 {
72 test01();
73 test02();
74 test03();
75 }