blob: 575283ed8b513b9fcaf384b4ed238ae0617ce33c [file] [log] [blame]
Anders Carlsson9351c172009-08-25 03:18:48 +00001// RUN: clang-cc -fsyntax-only -verify %s
2
Douglas Gregord85cef52009-09-17 19:51:30 +00003template<typename T>
4class C { C(int a0 = 0); };
5
6template<>
7C<char>::C(int a0);
8
Anders Carlsson9351c172009-08-25 03:18:48 +00009struct S { };
10
11template<typename T> void f1(T a, T b = 10) { } // expected-error{{cannot initialize 'b' with an rvalue of type 'int'}}
12
13template<typename T> void f2(T a, T b = T()) { }
14
15template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('struct S' and 'struct S')}}
16
17void g() {
18 f1(10);
Anders Carlsson25cae7f2009-09-05 05:14:19 +000019 f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<struct S>' required here}}
Anders Carlsson9351c172009-08-25 03:18:48 +000020
21 f2(10);
22 f2(S());
23
24 f3(10);
Anders Carlsson25cae7f2009-09-05 05:14:19 +000025 f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<struct S>' required here}}
Anders Carlsson9351c172009-08-25 03:18:48 +000026}
Anders Carlsson8644aec2009-08-25 13:07:08 +000027
28template<typename T> struct F {
Anders Carlsson21e1c4e2009-09-06 16:54:02 +000029 F(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}}
Anders Carlsson6bc107b2009-09-05 05:38:54 +000030 void f(T t = 10); // expected-error{{cannot initialize 't' with an rvalue of type 'int'}}
Anders Carlsson8644aec2009-08-25 13:07:08 +000031};
32
Douglas Gregor0b84a532009-08-25 15:24:38 +000033struct FD : F<int> { };
34
Anders Carlsson8644aec2009-08-25 13:07:08 +000035void g2() {
Anders Carlsson25cae7f2009-09-05 05:14:19 +000036 F<int> f;
Douglas Gregor0b84a532009-08-25 15:24:38 +000037 FD fd;
Anders Carlsson8644aec2009-08-25 13:07:08 +000038}
Anders Carlsson5653ca52009-08-25 13:46:13 +000039
Anders Carlsson6bc107b2009-09-05 05:38:54 +000040void g3(F<int> f, F<struct S> s) {
41 f.f();
42 s.f(); // expected-note{{in instantiation of default function argument expression for 'f<struct S>' required here}}
Anders Carlsson21e1c4e2009-09-06 16:54:02 +000043
44 F<int> f2;
45 F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<struct S>' required here}}
Anders Carlsson6bc107b2009-09-05 05:38:54 +000046}
47
Anders Carlsson5653ca52009-08-25 13:46:13 +000048template<typename T> struct G {
Anders Carlsson25cae7f2009-09-05 05:14:19 +000049 G(T) {}
Anders Carlsson5653ca52009-08-25 13:46:13 +000050};
51
52void s(G<int> flags = 10) { }
53
Douglas Gregor6cc15182009-09-11 18:44:32 +000054// Test default arguments
55template<typename T>
56struct X0 {
57 void f(T = T()); // expected-error{{no matching}}
58};
Anders Carlsson5653ca52009-08-25 13:46:13 +000059
Douglas Gregor6cc15182009-09-11 18:44:32 +000060template<typename U>
61void X0<U>::f(U) { }
Anders Carlsson6bc107b2009-09-05 05:38:54 +000062
Douglas Gregor6cc15182009-09-11 18:44:32 +000063void test_x0(X0<int> xi) {
64 xi.f();
65 xi.f(17);
66}
67
68struct NotDefaultConstructible { // expected-note{{candidate}}
69 NotDefaultConstructible(int); // expected-note{{candidate}}
70};
71
72void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) {
73 xn.f(NotDefaultConstructible(17));
74 xn.f(42);
75 xn.f(); // expected-note{{in instantiation of default function argument}}
76}
Douglas Gregore95b4092009-09-16 18:34:49 +000077
78template<typename T>
79struct X1 {
80 typedef T value_type;
81 X1(const value_type& value = value_type());
82};
83
84void test_X1() {
85 X1<int> x1;
86}