1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4 template<typename T
> struct initializer_list
{
7 initializer_list(T
*, __SIZE_TYPE__
);
11 struct X0
{ // expected-note 8{{candidate}}
12 X0(int*, float*); // expected-note 4{{candidate}}
15 template<typename T
, typename U
>
17 X0
x0(t
, u
); // expected-error{{no matching}}
18 return X0(t
, u
); // expected-error{{no matching}}
21 void test_f0(int *ip
, float *fp
, double *dp
) {
23 f0(ip
, dp
); // expected-note{{instantiation}}
26 template<typename Ret
, typename T
, typename U
>
27 Ret
f1(Ret
*retty
, T t
, U u
) {
28 Ret
r0(t
, u
); // expected-error{{no matching}}
29 return Ret(t
, u
); // expected-error{{no matching}}
32 void test_f1(X0
*x0
, int *ip
, float *fp
, double *dp
) {
34 f1(x0
, ip
, dp
); // expected-note{{instantiation}}
38 template <typename T
> struct X
{ explicit X(T
* p
= 0) { }; };
39 template <typename T
> struct Y
{ Y(int, const T
& x
); };
43 B() : y(0, X
<A
>()) { }
67 // Instantiate out-of-line definitions of static data members which complete
68 // types through an initializer even when the only use of the member that would
69 // cause instantiation is in an unevaluated context, but one requiring its
72 template <typename T
> struct S
{
73 static const int arr
[];
78 template <typename T
> const int S
<T
>::arr
[] = { 1, 2, 3 };
79 template <typename T
> const int S
<T
>::x
= sizeof(arr
) / sizeof(arr
[0]);
80 template <typename T
> int S
<T
>::f() { return x
; }
86 template<int N
> struct integral_c
{ };
88 template <typename T
, int N
>
89 integral_c
<N
> array_lengthof(T (&x
)[N
]) { return integral_c
<N
>(); } // expected-note 2{{candidate template ignored: could not match 'T[N]' against 'const Data<}}
98 static const Data
<T
> data
[];
102 const Data
<T
> Description
<T
>::data
[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}}
105 const Data
<float*> Description
<float*>::data
[];
108 integral_c
<1> ic1
= array_lengthof(Description
<int>::data
);
109 (void)sizeof(array_lengthof(Description
<float>::data
));
111 (void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
112 Description
<int*>::data
// expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
115 array_lengthof(Description
<float*>::data
); // expected-error{{no matching function for call to 'array_lengthof'}}
120 // Ensure that in-class direct-initialization is instantiated as
121 // direct-initialization and likewise copy-initialization is instantiated as
122 // copy-initialization.
123 struct A
{ explicit A(int); }; // expected-note{{here}}
124 template<typename T
> struct B
{ T a
{ 0 }; };
126 template <typename T
> struct C
{ // expected-note {{in instantiation of default member initializer}}
127 T a
= {0}; // expected-error{{explicit}}
129 C
<A
> c
; // expected-note {{in evaluation of exception spec}}
133 // Make sure we properly instantiate list-initialization.
137 for (int i
= 0; i
< 4; ++i
, ++it
){
138 m
|= long{char{*it
}};
142 char in
[4] = {0,0,0,0};
147 namespace ReturnStmtIsInitialization
{
150 X(const X
&) = delete;
152 template<typename T
> X
f() { return {}; }
153 auto &&x
= f
<void>();
156 namespace InitListUpdate
{
160 // Check that an init list update doesn't "lose" the pack-ness of an expression.
161 template <int... N
> void f() {
162 g(AA
{0, [0].n
= N
} ...); // expected-warning 3{{extension}} expected-note {{here}} expected-warning 3{{overrides prior init}} expected-note 3{{previous init}}
163 g(AA
{N
, [0].n
= 0} ...); // expected-warning 3{{extension}} expected-note {{here}} expected-warning 3{{overrides prior init}} expected-note 3{{previous init}}
167 void h() { f
<1, 2>(); } // expected-note {{instantiation of}}
170 namespace RebuildStdInitList
{
171 struct A
{ A(std::initializer_list
<int>, int = 0) {} };
172 struct B
: A
{ using A::A
; };
173 struct PES
{ PES(B
); };
175 // Check we can rebuild the use of the default argument here. This requires
176 // going to the original (base class) constructor, because we don't copy
177 // default arguments onto our fake derived class inherited constructors.
178 template<typename U
> void f() { PES({1, 2, 3}); }
179 void g() { f
<int>(); }