]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/is_nothrow_swappable_with/value.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / is_nothrow_swappable_with / value.cc
CommitLineData
ca9fde3d 1// { dg-options "-std=gnu++17" }
2// { dg-do compile }
3
fbd26352 4// Copyright (C) 2016-2019 Free Software Foundation, Inc.
ca9fde3d 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 copy 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 <type_traits>
22#include <testsuite_tr1.h>
23
24#ifndef __cpp_lib_is_swappable
25# error "Feature-test macro for is_nothrow_swappable_with missing"
26#elif __cpp_lib_is_swappable != 201603
27# error "Feature-test macro for is_nothrow_swappable_with has wrong value"
28#endif
29
30namespace funny {
31 struct T0 {};
32
33 void swap(T0, T0) noexcept;
34
35 struct T1
36 {
37 friend void swap(T1, T1) noexcept;
38 };
39
40 struct T2 {};
41 struct T3 {};
42
43 void swap(T2, T3) noexcept;
44 void swap(T3, T2) noexcept;
45
46 struct T4 { operator T0() const noexcept; };
47
48 struct F0 {};
49
50 void swap(F0, F0) = delete;
51
52 struct F1 {};
53
54 void swap(F1, F1);
55
56 struct F2 {};
57
58 void swap(F0, F2) noexcept;
59 void swap(F2, F0);
60
61 struct F3
62 {
63 friend void swap(F3, F3) = delete;
64 };
65
66 struct F4
67 {
68 friend void swap(F4, F4);
69 };
70
71 struct F5 { operator T0() const; };
72
73 struct BoolLike {};
74
75 void swap(BoolLike, bool&) noexcept;
76 void swap(bool&, BoolLike) noexcept;
77
78 struct BoolLikeErr {};
79
80 void swap(BoolLikeErr, bool&);
81 void swap(bool&, BoolLikeErr) noexcept;
82}
83
84void test01()
85{
86 using std::is_nothrow_swappable_with;
87 using namespace __gnu_test;
88 // Positive tests.
89 static_assert(test_property<is_nothrow_swappable_with, int&, int&>(true),
90 "");
91 static_assert(test_property<is_nothrow_swappable_with, funny::T0,
92 funny::T0>(true), "");
93 static_assert(test_property<is_nothrow_swappable_with, funny::T0,
94 const funny::T0>(true), "");
95 static_assert(test_property<is_nothrow_swappable_with, funny::T1,
96 funny::T1>(true), "");
97 static_assert(test_property<is_nothrow_swappable_with, funny::T1,
98 const funny::T1>(true), "");
99 static_assert(test_property<is_nothrow_swappable_with, funny::T2,
100 funny::T3>(true), "");
101 static_assert(test_property<is_nothrow_swappable_with, funny::T3,
102 funny::T2>(true), "");
103 static_assert(test_property<is_nothrow_swappable_with, funny::T0,
104 funny::T4>(true), "");
105 static_assert(test_property<is_nothrow_swappable_with, funny::T4,
106 funny::T0>(true), "");
107 static_assert(test_property<is_nothrow_swappable_with, funny::BoolLike,
108 bool&>(true), "");
109 static_assert(test_property<is_nothrow_swappable_with, const funny::BoolLike,
110 bool&>(true), "");
111
112 // Negative tests.
113 static_assert(test_property<is_nothrow_swappable_with, const int&,
114 const int&>(false), "");
115 static_assert(test_property<is_nothrow_swappable_with, int&,
116 unsigned&>(false), "");
117 static_assert(test_property<is_nothrow_swappable_with, funny::F0,
118 funny::F0>(false), "");
119 static_assert(test_property<is_nothrow_swappable_with, funny::F0,
120 const funny::F0>(false), "");
121 static_assert(test_property<is_nothrow_swappable_with, funny::F1,
122 funny::F1>(false), "");
123 static_assert(test_property<is_nothrow_swappable_with, funny::F1,
124 const funny::F1>(false), "");
125 static_assert(test_property<is_nothrow_swappable_with, funny::F0,
126 funny::F2>(false), "");
127 static_assert(test_property<is_nothrow_swappable_with, funny::F2,
128 funny::F0>(false), "");
129 static_assert(test_property<is_nothrow_swappable_with, funny::F3,
130 funny::F3>(false), "");
131 static_assert(test_property<is_nothrow_swappable_with, funny::F3,
132 const funny::F3>(false), "");
133 static_assert(test_property<is_nothrow_swappable_with, funny::F4,
134 funny::F4>(false), "");
135 static_assert(test_property<is_nothrow_swappable_with, funny::F4,
136 const funny::F4>(false), "");
137 static_assert(test_property<is_nothrow_swappable_with, funny::T0,
138 funny::F5>(false), "");
139 static_assert(test_property<is_nothrow_swappable_with, funny::F5,
140 funny::T0>(false), "");
141 static_assert(test_property<is_nothrow_swappable_with, funny::BoolLikeErr,
142 bool&>(false), "");
143 static_assert(test_property<is_nothrow_swappable_with,
144 const funny::BoolLikeErr, bool&>(false), "");
145}