StmtPrinter: factor out arg printing code to PrintCallArgs
[clang.git] / test / SemaTemplate / default-expr-arguments.cpp
blob5d301be2fb13733b2f25dfda804fc56ec792c8ba
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 template<typename T>
3 class C { C(int a0 = 0); };
5 template<>
6 C<char>::C(int a0);
8 struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
10 template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}} \
11 // expected-note{{passing argument to parameter 'b' here}}
13 template<typename T> void f2(T a, T b = T()) { }
15 template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('S' and 'S')}}
17 void g() {
18 f1(10);
19 f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}}
21 f2(10);
22 f2(S());
24 f3(10);
25 f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<S>' required here}}
28 template<typename T> struct F {
29 F(T t = 10); // expected-error{{no viable conversion}} \
30 // expected-note{{passing argument to parameter 't' here}}
31 void f(T t = 10); // expected-error{{no viable conversion}} \
32 // expected-note{{passing argument to parameter 't' here}}
35 struct FD : F<int> { };
37 void g2() {
38 F<int> f;
39 FD fd;
42 void g3(F<int> f, F<struct S> s) {
43 f.f();
44 s.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}}
46 F<int> f2;
47 F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}}
50 template<typename T> struct G {
51 G(T) {}
54 void s(G<int> flags = 10) { }
56 // Test default arguments
57 template<typename T>
58 struct X0 {
59 void f(T = T()); // expected-error{{no matching}}
62 template<typename U>
63 void X0<U>::f(U) { }
65 void test_x0(X0<int> xi) {
66 xi.f();
67 xi.f(17);
70 struct NotDefaultConstructible { // expected-note 2{{candidate}}
71 NotDefaultConstructible(int); // expected-note 2{{candidate}}
74 void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) {
75 xn.f(NotDefaultConstructible(17));
76 xn.f(42);
77 xn.f(); // expected-note{{in instantiation of default function argument}}
80 template<typename T>
81 struct X1 {
82 typedef T value_type;
83 X1(const value_type& value = value_type());
86 void test_X1() {
87 X1<int> x1;
90 template<typename T>
91 struct X2 {
92 void operator()(T = T()); // expected-error{{no matching}}
95 void test_x2(X2<int> x2i, X2<NotDefaultConstructible> x2n) {
96 x2i();
97 x2i(17);
98 x2n(NotDefaultConstructible(17));
99 x2n(); // expected-note{{in instantiation of default function argument}}
102 // PR5283
103 namespace PR5283 {
104 template<typename T> struct A {
105 A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}} \
106 // expected-note 3{{passing argument to parameter here}}
109 struct B : A<int*> {
110 B();
112 B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
114 struct C : virtual A<int*> {
115 C();
117 C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
119 struct D {
120 D();
122 A<int*> a;
124 D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
127 // PR5301
128 namespace pr5301 {
129 void f(int, int = 0);
131 template <typename T>
132 void g(T, T = 0);
134 template <int I>
135 void i(int a = I);
137 template <typename T>
138 void h(T t) {
139 f(0);
140 g(1);
141 g(t);
142 i<2>();
145 void test() {
146 h(0);
150 // PR5810
151 namespace PR5810 {
152 template<typename T>
153 struct allocator {
154 allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array with a negative size}}
157 template<typename T>
158 struct vector {
159 vector(const allocator<T>& = allocator<T>()) {} // expected-note2 {{instantiation of}}
162 struct A { };
163 struct B { };
165 template<typename>
166 void FilterVTs() {
167 vector<A> Result;
170 void f() {
171 vector<A> Result;
174 template<typename T>
175 struct X {
176 vector<B> bs;
177 X() { }
180 void f2() {
181 X<float> x; // expected-note{{member function}}
185 template<typename T> void f4(T, int = 17);
186 template<> void f4<int>(int, int);
188 void f4_test(int i) {
189 f4(i);
192 // Instantiate for initialization
193 namespace InstForInit {
194 template<typename T>
195 struct Ptr {
196 typedef T* type;
197 Ptr(type);
200 template<typename T>
201 struct Holder {
202 Holder(int i, Ptr<T> ptr = 0);
205 void test_holder(int i) {
206 Holder<int> h(i);
210 namespace PR5810b {
211 template<typename T>
212 T broken() {
213 T t;
214 double**** not_it = t;
217 void f(int = broken<int>());
218 void g() { f(17); }
221 namespace PR5810c {
222 template<typename T>
223 struct X {
224 X() {
225 T t;
226 double *****p = t; // expected-error{{cannot initialize a variable of type 'double *****' with an lvalue of type 'int'}}
228 X(const X&) { }
231 struct Y : X<int> { // expected-note{{instantiation of}}
234 void f(Y y = Y());
236 void g() { f(); }
239 namespace PR8127 {
240 template< typename T > class PointerClass {
241 public:
242 PointerClass( T * object_p ) : p_( object_p ) {
243 p_->acquire();
245 private:
246 T * p_;
249 class ExternallyImplementedClass;
251 class MyClass {
252 void foo( PointerClass<ExternallyImplementedClass> = 0 );
256 namespace rdar8427926 {
257 template<typename T>
258 struct Boom {
259 ~Boom() {
260 T t;
261 double *******ptr = t; // expected-error 2{{cannot initialize}}
265 Boom<float> *bfp;
267 struct X {
268 void f(Boom<int> = Boom<int>()) { } // expected-note{{requested here}}
269 void g(int x = (delete bfp, 0)); // expected-note{{requested here}}
272 void test(X *x) {
273 x->f();
274 x->g();
278 namespace PR8401 {
279 template<typename T>
280 struct A {
281 A() { T* x = 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
284 template<typename T>
285 struct B {
286 B(const A<T>& a = A<T>()); // expected-note{{in instantiation of}}
289 void f(B<int> b = B<int>());
291 void g() {
292 f();