blob: d2cc45b0352b2e23d11032c0cb2d94df13fbb520 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregord85cef52009-09-17 19:51:30 +00002template<typename T>
3class C { C(int a0 = 0); };
4
5template<>
6C<char>::C(int a0);
7
John McCall220ccbf2010-01-13 00:25:19 +00008struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
Anders Carlsson9351c172009-08-25 03:18:48 +00009
Douglas Gregor7abfbdb2009-12-19 03:01:41 +000010template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}}
Anders Carlsson9351c172009-08-25 03:18:48 +000011
12template<typename T> void f2(T a, T b = T()) { }
13
John McCall7c2342d2010-03-10 11:27:22 +000014template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('S' and 'S')}}
Anders Carlsson9351c172009-08-25 03:18:48 +000015
16void g() {
17 f1(10);
John McCall7c2342d2010-03-10 11:27:22 +000018 f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}}
Anders Carlsson9351c172009-08-25 03:18:48 +000019
20 f2(10);
21 f2(S());
22
23 f3(10);
John McCall7c2342d2010-03-10 11:27:22 +000024 f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<S>' required here}}
Anders Carlsson9351c172009-08-25 03:18:48 +000025}
Anders Carlsson8644aec2009-08-25 13:07:08 +000026
27template<typename T> struct F {
Douglas Gregor7abfbdb2009-12-19 03:01:41 +000028 F(T t = 10); // expected-error{{no viable conversion}}
29 void f(T t = 10); // expected-error{{no viable conversion}}
Anders Carlsson8644aec2009-08-25 13:07:08 +000030};
31
Douglas Gregor0b84a532009-08-25 15:24:38 +000032struct FD : F<int> { };
33
Anders Carlsson8644aec2009-08-25 13:07:08 +000034void g2() {
Anders Carlsson25cae7f2009-09-05 05:14:19 +000035 F<int> f;
Douglas Gregor0b84a532009-08-25 15:24:38 +000036 FD fd;
Anders Carlsson8644aec2009-08-25 13:07:08 +000037}
Anders Carlsson5653ca52009-08-25 13:46:13 +000038
Anders Carlsson6bc107b2009-09-05 05:38:54 +000039void g3(F<int> f, F<struct S> s) {
40 f.f();
John McCall7c2342d2010-03-10 11:27:22 +000041 s.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}}
Anders Carlsson21e1c4e2009-09-06 16:54:02 +000042
43 F<int> f2;
John McCall7c2342d2010-03-10 11:27:22 +000044 F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}}
Anders Carlsson6bc107b2009-09-05 05:38:54 +000045}
46
Anders Carlsson5653ca52009-08-25 13:46:13 +000047template<typename T> struct G {
Anders Carlsson25cae7f2009-09-05 05:14:19 +000048 G(T) {}
Anders Carlsson5653ca52009-08-25 13:46:13 +000049};
50
51void s(G<int> flags = 10) { }
52
Douglas Gregor6cc15182009-09-11 18:44:32 +000053// Test default arguments
54template<typename T>
55struct X0 {
56 void f(T = T()); // expected-error{{no matching}}
57};
Anders Carlsson5653ca52009-08-25 13:46:13 +000058
Douglas Gregor6cc15182009-09-11 18:44:32 +000059template<typename U>
60void X0<U>::f(U) { }
Anders Carlsson6bc107b2009-09-05 05:38:54 +000061
Douglas Gregor6cc15182009-09-11 18:44:32 +000062void test_x0(X0<int> xi) {
63 xi.f();
64 xi.f(17);
65}
66
Douglas Gregord47c47d2009-11-09 19:27:57 +000067struct NotDefaultConstructible { // expected-note 2{{candidate}}
68 NotDefaultConstructible(int); // expected-note 2{{candidate}}
Douglas Gregor6cc15182009-09-11 18:44:32 +000069};
70
71void 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 Gregore95b4092009-09-16 18:34:49 +000076
77template<typename T>
78struct X1 {
79 typedef T value_type;
80 X1(const value_type& value = value_type());
81};
82
83void test_X1() {
84 X1<int> x1;
85}
Anders Carlsson0ebb6d32009-10-29 15:46:07 +000086
Douglas Gregord47c47d2009-11-09 19:27:57 +000087template<typename T>
88struct X2 {
89 void operator()(T = T()); // expected-error{{no matching}}
90};
91
92void 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 Carlsson0ebb6d32009-10-29 15:46:07 +000099// PR5283
100namespace PR5283 {
101template<typename T> struct A {
Eli Friedman4a2c19b2009-12-22 02:46:13 +0000102 A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}}
Anders Carlsson0ebb6d32009-10-29 15:46:07 +0000103};
104
105struct B : A<int*> {
106 B();
107};
108B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
109
110struct C : virtual A<int*> {
111 C();
112};
113C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
114
115struct D {
116 D();
117
118 A<int*> a;
119};
120D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
121}
Sebastian Redla29e51b2009-11-08 13:56:19 +0000122
123// PR5301
124namespace 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 Gregord47c47d2009-11-09 19:27:57 +0000145
Douglas Gregor65222e82009-12-23 18:19:08 +0000146// PR5810
147namespace PR5810 {
148 template<typename T>
149 struct allocator {
Douglas Gregor036aed12009-12-23 23:03:06 +0000150 allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array size is negative}}
Douglas Gregor65222e82009-12-23 18:19:08 +0000151 };
152
153 template<typename T>
154 struct vector {
Douglas Gregor036aed12009-12-23 23:03:06 +0000155 vector(const allocator<T>& = allocator<T>()) {} // expected-note2 {{instantiation of}}
Douglas Gregor65222e82009-12-23 18:19:08 +0000156 };
157
158 struct A { };
Douglas Gregor036aed12009-12-23 23:03:06 +0000159 struct B { };
160
Douglas Gregor65222e82009-12-23 18:19:08 +0000161 template<typename>
162 void FilterVTs() {
163 vector<A> Result;
164 }
165
166 void f() {
167 vector<A> Result;
168 }
Douglas Gregor036aed12009-12-23 23:03:06 +0000169
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 Gregor65222e82009-12-23 18:19:08 +0000179}
Douglas Gregor525f96c2010-02-05 07:33:43 +0000180
181template<typename T> void f4(T, int = 17);
182template<> void f4<int>(int, int);
183
184void f4_test(int i) {
185 f4(i);
186}