blob: d30055c9a1e12523e6d6503eaac324a4c1baba71 [file] [log] [blame]
Douglas Gregor1393d5e2009-05-18 17:02:28 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor54dabfc2009-05-14 23:26:13 +00002template<typename T, typename U>
3struct X0 {
4 void f(T x, U y) {
5 x + y; // expected-error{{invalid operands}}
6 }
7};
8
9struct X1 { };
10
11template struct X0<int, float>;
12template struct X0<int*, int>;
13template struct X0<int X1::*, int>; // expected-note{{instantiation of}}
Douglas Gregore7a18c82009-05-14 23:40:54 +000014
15template<typename T>
16struct X2 {
17 void f(T);
18
19 T g(T x, T y) {
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +000020 /* DeclStmt */;
21 T *xp = &x, &yr = y; // expected-error{{pointer to a reference}}
Douglas Gregore7a18c82009-05-14 23:40:54 +000022 /* NullStmt */;
23 }
24};
25
26template struct X2<int>;
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +000027template struct X2<int&>; // expected-note{{instantiation of}}
Anders Carlsson137fa562009-05-15 00:15:26 +000028
29template<typename T>
30struct X3 {
31 void f(T) {
32 Label:
33 T x;
34 goto Label;
35 }
36};
37
38template struct X3<int>;
Anders Carlsson03d77762009-05-15 00:48:27 +000039
40template <typename T> struct X4 {
41 T f() const {
42 return; // expected-warning{{non-void function 'f' should return a value}}
43 }
44
45 T g() const {
46 return 1; // expected-warning{{void function 'g' should not return a value}}
47 }
48};
49
Douglas Gregorf3e7ce42009-05-18 17:01:57 +000050template struct X4<void>; // expected-note{{in instantiation of}}
51template struct X4<int>; // expected-note{{in instantiation of}}
Douglas Gregore2c31ff2009-05-15 17:59:04 +000052
53struct Incomplete; // expected-note{{forward declaration}}
54
55template<typename T> struct X5 {
56 T f() { } // expected-error{{incomplete result type}}
57};
58void test_X5(X5<Incomplete> x5); // okay!
59
60template struct X5<Incomplete>; // expected-note{{instantiation}}
Douglas Gregord06f6ca2009-05-15 18:53:42 +000061
62template<typename T, typename U, typename V> struct X6 {
63 U f(T t, U u, V v) {
64 // IfStmt
65 if (t > 0)
66 return u;
Douglas Gregor49f25ec2009-05-15 21:18:27 +000067 else {
68 if (t < 0)
69 return v; // expected-error{{incompatible type}}
70 }
71
72 return v;
Douglas Gregord06f6ca2009-05-15 18:53:42 +000073 }
74};
75
76struct ConvertibleToInt {
77 operator int() const;
78};
79
80template struct X6<ConvertibleToInt, float, char>;
81template struct X6<bool, int, int*>; // expected-note{{instantiation}}
Anders Carlsson0712d292009-05-15 20:26:03 +000082
83template <typename T> struct X7 {
84 void f() {
85 void *v = this;
86 }
87};
88
89template struct X7<int>;
Douglas Gregor4a2e2042009-05-15 21:45:53 +000090
91template<typename T> struct While0 {
92 void f(T t) {
93 while (t) {
94 }
95
96 while (T t2 = T()) ;
97 }
98};
99
100template struct While0<float>;
Douglas Gregor9f3ca2a2009-05-15 21:56:04 +0000101
102template<typename T> struct Do0 {
103 void f(T t) {
104 do {
105 } while (t); // expected-error{{not contextually}}
106
107 do {
108 } while (T t2 = T());
109 }
110};
111
112struct NotConvertibleToBool { };
113template struct Do0<ConvertibleToInt>;
114template struct Do0<NotConvertibleToBool>; // expected-note{{instantiation}}
Douglas Gregor5831c6a2009-05-15 22:12:32 +0000115
116template<typename T> struct For0 {
117 void f(T f, T l) {
118 for (; f != l; ++f) {
Douglas Gregor861ce312009-05-15 22:32:39 +0000119 if (*f)
120 continue;
121 else if (*f == 17)
122 break;
Douglas Gregor5831c6a2009-05-15 22:12:32 +0000123 }
124 }
125};
126
127template struct For0<int*>;
Anders Carlssonffce2df2009-05-15 23:10:19 +0000128
129template<typename T> struct Member0 {
130 void f(T t) {
131 t;
132 t.f;
133 t->f;
134
135 T* tp;
136 tp.f; // expected-error{{member reference base type 'T *' is not a structure or union}}
137 tp->f;
138
139 this->f;
140 this.f; // expected-error{{member reference base type 'struct Member0 *const' is not a structure or union}}
141 }
142};
Douglas Gregordbb26db2009-05-15 23:57:33 +0000143
144template<typename T, typename U> struct Switch0 {
145 U f(T value, U v0, U v1, U v2) {
146 switch (value) {
147 case 0: return v0;
148
149 case 1: return v1;
150
151 case 2: // fall through
152
153 default:
154 return v2;
155 }
156 }
157};
158
159template struct Switch0<int, float>;
160
161template<typename T, int I1, int I2> struct Switch1 {
162 T f(T x, T y, T z) {
163 switch (x) {
164 case I1: return y; // expected-note{{previous}}
165 case I2: return z; // expected-error{{duplicate}}
166 default: return x;
167 }
168 }
169};
170
171template struct Switch1<int, 1, 2>;
172template struct Switch1<int, 2, 2>; // expected-note{{instantiation}}
Douglas Gregor5f1b9e62009-05-16 00:20:29 +0000173
174template<typename T> struct IndirectGoto0 {
175 void f(T x) {
176 // FIXME: crummy error message below
177 goto *x; // expected-error{{incompatible}}
178 }
179};
180
181template struct IndirectGoto0<void*>;
182template struct IndirectGoto0<int>; // expected-note{{instantiation}}