]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / std / utilities / meta / meta.unary / meta.unary.cat / member_function_pointer.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // type_traits
11
12 // member_function_pointer
13
14 #include <type_traits>
15 #include "test_macros.h"
16
17 // NOTE: On Windows the function `test_is_member_function<void()>` and
18 // `test_is_member_function<void() noexcept> has the same mangled despite being
19 // a distinct instantiation. This causes Clang to emit an error. However
20 // structs do not have this problem.
21 template <class T>
22 struct test_member_function_pointer_imp {
23     static_assert(!std::is_void<T>::value, "");
24 #if TEST_STD_VER > 11
25     static_assert(!std::is_null_pointer<T>::value, "");
26 #endif
27     static_assert(!std::is_integral<T>::value, "");
28     static_assert(!std::is_floating_point<T>::value, "");
29     static_assert(!std::is_array<T>::value, "");
30     static_assert(!std::is_pointer<T>::value, "");
31     static_assert(!std::is_lvalue_reference<T>::value, "");
32     static_assert(!std::is_rvalue_reference<T>::value, "");
33     static_assert(!std::is_member_object_pointer<T>::value, "");
34     static_assert( std::is_member_function_pointer<T>::value, "");
35     static_assert(!std::is_enum<T>::value, "");
36     static_assert(!std::is_union<T>::value, "");
37     static_assert(!std::is_class<T>::value, "");
38     static_assert(!std::is_function<T>::value, "");
39 };
40
41 template <class T>
42 struct test_member_function_pointer :
43     test_member_function_pointer_imp<T>,
44     test_member_function_pointer_imp<const T>,
45     test_member_function_pointer_imp<volatile T>,
46     test_member_function_pointer_imp<const volatile T>
47 {
48 };
49
50 class Class
51 {
52 };
53
54 struct incomplete_type;
55
56 int main()
57 {
58   test_member_function_pointer<void (Class::*)()>();
59   test_member_function_pointer<void (Class::*)(int)>();
60   test_member_function_pointer<void (Class::*)(int, char)>();
61
62   test_member_function_pointer<void (Class::*)() const>();
63   test_member_function_pointer<void (Class::*)(int) const>();
64   test_member_function_pointer<void (Class::*)(int, char) const>();
65
66   test_member_function_pointer<void (Class::*)() volatile>();
67   test_member_function_pointer<void (Class::*)(int) volatile>();
68   test_member_function_pointer<void (Class::*)(int, char) volatile>();
69
70   test_member_function_pointer<void (Class::*)(...)>();
71   test_member_function_pointer<void (Class::*)(int, ...)>();
72   test_member_function_pointer<void (Class::*)(int, char, ...)>();
73
74   test_member_function_pointer<void (Class::*)(...) const>();
75   test_member_function_pointer<void (Class::*)(int, ...) const>();
76   test_member_function_pointer<void (Class::*)(int, char, ...) const>();
77
78   test_member_function_pointer<void (Class::*)(...) volatile>();
79   test_member_function_pointer<void (Class::*)(int, ...) volatile>();
80   test_member_function_pointer<void (Class::*)(int, char, ...) volatile>();
81
82
83 // reference qualifiers on functions are a C++11 extension
84 #if TEST_STD_VER >= 11
85   // Noexcept qualifiers
86   test_member_function_pointer<void (Class::*)() noexcept>();
87   test_member_function_pointer<void (Class::*)(int) noexcept>();
88   test_member_function_pointer<void (Class::*)(int, char) noexcept>();
89
90   test_member_function_pointer<void (Class::*)() const noexcept>();
91   test_member_function_pointer<void (Class::*)(int) const noexcept>();
92   test_member_function_pointer<void (Class::*)(int, char) const noexcept>();
93
94   test_member_function_pointer<void (Class::*)() volatile noexcept>();
95   test_member_function_pointer<void (Class::*)(int) volatile noexcept>();
96   test_member_function_pointer<void (Class::*)(int, char) volatile noexcept>();
97
98   test_member_function_pointer<void (Class::*)(...) noexcept>();
99   test_member_function_pointer<void (Class::*)(int, ...) noexcept>();
100   test_member_function_pointer<void (Class::*)(int, char, ...) noexcept>();
101
102   test_member_function_pointer<void (Class::*)(...) const noexcept>();
103   test_member_function_pointer<void (Class::*)(int, ...) const noexcept>();
104   test_member_function_pointer<void (Class::*)(int, char, ...) const noexcept>();
105
106   test_member_function_pointer<void (Class::*)(...) volatile noexcept>();
107   test_member_function_pointer<void (Class::*)(int, ...) volatile noexcept>();
108   test_member_function_pointer<void (Class::*)(int, char, ...) volatile noexcept>();
109
110   // lvalue qualifiers
111   test_member_function_pointer<void (Class::*)() &>();
112   test_member_function_pointer<void (Class::*)(int) &>();
113   test_member_function_pointer<void (Class::*)(int, char) &>();
114   test_member_function_pointer<void (Class::*)(...) &>();
115   test_member_function_pointer<void (Class::*)(int,...) &>();
116   test_member_function_pointer<void (Class::*)(int, char,...) &>();
117
118   test_member_function_pointer<void (Class::*)() const &>();
119   test_member_function_pointer<void (Class::*)(int) const &>();
120   test_member_function_pointer<void (Class::*)(int, char) const &>();
121   test_member_function_pointer<void (Class::*)(...) const &>();
122   test_member_function_pointer<void (Class::*)(int,...) const &>();
123   test_member_function_pointer<void (Class::*)(int, char,...) const &>();
124
125   test_member_function_pointer<void (Class::*)() volatile &>();
126   test_member_function_pointer<void (Class::*)(int) volatile &>();
127   test_member_function_pointer<void (Class::*)(int, char) volatile &>();
128   test_member_function_pointer<void (Class::*)(...) volatile &>();
129   test_member_function_pointer<void (Class::*)(int,...) volatile &>();
130   test_member_function_pointer<void (Class::*)(int, char,...) volatile &>();
131
132   test_member_function_pointer<void (Class::*)() const volatile &>();
133   test_member_function_pointer<void (Class::*)(int) const volatile &>();
134   test_member_function_pointer<void (Class::*)(int, char) const volatile &>();
135   test_member_function_pointer<void (Class::*)(...) const volatile &>();
136   test_member_function_pointer<void (Class::*)(int,...) const volatile &>();
137   test_member_function_pointer<void (Class::*)(int, char,...) const volatile &>();
138
139   // Lvalue qualifiers with noexcept
140   test_member_function_pointer<void (Class::*)() & noexcept>();
141   test_member_function_pointer<void (Class::*)(int) & noexcept>();
142   test_member_function_pointer<void (Class::*)(int, char) & noexcept>();
143   test_member_function_pointer<void (Class::*)(...) & noexcept>();
144   test_member_function_pointer<void (Class::*)(int,...) & noexcept>();
145   test_member_function_pointer<void (Class::*)(int, char,...) & noexcept>();
146
147   test_member_function_pointer<void (Class::*)() const & noexcept>();
148   test_member_function_pointer<void (Class::*)(int) const & noexcept>();
149   test_member_function_pointer<void (Class::*)(int, char) const & noexcept>();
150   test_member_function_pointer<void (Class::*)(...) const & noexcept>();
151   test_member_function_pointer<void (Class::*)(int,...) const & noexcept>();
152   test_member_function_pointer<void (Class::*)(int, char,...) const & noexcept>();
153
154   test_member_function_pointer<void (Class::*)() volatile & noexcept>();
155   test_member_function_pointer<void (Class::*)(int) volatile & noexcept>();
156   test_member_function_pointer<void (Class::*)(int, char) volatile & noexcept>();
157   test_member_function_pointer<void (Class::*)(...) volatile & noexcept>();
158   test_member_function_pointer<void (Class::*)(int,...) volatile & noexcept>();
159   test_member_function_pointer<void (Class::*)(int, char,...) volatile & noexcept>();
160
161   test_member_function_pointer<void (Class::*)() const volatile & noexcept>();
162   test_member_function_pointer<void (Class::*)(int) const volatile & noexcept>();
163   test_member_function_pointer<void (Class::*)(int, char) const volatile & noexcept>();
164   test_member_function_pointer<void (Class::*)(...) const volatile & noexcept>();
165   test_member_function_pointer<void (Class::*)(int,...) const volatile & noexcept>();
166   test_member_function_pointer<void (Class::*)(int, char,...) const volatile & noexcept>();
167
168   // RValue qualifiers
169   test_member_function_pointer<void (Class::*)() &&>();
170   test_member_function_pointer<void (Class::*)(int) &&>();
171   test_member_function_pointer<void (Class::*)(int, char) &&>();
172   test_member_function_pointer<void (Class::*)(...) &&>();
173   test_member_function_pointer<void (Class::*)(int,...) &&>();
174   test_member_function_pointer<void (Class::*)(int, char,...) &&>();
175
176   test_member_function_pointer<void (Class::*)() const &&>();
177   test_member_function_pointer<void (Class::*)(int) const &&>();
178   test_member_function_pointer<void (Class::*)(int, char) const &&>();
179   test_member_function_pointer<void (Class::*)(...) const &&>();
180   test_member_function_pointer<void (Class::*)(int,...) const &&>();
181   test_member_function_pointer<void (Class::*)(int, char,...) const &&>();
182
183   test_member_function_pointer<void (Class::*)() volatile &&>();
184   test_member_function_pointer<void (Class::*)(int) volatile &&>();
185   test_member_function_pointer<void (Class::*)(int, char) volatile &&>();
186   test_member_function_pointer<void (Class::*)(...) volatile &&>();
187   test_member_function_pointer<void (Class::*)(int,...) volatile &&>();
188   test_member_function_pointer<void (Class::*)(int, char,...) volatile &&>();
189
190   test_member_function_pointer<void (Class::*)() const volatile &&>();
191   test_member_function_pointer<void (Class::*)(int) const volatile &&>();
192   test_member_function_pointer<void (Class::*)(int, char) const volatile &&>();
193   test_member_function_pointer<void (Class::*)(...) const volatile &&>();
194   test_member_function_pointer<void (Class::*)(int,...) const volatile &&>();
195   test_member_function_pointer<void (Class::*)(int, char,...) const volatile &&>();
196
197   // RValue qualifiers with noexcept
198   test_member_function_pointer<void (Class::*)() && noexcept>();
199   test_member_function_pointer<void (Class::*)(int) && noexcept>();
200   test_member_function_pointer<void (Class::*)(int, char) && noexcept>();
201   test_member_function_pointer<void (Class::*)(...) && noexcept>();
202   test_member_function_pointer<void (Class::*)(int,...) && noexcept>();
203   test_member_function_pointer<void (Class::*)(int, char,...) && noexcept>();
204
205   test_member_function_pointer<void (Class::*)() const && noexcept>();
206   test_member_function_pointer<void (Class::*)(int) const && noexcept>();
207   test_member_function_pointer<void (Class::*)(int, char) const && noexcept>();
208   test_member_function_pointer<void (Class::*)(...) const && noexcept>();
209   test_member_function_pointer<void (Class::*)(int,...) const && noexcept>();
210   test_member_function_pointer<void (Class::*)(int, char,...) const && noexcept>();
211
212   test_member_function_pointer<void (Class::*)() volatile && noexcept>();
213   test_member_function_pointer<void (Class::*)(int) volatile && noexcept>();
214   test_member_function_pointer<void (Class::*)(int, char) volatile && noexcept>();
215   test_member_function_pointer<void (Class::*)(...) volatile && noexcept>();
216   test_member_function_pointer<void (Class::*)(int,...) volatile && noexcept>();
217   test_member_function_pointer<void (Class::*)(int, char,...) volatile && noexcept>();
218
219   test_member_function_pointer<void (Class::*)() const volatile && noexcept>();
220   test_member_function_pointer<void (Class::*)(int) const volatile && noexcept>();
221   test_member_function_pointer<void (Class::*)(int, char) const volatile && noexcept>();
222   test_member_function_pointer<void (Class::*)(...) const volatile && noexcept>();
223   test_member_function_pointer<void (Class::*)(int,...) const volatile && noexcept>();
224   test_member_function_pointer<void (Class::*)(int, char,...) const volatile && noexcept>();
225 #endif
226
227 //  LWG#2582
228   static_assert(!std::is_member_function_pointer<incomplete_type>::value, "");
229 }