1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3 namespace std {
4 template<typename T> struct initializer_list {
5 T *p;
6 __SIZE_TYPE__ n;
7 initializer_list(T*, __SIZE_TYPE__);
8 };
9 }
10
11 struct X0 { // expected-note 8{{candidate}}
12 X0(int*, float*); // expected-note 4{{candidate}}
13 };
14
15 template<typename T, typename U>
f0(T t,U u)16 X0 f0(T t, U u) {
17 X0 x0(t, u); // expected-error{{no matching}}
18 return X0(t, u); // expected-error{{no matching}}
19 }
20
test_f0(int * ip,float * fp,double * dp)21 void test_f0(int *ip, float *fp, double *dp) {
22 f0(ip, fp);
23 f0(ip, dp); // expected-note{{instantiation}}
24 }
25
26 template<typename Ret, typename T, typename U>
f1(Ret * retty,T t,U 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}}
30 }
31
test_f1(X0 * x0,int * ip,float * fp,double * dp)32 void test_f1(X0 *x0, int *ip, float *fp, double *dp) {
33 f1(x0, ip, fp);
34 f1(x0, ip, dp); // expected-note{{instantiation}}
35 }
36
37 namespace PR6457 {
XPR6457::X38 template <typename T> struct X { explicit X(T* p = 0) { }; };
39 template <typename T> struct Y { Y(int, const T& x); };
40 struct A { };
41 template <typename T>
42 struct B {
BPR6457::B43 B() : y(0, X<A>()) { }
44 Y<X<A> > y;
45 };
46 B<int> b;
47 }
48
49 namespace PR6657 {
50 struct X
51 {
XPR6657::X52 X (int, int) { }
53 };
54
55 template <typename>
f0()56 void f0()
57 {
58 X x = X(0, 0);
59 }
60
f1()61 void f1()
62 {
63 f0<int>();
64 }
65 }
66
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
70 // complete type.
71 namespace PR10001 {
72 template <typename T> struct S {
73 static const int arr[];
74 static const int x;
75 static int f();
76 };
77
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]);
f()80 template <typename T> int S<T>::f() { return x; }
81
82 int x = S<int>::f();
83 }
84
85 namespace PR7985 {
86 template<int N> struct integral_c { };
87
88 template <typename T, int N>
array_lengthof(T (& x)[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<}}
90
91 template<typename T>
92 struct Data {
93 T x;
94 };
95
96 template<typename T>
97 struct Description {
98 static const Data<T> data[];
99 };
100
101 template<typename T>
102 const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}}
103
104 template<>
105 const Data<float*> Description<float*>::data[];
106
test()107 void test() {
108 integral_c<1> ic1 = array_lengthof(Description<int>::data);
109 (void)sizeof(array_lengthof(Description<float>::data));
110
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}}
113 ));
114
115 array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}}
116 }
117 }
118
119 namespace PR13064 {
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 }; };
125 B<A> b;
126 template <typename T> struct C { // expected-note {{in instantiation of default member initializer}}
127 T a = {0}; // expected-error{{explicit}}
128 };
129 C<A> c; // expected-note {{in evaluation of exception spec}}
130 }
131
132 namespace PR16903 {
133 // Make sure we properly instantiate list-initialization.
134 template<typename T>
fun(T it)135 void fun (T it) {
136 int m = 0;
137 for (int i = 0; i < 4; ++i, ++it){
138 m |= long{char{*it}};
139 }
140 }
test()141 int test() {
142 char in[4] = {0,0,0,0};
143 fun(in);
144 }
145 }
146
147 namespace ReturnStmtIsInitialization {
148 struct X {
XReturnStmtIsInitialization::X149 X() {}
150 X(const X &) = delete;
151 };
f()152 template<typename T> X f() { return {}; }
153 auto &&x = f<void>();
154 }
155
156 namespace InitListUpdate {
157 struct A { int n; };
158 using AA = A[1];
159
160 // Check that an init list update doesn't "lose" the pack-ness of an expression.
f()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}}
164 };
165
166 void g(AA, AA);
h()167 void h() { f<1, 2>(); } // expected-note {{instantiation of}}
168 }
169
170 namespace RebuildStdInitList {
ARebuildStdInitList::A171 struct A { A(std::initializer_list<int>, int = 0) {} };
172 struct B : A { using A::A; };
173 struct PES { PES(B); };
174
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.
f()178 template<typename U> void f() { PES({1, 2, 3}); }
g()179 void g() { f<int>(); }
180 }
181