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
6 template<class U
> A(U p
) {}
9 template<class U
> void f(U p
) {}
11 template<> void f(int p
) {}
24 template<class T
> class B
{
26 template<class U
> B(U p
) {}
27 template<> B(int p
) {}
29 template<class U
> void f(U p
) { T y
= 9; }
31 template<> void f(int p
) {
35 void f(int p
) { T a
= 3; }
47 template<class T
> class TemplateClass
{
48 void member_function() { specialized_member_template
<false>(); }
50 template<bool b
> void specialized_member_template() {}
52 template<> void specialized_member_template
<false>() {}
55 void f() { TemplateClass
<int> t
; }
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
>() {}
65 // FIXME: We should diagnose the duplicate explicit specialization definitions
67 template struct A
<int>;
86 template<typename U
= void>
89 template<typename U
= void>
93 static auto h() -> A
*;
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}}
108 this->y
; // expected-error {{invalid use of 'this' outside of a non-static member function}}
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}}
121 &i
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
149 &i
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
156 auto h
<int>() -> decltype(this); // expected-error {{'this' cannot be used in a static member function declaration}}
159 template struct A
<int>; // expected-note {{in instantiation of}}
160 template<> template<> void A
<int>::f
<int>();
161 template<> template<> void A
<int>::g
<int>();
163 A
<int>().f
<int>(); // expected-note {{in instantiation of}}
164 A
<int>().g
<int>(); // expected-note {{in instantiation of}}
167 template <typename T
>
169 template <typename X
>
176 return bar(5.0); // ok
187 static inline int y0
;
193 static inline int y2
;
202 static inline int y1
;
213 void non_static_spec(U
);
216 static void static_spec(U
);
219 void non_static_spec(int z
) {
236 &f0
; // expected-error {{must explicitly qualify name of member function when taking its address}}
237 &f1
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
238 &f2
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
309 void static_spec(int z
) {
311 ++x0
; // expected-error {{invalid use of member 'x0' in static member function}}
312 ++x1
; // expected-error {{invalid use of member 'x1' in static member function}}
313 ++x2
; // expected-error {{invalid use of member 'x2' in static member function}}
319 &x0
; // expected-error {{invalid use of member 'x0' in static member function}}
320 &x1
; // expected-error {{invalid use of member 'x1' in static member function}}
321 &x2
; // expected-error {{invalid use of member 'x2' in static member function}}
326 &f0
; // expected-error {{must explicitly qualify name of member function when taking its address}}
327 &f1
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
328 &f2
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
346 f0(0); // expected-error {{call to non-static member function without an object argument}}
347 f0(z
); // expected-error {{call to non-static member function without an object argument}}
348 f0(x0
); // expected-error {{call to non-static member function without an object argument}}
349 f0(x1
); // expected-error {{call to non-static member function without an object argument}}
350 f0(x2
); // expected-error {{call to non-static member function without an object argument}}
351 f0(y0
); // expected-error {{call to non-static member function without an object argument}}
352 f0(y1
); // expected-error {{call to non-static member function without an object argument}}
353 f0(y2
); // expected-error {{call to non-static member function without an object argument}}
356 g0(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
357 g0(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
358 g0(x2
); // expected-error {{invalid use of member 'x2' in static member function}}
363 f1(0); // expected-error {{call to non-static member function without an object argument}}
364 f1(z
); // expected-error {{call to non-static member function without an object argument}}
365 f1(x0
); // expected-error {{call to non-static member function without an object argument}}
366 f1(x1
); // expected-error {{call to non-static member function without an object argument}}
367 f1(x2
); // expected-error {{call to non-static member function without an object argument}}
368 f1(y0
); // expected-error {{call to non-static member function without an object argument}}
369 f1(y1
); // expected-error {{call to non-static member function without an object argument}}
370 f1(y2
); // expected-error {{call to non-static member function without an object argument}}
373 g1(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
374 g1(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
375 g1(x2
); // expected-error {{invalid use of member 'x2' in static member function}}
380 f2(0); // expected-error {{call to non-static member function without an object argument}}
381 f2(z
); // expected-error {{call to non-static member function without an object argument}}
382 f2(x0
); // expected-error {{call to non-static member function without an object argument}}
383 f2(x1
); // expected-error {{call to non-static member function without an object argument}}
384 f2(x2
); // expected-error {{call to non-static member function without an object argument}}
385 f2(y0
); // expected-error {{call to non-static member function without an object argument}}
386 f2(y1
); // expected-error {{call to non-static member function without an object argument}}
387 f2(y2
); // expected-error {{call to non-static member function without an object argument}}
390 g2(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
391 g2(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
392 g2(x2
); // expected-error {{invalid use of member 'x2' in static member function}}
399 template struct D
<int>;
402 D
<int>().non_static_spec(0); // expected-note {{in instantiation of}}
403 D
<int>().static_spec(0); // expected-note {{in instantiation of}}
409 static inline int y1
;
420 void non_static_spec(U
);
423 static void static_spec(U
);
426 void non_static_spec(int z
) {
439 &f0
; // expected-error {{must explicitly qualify name of member function when taking its address}}
440 &f1
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
507 void static_spec(int z
) {
509 ++x0
; // expected-error {{invalid use of member 'x0' in static member function}}
510 ++x1
; // expected-error {{invalid use of member 'x1' in static member function}}
515 &x0
; // expected-error {{invalid use of member 'x0' in static member function}}
516 &x1
; // expected-error {{invalid use of member 'x1' in static member function}}
520 &f0
; // expected-error {{must explicitly qualify name of member function when taking its address}}
521 &f1
; // expected-error 2{{must explicitly qualify name of member function when taking its address}}
534 f0(0); // expected-error {{call to non-static member function without an object argument}}
535 f0(z
); // expected-error {{call to non-static member function without an object argument}}
536 f0(x0
); // expected-error {{call to non-static member function without an object argument}}
537 f0(x1
); // expected-error {{call to non-static member function without an object argument}}
538 f0(y0
); // expected-error {{call to non-static member function without an object argument}}
539 f0(y1
); // expected-error {{call to non-static member function without an object argument}}
542 g0(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
543 g0(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
547 f1(0); // expected-error {{call to non-static member function without an object argument}}
548 f1(z
); // expected-error {{call to non-static member function without an object argument}}
549 f1(x0
); // expected-error {{call to non-static member function without an object argument}}
550 f1(x1
); // expected-error {{call to non-static member function without an object argument}}
551 f1(y0
); // expected-error {{call to non-static member function without an object argument}}
552 f1(y1
); // expected-error {{call to non-static member function without an object argument}}
555 g1(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
556 g1(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
560 T::f0(0); // expected-error {{call to non-static member function without an object argument}}
561 T::f0(z
); // expected-error {{call to non-static member function without an object argument}}
562 T::f0(x0
); // expected-error {{call to non-static member function without an object argument}}
563 T::f0(x1
); // expected-error {{call to non-static member function without an object argument}}
564 T::f0(y0
); // expected-error {{call to non-static member function without an object argument}}
565 T::f0(y1
); // expected-error {{call to non-static member function without an object argument}}
568 T::g0(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
569 T::g0(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
573 E::f1(0); // expected-error {{call to non-static member function without an object argument}}
574 E::f1(z
); // expected-error {{call to non-static member function without an object argument}}
575 E::f1(x0
); // expected-error {{call to non-static member function without an object argument}}
576 E::f1(x1
); // expected-error {{call to non-static member function without an object argument}}
577 E::f1(y0
); // expected-error {{call to non-static member function without an object argument}}
578 E::f1(y1
); // expected-error {{call to non-static member function without an object argument}}
581 E::g1(x0
); // expected-error {{invalid use of member 'x0' in static member function}}
582 E::g1(x1
); // expected-error {{invalid use of member 'x1' in static member function}}
588 template struct E
<B
>;
591 E
<B
>().non_static_spec(0); // expected-note {{in instantiation of}}
592 E
<B
>().static_spec(0); // expected-note {{in instantiation of}}
597 template<class T
> struct S
{
598 template<int> auto foo();
599 template<> auto foo
<1>() {
600 return [](auto x
) { return x
; };
603 template struct S
<void>;
607 } // namespace GH111266