blob: 3b88700c540bded0f549938e6f935c4a457324ea [file] [log] [blame]
Douglas Gregor5f62c5e2009-05-14 23:26:13 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor5f62c5e2009-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 Gregorbd5c81c2009-05-14 23:40:54 +000014
15template<typename T>
16struct X2 {
17 void f(T);
18
19 T g(T x, T y) {
Douglas Gregorb06585a2009-05-15 00:01:03 +000020 /* DeclStmt */;
21 T *xp = &x, &yr = y; // expected-error{{pointer to a reference}}
Douglas Gregorbd5c81c2009-05-14 23:40:54 +000022 /* NullStmt */;
23 }
24};
25
26template struct X2<int>;
Douglas Gregorb06585a2009-05-15 00:01:03 +000027template struct X2<int&>; // expected-note{{instantiation of}}
Anders Carlsson23daf412009-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 Carlsson92358ae2009-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
50template struct X4<void>; // expected-note{{in instantiation of template class 'X4<void>' requested here}}
51template struct X4<int>; // expected-note{{in instantiation of template class 'X4<int>' requested here}}
Douglas Gregor556d8c72009-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 Gregor30033492009-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 Gregor4850df62009-05-15 21:18:27 +000067 else {
68 if (t < 0)
69 return v; // expected-error{{incompatible type}}
70 }
71
72 return v;
Douglas Gregor30033492009-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 Carlssonabf6af42009-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 Gregorcbe3be62009-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>;