Douglas Gregor | 5f62c5e | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | 5f62c5e | 2009-05-14 23:26:13 +0000 | [diff] [blame] | 2 | template<typename T, typename U> |
| 3 | struct X0 { |
| 4 | void f(T x, U y) { |
| 5 | x + y; // expected-error{{invalid operands}} |
| 6 | } |
| 7 | }; |
| 8 | |
| 9 | struct X1 { }; |
| 10 | |
| 11 | template struct X0<int, float>; |
| 12 | template struct X0<int*, int>; |
| 13 | template struct X0<int X1::*, int>; // expected-note{{instantiation of}} |
Douglas Gregor | bd5c81c | 2009-05-14 23:40:54 +0000 | [diff] [blame] | 14 | |
| 15 | template<typename T> |
| 16 | struct X2 { |
| 17 | void f(T); |
| 18 | |
| 19 | T g(T x, T y) { |
Douglas Gregor | b06585a | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 20 | /* DeclStmt */; |
| 21 | T *xp = &x, &yr = y; // expected-error{{pointer to a reference}} |
Douglas Gregor | bd5c81c | 2009-05-14 23:40:54 +0000 | [diff] [blame] | 22 | /* NullStmt */; |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | template struct X2<int>; |
Douglas Gregor | b06585a | 2009-05-15 00:01:03 +0000 | [diff] [blame] | 27 | template struct X2<int&>; // expected-note{{instantiation of}} |
Anders Carlsson | 23daf41 | 2009-05-15 00:15:26 +0000 | [diff] [blame] | 28 | |
| 29 | template<typename T> |
| 30 | struct X3 { |
| 31 | void f(T) { |
| 32 | Label: |
| 33 | T x; |
| 34 | goto Label; |
| 35 | } |
| 36 | }; |
| 37 | |
| 38 | template struct X3<int>; |
Anders Carlsson | 92358ae | 2009-05-15 00:48:27 +0000 | [diff] [blame] | 39 | |
| 40 | template <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 | |
| 50 | template struct X4<void>; // expected-note{{in instantiation of template class 'X4<void>' requested here}} |
| 51 | template struct X4<int>; // expected-note{{in instantiation of template class 'X4<int>' requested here}} |
Douglas Gregor | 556d8c7 | 2009-05-15 17:59:04 +0000 | [diff] [blame] | 52 | |
| 53 | struct Incomplete; // expected-note{{forward declaration}} |
| 54 | |
| 55 | template<typename T> struct X5 { |
| 56 | T f() { } // expected-error{{incomplete result type}} |
| 57 | }; |
| 58 | void test_X5(X5<Incomplete> x5); // okay! |
| 59 | |
| 60 | template struct X5<Incomplete>; // expected-note{{instantiation}} |
Douglas Gregor | 3003349 | 2009-05-15 18:53:42 +0000 | [diff] [blame] | 61 | |
| 62 | template<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 Gregor | 4850df6 | 2009-05-15 21:18:27 +0000 | [diff] [blame] | 67 | else { |
| 68 | if (t < 0) |
| 69 | return v; // expected-error{{incompatible type}} |
| 70 | } |
| 71 | |
| 72 | return v; |
Douglas Gregor | 3003349 | 2009-05-15 18:53:42 +0000 | [diff] [blame] | 73 | } |
| 74 | }; |
| 75 | |
| 76 | struct ConvertibleToInt { |
| 77 | operator int() const; |
| 78 | }; |
| 79 | |
| 80 | template struct X6<ConvertibleToInt, float, char>; |
| 81 | template struct X6<bool, int, int*>; // expected-note{{instantiation}} |
Anders Carlsson | abf6af4 | 2009-05-15 20:26:03 +0000 | [diff] [blame] | 82 | |
| 83 | template <typename T> struct X7 { |
| 84 | void f() { |
| 85 | void *v = this; |
| 86 | } |
| 87 | }; |
| 88 | |
| 89 | template struct X7<int>; |
Douglas Gregor | cbe3be6 | 2009-05-15 21:45:53 +0000 | [diff] [blame] | 90 | |
| 91 | template<typename T> struct While0 { |
| 92 | void f(T t) { |
| 93 | while (t) { |
| 94 | } |
| 95 | |
| 96 | while (T t2 = T()) ; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | template struct While0<float>; |
Douglas Gregor | ef48276 | 2009-05-15 21:56:04 +0000 | [diff] [blame] | 101 | |
| 102 | template<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 | |
| 112 | struct NotConvertibleToBool { }; |
| 113 | template struct Do0<ConvertibleToInt>; |
| 114 | template struct Do0<NotConvertibleToBool>; // expected-note{{instantiation}} |
Douglas Gregor | 1401330 | 2009-05-15 22:12:32 +0000 | [diff] [blame] | 115 | |
| 116 | template<typename T> struct For0 { |
| 117 | void f(T f, T l) { |
| 118 | for (; f != l; ++f) { |
Douglas Gregor | 777cc7a | 2009-05-15 22:32:39 +0000 | [diff] [blame^] | 119 | if (*f) |
| 120 | continue; |
| 121 | else if (*f == 17) |
| 122 | break; |
Douglas Gregor | 1401330 | 2009-05-15 22:12:32 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | }; |
| 126 | |
| 127 | template struct For0<int*>; |