1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
6 class C
{ C(int a0
= 0); };
11 struct S
{ }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
12 #if __cplusplus >= 201103L // C++11 or later
13 // expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}
16 template<typename T
> void f1(T a
, T b
= 10) { } // expected-error{{no viable conversion}} \
17 // expected-note{{passing argument to parameter 'b' here}}
19 template<typename T
> void f2(T a
, T b
= T()) { }
21 template<typename T
> void f3(T a
, T b
= T() + T()); // expected-error{{invalid operands to binary expression ('S' and 'S')}}
25 f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}}
31 f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<S>' required here}}
34 template<typename T
> struct F
{
35 F(T t
= 10); // expected-error{{no viable conversion}} \
36 // expected-note{{passing argument to parameter 't' here}}
37 void f(T t
= 10); // expected-error{{no viable conversion}} \
38 // expected-note{{passing argument to parameter 't' here}}
41 struct FD
: F
<int> { };
48 void g3(F
<int> f
, F
<struct S
> s
) {
50 s
.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}}
53 F
<S
> s2
; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}}
56 template<typename T
> struct G
{
60 void s(G
<int> flags
= 10) { }
62 // Test default arguments
65 void f(T
= T()); // expected-error{{no matching}}
71 void test_x0(X0
<int> xi
) {
76 struct NotDefaultConstructible
{ // expected-note 2 {{candidate constructor (the implicit copy constructor) not viable}}
77 #if __cplusplus >= 201103L // C++11 or later
78 // expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}}
80 NotDefaultConstructible(int); // expected-note 2{{candidate}}
83 void test_x0_not_default_constructible(X0
<NotDefaultConstructible
> xn
) {
84 xn
.f(NotDefaultConstructible(17));
86 xn
.f(); // expected-note{{in instantiation of default function argument}}
92 X1(const value_type
& value
= value_type());
101 void operator()(T
= T()); // expected-error{{no matching}}
104 void test_x2(X2
<int> x2i
, X2
<NotDefaultConstructible
> x2n
) {
107 x2n(NotDefaultConstructible(17));
108 x2n(); // expected-note{{in instantiation of default function argument}}
113 template<typename T
> struct A
{
114 A(T
= 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}} \
115 // expected-note 3{{passing argument to parameter here}}
121 B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
123 struct C
: virtual A
<int*> {
126 C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
133 D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
138 void f(int, int = 0);
140 template <typename T
>
146 template <typename T
>
163 allocator() { int a
[sizeof(T
) ? -1 : -1]; } // expected-error2 {{array with a negative size}}
168 vector(const allocator
<T
>& = allocator
<T
>()) {} // expected-note2 {{instantiation of}}
190 X
<float> x
; // expected-note{{member function}}
194 template<typename T
> void f4(T
, int = 17);
195 template<> void f4
<int>(int, int);
197 void f4_test(int i
) {
201 // Instantiate for initialization
202 namespace InstForInit
{
211 Holder(int i
, Ptr
<T
> ptr
= 0);
214 void test_holder(int i
) {
223 double**** not_it
= t
;
226 void f(int = broken
<int>());
235 double *****p
= t
; // expected-error{{cannot initialize a variable of type 'double *****' with an lvalue of type 'int'}}
240 struct Y
: X
<int> { // expected-note{{instantiation of}}
249 template< typename T
> class PointerClass
{
251 PointerClass( T
* object_p
) : p_( object_p
) {
258 class ExternallyImplementedClass
;
261 void foo( PointerClass
<ExternallyImplementedClass
> = 0 );
265 namespace rdar8427926
{
270 double *******ptr
= t
; // expected-error 2{{cannot initialize}}
277 void f(Boom
<int> = Boom
<int>()) { } // expected-note{{requested here}}
278 void g(int x
= (delete bfp
, 0)); // expected-note{{requested here}}
290 A() { T
* x
= 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
295 B(const A
<T
>& a
= A
<T
>()); // expected-note{{in instantiation of}}
298 void f(B
<int> b
= B
<int>());
307 template < typename
> struct A
;
308 template < typename MatrixType
, int =
309 A
< MatrixType
>::Flags
? : A
< MatrixType
>::Flags
& a
> class B
;
317 template <typename T
> struct move_from
{
321 struct unordered_map
{
322 explicit unordered_map(int n
= 42);
323 unordered_map(move_from
<K
> other
);
326 void StripedHashTable() {
327 new unordered_map
<void>();
328 new unordered_map
<void>;
331 StripedHashTable
<int>();