2017-03-14 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / is_nothrow_swappable_with / value.cc
blob5cd68a0dffd88f8e7d88fa2605310a7e125c0026
1 // { dg-options "-std=gnu++17" }
2 // { dg-do compile }
4 // Copyright (C) 2016-2017 Free Software Foundation, Inc.
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.
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.
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/>.
21 #include <type_traits>
22 #include <testsuite_tr1.h>
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
30 namespace funny {
31 struct T0 {};
33 void swap(T0, T0) noexcept;
35 struct T1
37 friend void swap(T1, T1) noexcept;
40 struct T2 {};
41 struct T3 {};
43 void swap(T2, T3) noexcept;
44 void swap(T3, T2) noexcept;
46 struct T4 { operator T0() const noexcept; };
48 struct F0 {};
50 void swap(F0, F0) = delete;
52 struct F1 {};
54 void swap(F1, F1);
56 struct F2 {};
58 void swap(F0, F2) noexcept;
59 void swap(F2, F0);
61 struct F3
63 friend void swap(F3, F3) = delete;
66 struct F4
68 friend void swap(F4, F4);
71 struct F5 { operator T0() const; };
73 struct BoolLike {};
75 void swap(BoolLike, bool&) noexcept;
76 void swap(bool&, BoolLike) noexcept;
78 struct BoolLikeErr {};
80 void swap(BoolLikeErr, bool&);
81 void swap(bool&, BoolLikeErr) noexcept;
84 void test01()
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), "");
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), "");