1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 class C
{ C(int a0
= 0); };
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')}}
19 f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}}
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> { };
42 void g3(F
<int> f
, F
<struct S
> s
) {
44 s
.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}}
47 F
<S
> s2
; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}}
50 template<typename T
> struct G
{
54 void s(G
<int> flags
= 10) { }
56 // Test default arguments
59 void f(T
= T()); // expected-error{{no matching}}
65 void test_x0(X0
<int> xi
) {
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));
77 xn
.f(); // expected-note{{in instantiation of default function argument}}
83 X1(const value_type
& value
= value_type());
92 void operator()(T
= T()); // expected-error{{no matching}}
95 void test_x2(X2
<int> x2i
, X2
<NotDefaultConstructible
> x2n
) {
98 x2n(NotDefaultConstructible(17));
99 x2n(); // expected-note{{in instantiation of default function argument}}
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}}
112 B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
114 struct C
: virtual A
<int*> {
117 C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
124 D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
129 void f(int, int = 0);
131 template <typename T
>
137 template <typename T
>
154 allocator() { int a
[sizeof(T
) ? -1 : -1]; } // expected-error2 {{array with a negative size}}
159 vector(const allocator
<T
>& = allocator
<T
>()) {} // expected-note2 {{instantiation of}}
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
) {
192 // Instantiate for initialization
193 namespace InstForInit
{
202 Holder(int i
, Ptr
<T
> ptr
= 0);
205 void test_holder(int i
) {
214 double**** not_it
= t
;
217 void f(int = broken
<int>());
226 double *****p
= t
; // expected-error{{cannot initialize a variable of type 'double *****' with an lvalue of type 'int'}}
231 struct Y
: X
<int> { // expected-note{{instantiation of}}
240 template< typename T
> class PointerClass
{
242 PointerClass( T
* object_p
) : p_( object_p
) {
249 class ExternallyImplementedClass
;
252 void foo( PointerClass
<ExternallyImplementedClass
> = 0 );
256 namespace rdar8427926
{
261 double *******ptr
= t
; // expected-error 2{{cannot initialize}}
268 void f(Boom
<int> = Boom
<int>()) { } // expected-note{{requested here}}
269 void g(int x
= (delete bfp
, 0)); // expected-note{{requested here}}
281 A() { T
* x
= 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
286 B(const A
<T
>& a
= A
<T
>()); // expected-note{{in instantiation of}}
289 void f(B
<int> b
= B
<int>());