Debian Codegraph @

clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp

raw
1 // RUN: %clang_cc1 -fms-extensions -fsyntax-only -Wno-unused-value -verify %s
2 // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -Wno-unused-value -verify %s
3
4 class A {
5 public:
6 template<class U> A(U p) {}
7 template<> A(int p) {}
8
9 template<class U> void f(U p) {}
10
11 template<> void f(int p) {}
12
13 void f(int p) {}
14 };
15
16 void test1() {
17 A a(3);
18 char *b;
19 a.f(b);
20 a.f<int>(99);
21 a.f(100);
22 }
23
24 template<class T> class B {
25 public:
26 template<class U> B(U p) {}
27 template<> B(int p) {}
28
29 template<class U> void f(U p) { T y = 9; }
30
31 template<> void f(int p) {
32 T a = 3;
33 }
34
35 void f(int p) { T a = 3; }
36 };
37
38 void test2() {
39 B<char> b(3);
40 char *ptr;
41 b.f(ptr);
42 b.f<int>(99);
43 b.f(100);
44 }
45
46 namespace PR12709 {
47 template<class T> class TemplateClass {
48 void member_function() { specialized_member_template<false>(); }
49
50 template<bool b> void specialized_member_template() {}
51
52 template<> void specialized_member_template<false>() {}
53 };
54
55 void f() { TemplateClass<int> t; }
56 }
57
58 namespace Duplicates {
59 template<typename T> struct A {
60 template<typename U> void f();
61 template<> void f<int>() {}
62 template<> void f<T>() {}
63 };
64
65 // FIXME: We should diagnose the duplicate explicit specialization definitions
66 // here.
67 template struct A<int>;
68 }
69
70 namespace PR28082 {
71 struct S {
72 template <int>
73 int f(int = 0);
74 template <>
75 int f<0>(int);
76 };
77 }
78
79 namespace UsesThis {
80 template<typename T>
81 struct A {
82 int x;
83
84 static inline int y;
85
86 template<typename U = void>
87 static void f();
88
89 template<typename U = void>
90 void g();
91
92 template<typename U>
93 static auto h() -> A*;
94
95 void i();
96
97 static void j();
98
99 template<>
100 void f<int>() {
101 this->x; // expected-error {{invalid use of 'this' outside of a non-static member function}}
102 x; // expected-error {{invalid use of member 'x' in static member function}}
103 A::x; // expected-error {{invalid use of member 'x' in static member function}}
104 +x; // expected-error {{invalid use of member 'x' in static member function}}
105 +A::x; // expected-error {{invalid use of member 'x' in static member function}}
106 &x; // expected-error {{invalid use of member 'x' in static member function}}
107 &A::x;
108 this->y; // expected-error {{invalid use of 'this' outside of a non-static member function}}
109 y;
110 A::y;
111 +y;
112 +A::y;
113 &y;
114 &A::y;
115 f();
116 f<void>();
117 g(); // expected-error {{call to non-static member function without an object argument}}
118 g<void>(); // expected-error {{call to non-static member function without an object argument}}
119 i(); // expected-error {{call to non-static member function without an object argument}}
120 j();
121 &i; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
122 &j;
123 &A::i;
124 &A::j;
125 }
126
127 template<>
128 void g<int>() {
129 this->x;
130 x;
131 A::x;
132 +x;
133 +A::x;
134 &x;
135 &A::x;
136 this->y;
137 y;
138 A::y;
139 +y;
140 +A::y;
141 &y;
142 &A::y;
143 f();
144 f<void>();
145 g();
146 g<void>();
147 i();
148 j();
149 &i; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
150 &j;
151 &A::i;
152 &A::j;
153 }
154
155 template<>
156 auto h<int>() -> decltype(this); // expected-error {{'this' cannot be used in a static member function declaration}}
157 };
158
159 template struct A<int>; // expected-note 3{{in instantiation of}}
160
161 template <typename T>
162 struct Foo {
163 template <typename X>
164 int bar(X x) {
165 return 0;
166 }
167
168 template <>
169 int bar(int x) {
170 return bar(5.0); // ok
171 }
172 };
173
174 void call() {
175 Foo<double> f;
176 f.bar(1);
177 }
178
179 struct B {
180 int x0;
181 static inline int y0;
182
183 int f0(int);
184 static int g0(int);
185
186 int x2;
187 static inline int y2;
188
189 int f2(int);
190 static int g2(int);
191 };
192
193 template<typename T>
194 struct D : B {
195 int x1;
196 static inline int y1;
197
198 int f1(int);
199 static int g1(int);
200
201 using B::x2;
202 using B::y2;
203 using B::f2;
204 using B::g2;
205
206 template<typename U>
207 void non_static_spec(U);
208
209 template<typename U>
210 static void static_spec(U);
211
212 template<>
213 void non_static_spec(int z) {
214 ++z;
215 ++x0;
216 ++x1;
217 ++x2;
218 ++y0;
219 ++y1;
220 ++y2;
221
222 &z;
223 &x0;
224 &x1;
225 &x2;
226 &y0;
227 &y1;
228 &y2;
229
230 &f0; // expected-error {{must explicitly qualify name of member function when taking its address}}
231 &f1; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
232 &f2; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
233 &g0;
234 &g1;
235 &g2;
236
237 &B::x0;
238 &D::x1;
239 &B::x2;
240 &B::y0;
241 &D::y1;
242 &B::y2;
243 &B::f0;
244 &D::f1;
245 &B::f2;
246 &B::g0;
247 &D::g1;
248 &B::g2;
249
250 f0(0);
251 f0(z);
252 f0(x0);
253 f0(x1);
254 f0(x2);
255 f0(y0);
256 f0(y1);
257 f0(y2);
258 g0(0);
259 g0(z);
260 g0(x0);
261 g0(x1);
262 g0(x2);
263 g0(y0);
264 g0(y1);
265 g0(y2);
266
267 f1(0);
268 f1(z);
269 f1(x0);
270 f1(x1);
271 f1(x2);
272 f1(y0);
273 f1(y1);
274 f1(y2);
275 g1(0);
276 g1(z);
277 g1(x0);
278 g1(x1);
279 g1(x2);
280 g1(y0);
281 g1(y1);
282 g1(y2);
283
284 f2(0);
285 f2(z);
286 f2(x0);
287 f2(x1);
288 f2(x2);
289 f2(y0);
290 f2(y1);
291 f2(y2);
292 g2(0);
293 g2(z);
294 g2(x0);
295 g2(x1);
296 g2(x2);
297 g2(y0);
298 g2(y1);
299 g2(y2);
300 }
301
302 template<>
303 void static_spec(int z) {
304 ++z;
305 ++x0; // expected-error {{invalid use of member 'x0' in static member function}}
306 ++x1; // expected-error {{invalid use of member 'x1' in static member function}}
307 ++x2; // expected-error {{invalid use of member 'x2' in static member function}}
308 ++y0;
309 ++y1;
310 ++y2;
311
312 &z;
313 &x0; // expected-error {{invalid use of member 'x0' in static member function}}
314 &x1; // expected-error {{invalid use of member 'x1' in static member function}}
315 &x2; // expected-error {{invalid use of member 'x2' in static member function}}
316 &y0;
317 &y1;
318 &y2;
319
320 &f0; // expected-error {{must explicitly qualify name of member function when taking its address}}
321 &f1; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
322 &f2; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
323 &g0;
324 &g1;
325 &g2;
326
327 &B::x0;
328 &D::x1;
329 &B::x2;
330 &B::y0;
331 &D::y1;
332 &B::y2;
333 &B::f0;
334 &D::f1;
335 &B::f2;
336 &B::g0;
337 &D::g1;
338 &B::g2;
339
340 f0(0); // expected-error {{call to non-static member function without an object argument}}
341 f0(z); // expected-error {{call to non-static member function without an object argument}}
342 f0(x0); // expected-error {{call to non-static member function without an object argument}}
343 f0(x1); // expected-error {{call to non-static member function without an object argument}}
344 f0(x2); // expected-error {{call to non-static member function without an object argument}}
345 f0(y0); // expected-error {{call to non-static member function without an object argument}}
346 f0(y1); // expected-error {{call to non-static member function without an object argument}}
347 f0(y2); // expected-error {{call to non-static member function without an object argument}}
348 g0(0);
349 g0(z);
350 g0(x0); // expected-error {{invalid use of member 'x0' in static member function}}
351 g0(x1); // expected-error {{invalid use of member 'x1' in static member function}}
352 g0(x2); // expected-error {{invalid use of member 'x2' in static member function}}
353 g0(y0);
354 g0(y1);
355 g0(y2);
356
357 f1(0); // expected-error {{call to non-static member function without an object argument}}
358 f1(z); // expected-error {{call to non-static member function without an object argument}}
359 f1(x0); // expected-error {{call to non-static member function without an object argument}}
360 f1(x1); // expected-error {{call to non-static member function without an object argument}}
361 f1(x2); // expected-error {{call to non-static member function without an object argument}}
362 f1(y0); // expected-error {{call to non-static member function without an object argument}}
363 f1(y1); // expected-error {{call to non-static member function without an object argument}}
364 f1(y2); // expected-error {{call to non-static member function without an object argument}}
365 g1(0);
366 g1(z);
367 g1(x0); // expected-error {{invalid use of member 'x0' in static member function}}
368 g1(x1); // expected-error {{invalid use of member 'x1' in static member function}}
369 g1(x2); // expected-error {{invalid use of member 'x2' in static member function}}
370 g1(y0);
371 g1(y1);
372 g1(y2);
373
374 f2(0); // expected-error {{call to non-static member function without an object argument}}
375 f2(z); // expected-error {{call to non-static member function without an object argument}}
376 f2(x0); // expected-error {{call to non-static member function without an object argument}}
377 f2(x1); // expected-error {{call to non-static member function without an object argument}}
378 f2(x2); // expected-error {{call to non-static member function without an object argument}}
379 f2(y0); // expected-error {{call to non-static member function without an object argument}}
380 f2(y1); // expected-error {{call to non-static member function without an object argument}}
381 f2(y2); // expected-error {{call to non-static member function without an object argument}}
382 g2(0);
383 g2(z);
384 g2(x0); // expected-error {{invalid use of member 'x0' in static member function}}
385 g2(x1); // expected-error {{invalid use of member 'x1' in static member function}}
386 g2(x2); // expected-error {{invalid use of member 'x2' in static member function}}
387 g2(y0);
388 g2(y1);
389 g2(y2);
390 }
391 };
392
393 template struct D<int>; // expected-note 2{{in instantiation of}}
394
395 template<typename T>
396 struct E : T {
397 int x1;
398 static inline int y1;
399
400 int f1(int);
401 static int g1(int);
402
403 using T::x0;
404 using T::y0;
405 using T::f0;
406 using T::g0;
407
408 template<typename U>
409 void non_static_spec(U);
410
411 template<typename U>
412 static void static_spec(U);
413
414 template<>
415 void non_static_spec(int z) {
416 ++z;
417 ++x0;
418 ++x1;
419 ++y0;
420 ++y1;
421
422 &z;
423 &x0;
424 &x1;
425 &y0;
426 &y1;
427
428 &f0; // expected-error {{must explicitly qualify name of member function when taking its address}}
429 &f1; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
430 &g0;
431 &g1;
432
433 &T::x0;
434 &E::x1;
435 &T::y0;
436 &E::y1;
437 &T::f0;
438 &E::f1;
439 &T::g0;
440 &E::g1;
441
442 f0(0);
443 f0(z);
444 f0(x0);
445 f0(x1);
446 f0(y0);
447 f0(y1);
448 g0(0);
449 g0(z);
450 g0(x0);
451 g0(x1);
452 g0(y0);
453 g0(y1);
454
455 f1(0);
456 f1(z);
457 f1(x0);
458 f1(x1);
459 f1(y0);
460 f1(y1);
461 g1(0);
462 g1(z);
463 g1(x0);
464 g1(x1);
465 g1(y0);
466 g1(y1);
467
468 T::f0(0);
469 T::f0(z);
470 T::f0(x0);
471 T::f0(x1);
472 T::f0(y0);
473 T::f0(y1);
474 T::g0(0);
475 T::g0(z);
476 T::g0(x0);
477 T::g0(x1);
478 T::g0(y0);
479 T::g0(y1);
480
481 E::f1(0);
482 E::f1(z);
483 E::f1(x0);
484 E::f1(x1);
485 E::f1(y0);
486 E::f1(y1);
487 E::g1(0);
488 E::g1(z);
489 E::g1(x0);
490 E::g1(x1);
491 E::g1(y0);
492 E::g1(y1);
493 }
494
495 template<>
496 void static_spec(int z) {
497 ++z;
498 ++x0; // expected-error {{invalid use of member 'x0' in static member function}}
499 ++x1; // expected-error {{invalid use of member 'x1' in static member function}}
500 ++y0;
501 ++y1;
502
503 &z;
504 &x0; // expected-error {{invalid use of member 'x0' in static member function}}
505 &x1; // expected-error {{invalid use of member 'x1' in static member function}}
506 &y0;
507 &y1;
508
509 &f0; // expected-error {{must explicitly qualify name of member function when taking its address}}
510 &f1; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
511 &g0;
512 &g1;
513
514 &T::x0;
515 &E::x1;
516 &T::y0;
517 &E::y1;
518 &T::f0;
519 &E::f1;
520 &T::g0;
521 &E::g1;
522
523 f0(0); // expected-error {{call to non-static member function without an object argument}}
524 f0(z); // expected-error {{call to non-static member function without an object argument}}
525 f0(x0); // expected-error {{call to non-static member function without an object argument}}
526 f0(x1); // expected-error {{call to non-static member function without an object argument}}
527 f0(y0); // expected-error {{call to non-static member function without an object argument}}
528 f0(y1); // expected-error {{call to non-static member function without an object argument}}
529 g0(0);
530 g0(z);
531 g0(x0); // expected-error {{invalid use of member 'x0' in static member function}}
532 g0(x1); // expected-error {{invalid use of member 'x1' in static member function}}
533 g0(y0);
534 g0(y1);
535
536 f1(0); // expected-error {{call to non-static member function without an object argument}}
537 f1(z); // expected-error {{call to non-static member function without an object argument}}
538 f1(x0); // expected-error {{call to non-static member function without an object argument}}
539 f1(x1); // expected-error {{call to non-static member function without an object argument}}
540 f1(y0); // expected-error {{call to non-static member function without an object argument}}
541 f1(y1); // expected-error {{call to non-static member function without an object argument}}
542 g1(0);
543 g1(z);
544 g1(x0); // expected-error {{invalid use of member 'x0' in static member function}}
545 g1(x1); // expected-error {{invalid use of member 'x1' in static member function}}
546 g1(y0);
547 g1(y1);
548
549 T::f0(0); // expected-error {{call to non-static member function without an object argument}}
550 T::f0(z); // expected-error {{call to non-static member function without an object argument}}
551 T::f0(x0); // expected-error {{call to non-static member function without an object argument}}
552 T::f0(x1); // expected-error {{call to non-static member function without an object argument}}
553 T::f0(y0); // expected-error {{call to non-static member function without an object argument}}
554 T::f0(y1); // expected-error {{call to non-static member function without an object argument}}
555 T::g0(0);
556 T::g0(z);
557 T::g0(x0); // expected-error {{invalid use of member 'x0' in static member function}}
558 T::g0(x1); // expected-error {{invalid use of member 'x1' in static member function}}
559 T::g0(y0);
560 T::g0(y1);
561
562 E::f1(0); // expected-error {{call to non-static member function without an object argument}}
563 E::f1(z); // expected-error {{call to non-static member function without an object argument}}
564 E::f1(x0); // expected-error {{call to non-static member function without an object argument}}
565 E::f1(x1); // expected-error {{call to non-static member function without an object argument}}
566 E::f1(y0); // expected-error {{call to non-static member function without an object argument}}
567 E::f1(y1); // expected-error {{call to non-static member function without an object argument}}
568 E::g1(0);
569 E::g1(z);
570 E::g1(x0); // expected-error {{invalid use of member 'x0' in static member function}}
571 E::g1(x1); // expected-error {{invalid use of member 'x1' in static member function}}
572 E::g1(y0);
573 E::g1(y1);
574 }
575 };
576
577 template struct E<B>; // expected-note 2{{in instantiation of}}
578
579 }