blob: 2b5ba5c891ee1e4243325be736e980cc56c5009f [file] [log] [blame]
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregore704c9d2009-08-27 16:57:43 +00002
3template<typename T>
4struct X0 {
5 template<typename U> T f0(U);
6 template<typename U> U& f1(T*, U); // expected-error{{pointer to a reference}} \
7 // expected-note{{candidate}}
8};
9
10X0<int> x0i;
11X0<void> x0v;
12X0<int&> x0ir; // expected-note{{instantiation}}
13
14void test_X0(int *ip, double *dp) {
15 X0<int> xi;
16 int i1 = xi.f0(ip);
17 double *&dpr = xi.f1(ip, dp);
18 xi.f1(dp, dp); // expected-error{{no matching}}
19
20 X0<void> xv;
21 double *&dpr2 = xv.f1(ip, dp);
22}
Douglas Gregora654dd82009-08-28 17:37:35 +000023
Douglas Gregor01afeef2009-08-28 20:31:08 +000024template<typename T>
25struct X1 {
26 template<typename U>
27 struct Inner0 {
28 U x;
29 T y; // expected-error{{void}}
30 };
31
32 template<typename U>
33 struct Inner1 {
34 U x; // expected-error{{void}}
Douglas Gregor39cacdb2009-08-28 20:50:45 +000035 T y;
36 };
37
38 template<typename U>
39 struct Inner2 {
40 struct SuperInner {
41 U z; // expected-error{{void}}
42 };
Douglas Gregor01afeef2009-08-28 20:31:08 +000043 };
Douglas Gregord99bb432009-08-28 21:09:48 +000044
45 template<typename U>
46 struct Inner3 {
47 void f0(T t, U u) {
48 (void)(t + u); // expected-error{{invalid operands}}
49 }
50
51 template<typename V>
52 V f1(T t, U u, V) {
Douglas Gregore1314a62009-12-18 05:02:21 +000053 return t + u; // expected-error{{cannot initialize return object}}
Douglas Gregord99bb432009-08-28 21:09:48 +000054 }
55 };
56
Douglas Gregor5c580932009-08-28 21:15:08 +000057 template<typename U>
58 struct Inner4;
Douglas Gregor01afeef2009-08-28 20:31:08 +000059};
60
Douglas Gregor5c580932009-08-28 21:15:08 +000061template<typename T>
62template<typename U>
63struct X1<T>::Inner4 {
64 template<typename V>
65 V f2(T t, U u, V);
Douglas Gregor11395b62009-08-28 21:41:19 +000066
67 static U value;
Douglas Gregor5c580932009-08-28 21:15:08 +000068};
69
70template<typename T>
71template<typename U>
Douglas Gregor11395b62009-08-28 21:41:19 +000072U X1<T>::Inner4<U>::value; // expected-error{{reference variable}}
73
74template<typename T>
75template<typename U>
Douglas Gregor5c580932009-08-28 21:15:08 +000076template<typename V>
77V X1<T>::Inner4<U>::f2(T t, U u, V) {
Douglas Gregore1314a62009-12-18 05:02:21 +000078 return t + u; // expected-error{{cannot initialize return object}}
Douglas Gregor5c580932009-08-28 21:15:08 +000079}
80
Douglas Gregord99bb432009-08-28 21:09:48 +000081void test_X1(int *ip, int i, double *dp) {
Douglas Gregor01afeef2009-08-28 20:31:08 +000082 X1<void>::Inner0<int> *xvip; // okay
83 X1<void>::Inner0<int> xvi; // expected-note{{instantiation}}
84
85 X1<int>::Inner1<void> *xivp; // okay
86 X1<int>::Inner1<void> xiv; // expected-note{{instantiation}}
Douglas Gregor39cacdb2009-08-28 20:50:45 +000087
88 X1<int>::Inner2<void>::SuperInner *xisivp; // okay
89 X1<int>::Inner2<void>::SuperInner xisiv; // expected-note{{instantiation}}
Douglas Gregord99bb432009-08-28 21:09:48 +000090
91 X1<int*>::Inner3<int> id3;
92 id3.f0(ip, i);
93 id3.f0(dp, i); // expected-error{{incompatible type}}
94 id3.f1(ip, i, ip);
95 id3.f1(ip, i, dp); // expected-note{{instantiation}}
96
97 X1<int*>::Inner3<double*> id3b;
98 id3b.f0(ip, dp); // expected-note{{instantiation}}
Douglas Gregor5c580932009-08-28 21:15:08 +000099
100 X1<int*>::Inner4<int> id4;
101 id4.f2(ip, i, dp); // expected-note{{instantiation}}
Douglas Gregor11395b62009-08-28 21:41:19 +0000102
103 X1<int*>::Inner4<int>::value = 17;
104 i = X1<int*>::Inner4<int&>::value; // expected-note{{instantiation}}
Douglas Gregor01afeef2009-08-28 20:31:08 +0000105}
Douglas Gregora8ab71b2009-11-09 18:29:00 +0000106
107
108template<typename T>
109struct X2 {
110 template<T *Ptr> // expected-error{{pointer to a reference}}
111 struct Inner;
112
113 template<T Value> // expected-error{{cannot have type 'float'}}
114 struct Inner2;
115};
116
117X2<int&> x2a; // expected-note{{instantiation}}
118X2<float> x2b; // expected-note{{instantiation}}
Douglas Gregor51c538b2009-11-20 19:42:02 +0000119
120namespace N0 {
121 template<typename T>
122 struct X0 { };
123
124 struct X1 {
125 template<typename T> void f(X0<T>& vals) { g(vals); }
126 template<typename T> void g(X0<T>& vals) { }
127 };
128
129 void test(X1 x1, X0<int> x0i, X0<long> x0l) {
130 x1.f(x0i);
131 x1.f(x0l);
132 }
133}