summaryrefslogtreecommitdiff
path: root/test/std/utilities/meta/meta.unary/meta.unary.cat/member_function_pointer.pass.cpp
blob: 345195e0e368aea6a10dbfa095df253f5efee4c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// type_traits

// member_function_pointer

#include <type_traits>
#include "test_macros.h"

// NOTE: On Windows the function `test_is_member_function<void()>` and
// `test_is_member_function<void() noexcept> has the same mangled despite being
// a distinct instantiation. This causes Clang to emit an error. However
// structs do not have this problem.
template <class T>
struct test_member_function_pointer_imp {
    static_assert(!std::is_void<T>::value, "");
#if TEST_STD_VER > 11
    static_assert(!std::is_null_pointer<T>::value, "");
#endif
    static_assert(!std::is_integral<T>::value, "");
    static_assert(!std::is_floating_point<T>::value, "");
    static_assert(!std::is_array<T>::value, "");
    static_assert(!std::is_pointer<T>::value, "");
    static_assert(!std::is_lvalue_reference<T>::value, "");
    static_assert(!std::is_rvalue_reference<T>::value, "");
    static_assert(!std::is_member_object_pointer<T>::value, "");
    static_assert( std::is_member_function_pointer<T>::value, "");
    static_assert(!std::is_enum<T>::value, "");
    static_assert(!std::is_union<T>::value, "");
    static_assert(!std::is_class<T>::value, "");
    static_assert(!std::is_function<T>::value, "");
};

template <class T>
struct test_member_function_pointer :
    test_member_function_pointer_imp<T>,
    test_member_function_pointer_imp<const T>,
    test_member_function_pointer_imp<volatile T>,
    test_member_function_pointer_imp<const volatile T>
{
};

class Class
{
};

struct incomplete_type;

