xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/ms-function-specialization-class-scope.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify %s
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc class A {
5f4a2713aSLionel Sambuc public:
A(U p)6*0a6a1f1dSLionel Sambuc   template<class U> A(U p) {}
A(int p)7*0a6a1f1dSLionel Sambuc   template<> A(int p) {
8*0a6a1f1dSLionel Sambuc     // expected-warning@-1 {{explicit specialization of 'A' within class scope is a Microsoft extension}}
9f4a2713aSLionel Sambuc   }
10f4a2713aSLionel Sambuc 
f(U p)11*0a6a1f1dSLionel Sambuc   template<class U> void f(U p) {}
12*0a6a1f1dSLionel Sambuc 
f(int p)13*0a6a1f1dSLionel Sambuc   template<> void f(int p) {
14*0a6a1f1dSLionel Sambuc     // expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
15f4a2713aSLionel Sambuc   }
16f4a2713aSLionel Sambuc 
f(int p)17*0a6a1f1dSLionel Sambuc   void f(int p) {}
18f4a2713aSLionel Sambuc };
19f4a2713aSLionel Sambuc 
test1()20*0a6a1f1dSLionel Sambuc void test1() {
21f4a2713aSLionel Sambuc   A a(3);
22f4a2713aSLionel Sambuc   char *b;
23f4a2713aSLionel Sambuc   a.f(b);
24f4a2713aSLionel Sambuc   a.f<int>(99);
25f4a2713aSLionel Sambuc   a.f(100);
26f4a2713aSLionel Sambuc }
27f4a2713aSLionel Sambuc 
28*0a6a1f1dSLionel Sambuc template<class T> class B {
29f4a2713aSLionel Sambuc public:
B(U p)30*0a6a1f1dSLionel Sambuc   template<class U> B(U p) {}
B(int p)31*0a6a1f1dSLionel Sambuc   template<> B(int p) {
32*0a6a1f1dSLionel Sambuc     // expected-warning@-1 {{explicit specialization of 'B<T>' within class scope is a Microsoft extension}}
33f4a2713aSLionel Sambuc   }
34f4a2713aSLionel Sambuc 
f(U p)35*0a6a1f1dSLionel Sambuc   template<class U> void f(U p) { T y = 9; }
36f4a2713aSLionel Sambuc 
f(int p)37*0a6a1f1dSLionel Sambuc   template<> void f(int p) {
38*0a6a1f1dSLionel Sambuc     // expected-warning@-1 {{explicit specialization of 'f' within class scope is a Microsoft extension}}
39f4a2713aSLionel Sambuc     T a = 3;
40f4a2713aSLionel Sambuc   }
41f4a2713aSLionel Sambuc 
f(int p)42*0a6a1f1dSLionel Sambuc   void f(int p) { T a = 3; }
43f4a2713aSLionel Sambuc };
44f4a2713aSLionel Sambuc 
test2()45*0a6a1f1dSLionel Sambuc void test2() {
46f4a2713aSLionel Sambuc   B<char> b(3);
47f4a2713aSLionel Sambuc   char *ptr;
48f4a2713aSLionel Sambuc   b.f(ptr);
49f4a2713aSLionel Sambuc   b.f<int>(99);
50f4a2713aSLionel Sambuc   b.f(100);
51f4a2713aSLionel Sambuc }
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc namespace PR12709 {
54*0a6a1f1dSLionel Sambuc   template<class T> class TemplateClass {
member_function()55*0a6a1f1dSLionel Sambuc     void member_function() { specialized_member_template<false>(); }
56f4a2713aSLionel Sambuc 
specialized_member_template()57*0a6a1f1dSLionel Sambuc     template<bool b> void specialized_member_template() {}
58*0a6a1f1dSLionel Sambuc 
specialized_member_template()59*0a6a1f1dSLionel Sambuc     template<> void specialized_member_template<false>() {
60*0a6a1f1dSLionel Sambuc       // expected-warning@-1 {{explicit specialization of 'specialized_member_template' within class scope is a Microsoft extension}}
61f4a2713aSLionel Sambuc     }
62f4a2713aSLionel Sambuc   };
63f4a2713aSLionel Sambuc 
f()64*0a6a1f1dSLionel Sambuc   void f() { TemplateClass<int> t; }
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc namespace Duplicates {
68*0a6a1f1dSLionel Sambuc   template<typename T> struct A {
69*0a6a1f1dSLionel Sambuc     template<typename U> void f();
fDuplicates::A70*0a6a1f1dSLionel Sambuc     template<> void f<int>() {} // expected-warning {{Microsoft extension}}
fDuplicates::A71*0a6a1f1dSLionel Sambuc     template<> void f<T>() {} // expected-warning {{Microsoft extension}}
72*0a6a1f1dSLionel Sambuc   };
73*0a6a1f1dSLionel Sambuc 
74*0a6a1f1dSLionel Sambuc   // FIXME: We should diagnose the duplicate explicit specialization definitions
75*0a6a1f1dSLionel Sambuc   // here.
76*0a6a1f1dSLionel Sambuc   template struct A<int>;
77f4a2713aSLionel Sambuc }
78