xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/extern-templates.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc template<typename T>
4*f4a2713aSLionel Sambuc class X0 {
5*f4a2713aSLionel Sambuc public:
6*f4a2713aSLionel Sambuc   void f(T t);
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc   struct Inner {
9*f4a2713aSLionel Sambuc     void g(T t);
10*f4a2713aSLionel Sambuc   };
11*f4a2713aSLionel Sambuc };
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc template<typename T>
f(T t)14*f4a2713aSLionel Sambuc void X0<T>::f(T t) {
15*f4a2713aSLionel Sambuc   t = 17; // expected-error{{incompatible}}
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc extern template class X0<int>;
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc extern template class X0<int*>;
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc template<typename T>
g(T t)23*f4a2713aSLionel Sambuc void X0<T>::Inner::g(T t) {
24*f4a2713aSLionel Sambuc   t = 17; // expected-error{{incompatible}}
25*f4a2713aSLionel Sambuc }
26*f4a2713aSLionel Sambuc 
test_intptr(X0<int * > xi,X0<int * >::Inner xii)27*f4a2713aSLionel Sambuc void test_intptr(X0<int*> xi, X0<int*>::Inner xii) {
28*f4a2713aSLionel Sambuc   xi.f(0);
29*f4a2713aSLionel Sambuc   xii.g(0);
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc extern template class X0<long*>;
33*f4a2713aSLionel Sambuc 
test_longptr(X0<long * > xl,X0<long * >::Inner xli)34*f4a2713aSLionel Sambuc void test_longptr(X0<long*> xl, X0<long*>::Inner xli) {
35*f4a2713aSLionel Sambuc   xl.f(0);
36*f4a2713aSLionel Sambuc   xli.g(0);
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
39*f4a2713aSLionel Sambuc template class X0<long*>; // expected-note 2{{instantiation}}
40*f4a2713aSLionel Sambuc 
41*f4a2713aSLionel Sambuc template<typename T>
42*f4a2713aSLionel Sambuc class X1 {
43*f4a2713aSLionel Sambuc public:
f(T t)44*f4a2713aSLionel Sambuc   void f(T t) { t += 2; }
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc   void g(T t);
47*f4a2713aSLionel Sambuc };
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc template<typename T>
g(T t)50*f4a2713aSLionel Sambuc void X1<T>::g(T t) {
51*f4a2713aSLionel Sambuc   t += 2;
52*f4a2713aSLionel Sambuc }
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc extern template class X1<void*>;
55*f4a2713aSLionel Sambuc 
g_X1(X1<void * > x1,void * ptr)56*f4a2713aSLionel Sambuc void g_X1(X1<void*> x1, void *ptr) {
57*f4a2713aSLionel Sambuc   x1.g(ptr);
58*f4a2713aSLionel Sambuc }
59*f4a2713aSLionel Sambuc 
60*f4a2713aSLionel Sambuc extern template void X1<const void*>::g(const void*);
61*f4a2713aSLionel Sambuc 
g_X1_2(X1<const void * > x1,const void * ptr)62*f4a2713aSLionel Sambuc void g_X1_2(X1<const void *> x1, const void *ptr) {
63*f4a2713aSLionel Sambuc   x1.g(ptr);
64*f4a2713aSLionel Sambuc }
65