Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | d85cef5 | 2009-09-17 19:51:30 +0000 | [diff] [blame] | 2 | template<typename T> |
| 3 | class C { C(int a0 = 0); }; |
| 4 | |
| 5 | template<> |
| 6 | C<char>::C(int a0); |
| 7 | |
John McCall | 220ccbf | 2010-01-13 00:25:19 +0000 | [diff] [blame] | 8 | struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 9 | |
Douglas Gregor | 7abfbdb | 2009-12-19 03:01:41 +0000 | [diff] [blame] | 10 | template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 11 | |
| 12 | template<typename T> void f2(T a, T b = T()) { } |
| 13 | |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 14 | template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('S' and 'S')}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 15 | |
| 16 | void g() { |
| 17 | f1(10); |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 18 | f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 19 | |
| 20 | f2(10); |
| 21 | f2(S()); |
| 22 | |
| 23 | f3(10); |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 24 | f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<S>' required here}} |
Anders Carlsson | 9351c17 | 2009-08-25 03:18:48 +0000 | [diff] [blame] | 25 | } |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 26 | |
| 27 | template<typename T> struct F { |
Douglas Gregor | 7abfbdb | 2009-12-19 03:01:41 +0000 | [diff] [blame] | 28 | F(T t = 10); // expected-error{{no viable conversion}} |
| 29 | void f(T t = 10); // expected-error{{no viable conversion}} |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
Douglas Gregor | 0b84a53 | 2009-08-25 15:24:38 +0000 | [diff] [blame] | 32 | struct FD : F<int> { }; |
| 33 | |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 34 | void g2() { |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 35 | F<int> f; |
Douglas Gregor | 0b84a53 | 2009-08-25 15:24:38 +0000 | [diff] [blame] | 36 | FD fd; |
Anders Carlsson | 8644aec | 2009-08-25 13:07:08 +0000 | [diff] [blame] | 37 | } |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 38 | |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 39 | void g3(F<int> f, F<struct S> s) { |
| 40 | f.f(); |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 41 | s.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}} |
Anders Carlsson | 21e1c4e | 2009-09-06 16:54:02 +0000 | [diff] [blame] | 42 | |
| 43 | F<int> f2; |
John McCall | 7c2342d | 2010-03-10 11:27:22 +0000 | [diff] [blame] | 44 | F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}} |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 47 | template<typename T> struct G { |
Anders Carlsson | 25cae7f | 2009-09-05 05:14:19 +0000 | [diff] [blame] | 48 | G(T) {} |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | void s(G<int> flags = 10) { } |
| 52 | |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 53 | // Test default arguments |
| 54 | template<typename T> |
| 55 | struct X0 { |
| 56 | void f(T = T()); // expected-error{{no matching}} |
| 57 | }; |
Anders Carlsson | 5653ca5 | 2009-08-25 13:46:13 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 59 | template<typename U> |
| 60 | void X0<U>::f(U) { } |
Anders Carlsson | 6bc107b | 2009-09-05 05:38:54 +0000 | [diff] [blame] | 61 | |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 62 | void test_x0(X0<int> xi) { |
| 63 | xi.f(); |
| 64 | xi.f(17); |
| 65 | } |
| 66 | |
Douglas Gregor | d47c47d | 2009-11-09 19:27:57 +0000 | [diff] [blame] | 67 | struct NotDefaultConstructible { // expected-note 2{{candidate}} |
| 68 | NotDefaultConstructible(int); // expected-note 2{{candidate}} |
Douglas Gregor | 6cc1518 | 2009-09-11 18:44:32 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) { |
| 72 | xn.f(NotDefaultConstructible(17)); |
| 73 | xn.f(42); |
| 74 | xn.f(); // expected-note{{in instantiation of default function argument}} |
| 75 | } |
Douglas Gregor | e95b409 | 2009-09-16 18:34:49 +0000 | [diff] [blame] | 76 | |
| 77 | template<typename T> |
| 78 | struct X1 { |
| 79 | typedef T value_type; |
| 80 | X1(const value_type& value = value_type()); |
| 81 | }; |
| 82 | |
| 83 | void test_X1() { |
| 84 | X1<int> x1; |
| 85 | } |
Anders Carlsson | 0ebb6d3 | 2009-10-29 15:46:07 +0000 | [diff] [blame] | 86 | |
Douglas Gregor | d47c47d | 2009-11-09 19:27:57 +0000 | [diff] [blame] | 87 | template<typename T> |
| 88 | struct X2 { |
| 89 | void operator()(T = T()); // expected-error{{no matching}} |
| 90 | }; |
| 91 | |
| 92 | void test_x2(X2<int> x2i, X2<NotDefaultConstructible> x2n) { |
| 93 | x2i(); |
| 94 | x2i(17); |
| 95 | x2n(NotDefaultConstructible(17)); |
| 96 | x2n(); // expected-note{{in instantiation of default function argument}} |
| 97 | } |
| 98 | |
Anders Carlsson | 0ebb6d3 | 2009-10-29 15:46:07 +0000 | [diff] [blame] | 99 | // PR5283 |
| 100 | namespace PR5283 { |
| 101 | template<typename T> struct A { |
Eli Friedman | 4a2c19b | 2009-12-22 02:46:13 +0000 | [diff] [blame] | 102 | A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}} |
Anders Carlsson | 0ebb6d3 | 2009-10-29 15:46:07 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | struct B : A<int*> { |
| 106 | B(); |
| 107 | }; |
| 108 | B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}} |
| 109 | |
| 110 | struct C : virtual A<int*> { |
| 111 | C(); |
| 112 | }; |
| 113 | C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}} |
| 114 | |
| 115 | struct D { |
| 116 | D(); |
| 117 | |
| 118 | A<int*> a; |
| 119 | }; |
| 120 | D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}} |
| 121 | } |
Sebastian Redl | a29e51b | 2009-11-08 13:56:19 +0000 | [diff] [blame] | 122 | |
| 123 | // PR5301 |
| 124 | namespace pr5301 { |
| 125 | void f(int, int = 0); |
| 126 | |
| 127 | template <typename T> |
| 128 | void g(T, T = 0); |
| 129 | |
| 130 | template <int I> |
| 131 | void i(int a = I); |
| 132 | |
| 133 | template <typename T> |
| 134 | void h(T t) { |
| 135 | f(0); |
| 136 | g(1); |
| 137 | g(t); |
| 138 | i<2>(); |
| 139 | } |
| 140 | |
| 141 | void test() { |
| 142 | h(0); |
| 143 | } |
| 144 | } |
Douglas Gregor | d47c47d | 2009-11-09 19:27:57 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 146 | // PR5810 |
| 147 | namespace PR5810 { |
| 148 | template<typename T> |
| 149 | struct allocator { |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 150 | allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array size is negative}} |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | template<typename T> |
| 154 | struct vector { |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 155 | vector(const allocator<T>& = allocator<T>()) {} // expected-note2 {{instantiation of}} |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | struct A { }; |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 159 | struct B { }; |
| 160 | |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 161 | template<typename> |
| 162 | void FilterVTs() { |
| 163 | vector<A> Result; |
| 164 | } |
| 165 | |
| 166 | void f() { |
| 167 | vector<A> Result; |
| 168 | } |
Douglas Gregor | 036aed1 | 2009-12-23 23:03:06 +0000 | [diff] [blame] | 169 | |
| 170 | template<typename T> |
| 171 | struct X { |
| 172 | vector<B> bs; |
| 173 | X() { } |
| 174 | }; |
| 175 | |
| 176 | void f2() { |
| 177 | X<float> x; // expected-note{{member function}} |
| 178 | } |
Douglas Gregor | 65222e8 | 2009-12-23 18:19:08 +0000 | [diff] [blame] | 179 | } |
Douglas Gregor | 525f96c | 2010-02-05 07:33:43 +0000 | [diff] [blame] | 180 | |
| 181 | template<typename T> void f4(T, int = 17); |
| 182 | template<> void f4<int>(int, int); |
| 183 | |
| 184 | void f4_test(int i) { |
| 185 | f4(i); |
| 186 | } |