int main()
{
  test_member_function_pointer<void (Class::*)()>();
  test_member_function_pointer<void (Class::*)(int)>();
  test_member_function_pointer<void (Class::*)(int, char)>();

  test_member_function_pointer<void (Class::*)() const>();
  test_member_function_pointer<void (Class::*)(int) const>();
  test_member_function_pointer<void (Class::*)(int, char) const>();

  test_member_function_pointer<void (Class::*)() volatile>();
  test_member_function_pointer<void (Class::*)(int) volatile>();
  test_member_function_pointer<void (Class::*)(int, char) volatile>();

  test_member_function_pointer<void (Class::*)(...)>();
  test_member_function_pointer<void (Class::*)(int, ...)>();
  test_member_function_pointer<void (Class::*)(int, char, ...)>();

  test_member_function_pointer<void (Class::*)(...) const>();
  test_member_function_pointer<void (Class::*)(int, ...) const>();
  test_member_function_pointer<void (Class::*)(int, char, ...) const>();

  test_member_function_pointer<void (Class::*)(...) volatile>();
  test_member_function_pointer<void (Class::*)(int, ...) volatile>();
  test_member_function_pointer<void (Class::*)(int, char, ...) volatile>();


// reference qualifiers on functions are a C++11 extension
#if TEST_STD_VER >= 11
  // Noexcept qualifiers
  test_member_function_pointer<void (Class::*)() noexcept>();
  test_member_function_pointer<void (Class::*)(int) noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) noexcept>();

  test_member_function_pointer<void (Class::*)() const noexcept>();
  test_member_function_pointer<void (Class::*)(int) const noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) const noexcept>();

  test_member_function_pointer<void (Class::*)() volatile noexcept>();
  test_member_function_pointer<void (Class::*)(int) volatile noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) volatile noexcept>();

  test_member_function_pointer<void (Class::*)(...) noexcept>();
  test_member_function_pointer<void (Class::*)(int, ...) noexcept>();
  test_member_function_pointer<void (Class::*)(int, char, ...) noexcept>();

  test_member_function_pointer<void (Class::*)(...) const noexcept>();
  test_member_function_pointer<void (Class::*)(int, ...) const noexcept>();
  test_member_function_pointer<void (Class::*)(int, char, ...) const noexcept>();

  test_member_function_pointer<void (Class::*)(...) volatile noexcept>();
  test_member_function_pointer<void (Class::*)(int, ...) volatile noexcept>();
  test_member_function_pointer<void (Class::*)(int, char, ...) volatile noexcept>();

  // lvalue qualifiers
  test_member_function_pointer<void (Class::*)() &>();
  test_member_function_pointer<void (Class::*)(int) &>();
  test_member_function_pointer<void (Class::*)(int, char) &>();
  test_member_function_pointer<void (Class::*)(...) &>();
  test_member_function_pointer<void (Class::*)(int,...) &>();
  test_member_function_pointer<void (Class::*)(int, char,...) &>();

  test_member_function_pointer<void (Class::*)() const &>();
  test_member_function_pointer<void (Class::*)(int) const &>();
  test_member_function_pointer<void (Class::*)(int, char) const &>();
  test_member_function_pointer<void (Class::*)(...) const &>();
  test_member_function_pointer<void (Class::*)(int,...) const &>();
  test_member_function_pointer<void (Class::*)(int, char,...) const &>();

  test_member_function_pointer<void (Class::*)() volatile &>();
  test_member_function_pointer<void (Class::*)(int) volatile &>();
  test_member_function_pointer<void (Class::*)(int, char) volatile &>();
  test_member_function_pointer<void (Class::*)(...) volatile &>();
  test_member_function_pointer<void (Class::*)(int,...) volatile &>();
  test_member_function_pointer<void (Class::*)(int, char,...) volatile &>();

  test_member_function_pointer<void (Class::*)() const volatile &>();
  test_member_function_pointer<void (Class::*)(int) const volatile &>();
  test_member_function_pointer<void (Class::*)(int, char) const volatile &>();
  test_member_function_pointer<void (Class::*)(...) const volatile &>();
  test_member_function_pointer<void (Class::*)(int,...) const volatile &>();
  test_member_function_pointer<void (Class::*)(int, char,...) const volatile &>();

  // Lvalue qualifiers with noexcept
  test_member_function_pointer<void (Class::*)() & noexcept>();
  test_member_function_pointer<void (Class::*)(int) & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) & noexcept>();
  test_member_function_pointer<void (Class::*)(...) & noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) & noexcept>();

  test_member_function_pointer<void (Class::*)() const & noexcept>();
  test_member_function_pointer<void (Class::*)(int) const & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) const & noexcept>();
  test_member_function_pointer<void (Class::*)(...) const & noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) const & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) const & noexcept>();

  test_member_function_pointer<void (Class::*)() volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int) volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(...) volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) volatile & noexcept>();

  test_member_function_pointer<void (Class::*)() const volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int) const volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) const volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(...) const volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) const volatile & noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) const volatile & noexcept>();

  // RValue qualifiers
  test_member_function_pointer<void (Class::*)() &&>();
  test_member_function_pointer<void (Class::*)(int) &&>();
  test_member_function_pointer<void (Class::*)(int, char) &&>();
  test_member_function_pointer<void (Class::*)(...) &&>();
  test_member_function_pointer<void (Class::*)(int,...) &&>();
  test_member_function_pointer<void (Class::*)(int, char,...) &&>();

  test_member_function_pointer<void (Class::*)() const &&>();
  test_member_function_pointer<void (Class::*)(int) const &&>();
  test_member_function_pointer<void (Class::*)(int, char) const &&>();
  test_member_function_pointer<void (Class::*)(...) const &&>();
  test_member_function_pointer<void (Class::*)(int,...) const &&>();
  test_member_function_pointer<void (Class::*)(int, char,...) const &&>();

  test_member_function_pointer<void (Class::*)() volatile &&>();
  test_member_function_pointer<void (Class::*)(int) volatile &&>();
  test_member_function_pointer<void (Class::*)(int, char) volatile &&>();
  test_member_function_pointer<void (Class::*)(...) volatile &&>();
  test_member_function_pointer<void (Class::*)(int,...) volatile &&>();
  test_member_function_pointer<void (Class::*)(int, char,...) volatile &&>();

  test_member_function_pointer<void (Class::*)() const volatile &&>();
  test_member_function_pointer<void (Class::*)(int) const volatile &&>();
  test_member_function_pointer<void (Class::*)(int, char) const volatile &&>();
  test_member_function_pointer<void (Class::*)(...) const volatile &&>();
  test_member_function_pointer<void (Class::*)(int,...) const volatile &&>();
  test_member_function_pointer<void (Class::*)(int, char,...) const volatile &&>();

  // RValue qualifiers with noexcept
  test_member_function_pointer<void (Class::*)() && noexcept>();
  test_member_function_pointer<void (Class::*)(int) && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) && noexcept>();
  test_member_function_pointer<void (Class::*)(...) && noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) && noexcept>();

  test_member_function_pointer<void (Class::*)() const && noexcept>();
  test_member_function_pointer<void (Class::*)(int) const && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) const && noexcept>();
  test_member_function_pointer<void (Class::*)(...) const && noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) const && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) const && noexcept>();

  test_member_function_pointer<void (Class::*)() volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int) volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(...) volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) volatile && noexcept>();

  test_member_function_pointer<void (Class::*)() const volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int) const volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char) const volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(...) const volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int,...) const volatile && noexcept>();
  test_member_function_pointer<void (Class::*)(int, char,...) const volatile && noexcept>();
#endif

//  LWG#2582
  static_assert(!std::is_member_function_pointer<incomplete_type>::value, "");
}