1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2f4a2713aSLionel Sambuc
3f4a2713aSLionel Sambuc struct X0 { // expected-note 8{{candidate}}
4f4a2713aSLionel Sambuc X0(int*, float*); // expected-note 4{{candidate}}
5f4a2713aSLionel Sambuc };
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc template<typename T, typename U>
f0(T t,U u)8f4a2713aSLionel Sambuc X0 f0(T t, U u) {
9f4a2713aSLionel Sambuc X0 x0(t, u); // expected-error{{no matching}}
10f4a2713aSLionel Sambuc return X0(t, u); // expected-error{{no matching}}
11f4a2713aSLionel Sambuc }
12f4a2713aSLionel Sambuc
test_f0(int * ip,float * fp,double * dp)13f4a2713aSLionel Sambuc void test_f0(int *ip, float *fp, double *dp) {
14f4a2713aSLionel Sambuc f0(ip, fp);
15f4a2713aSLionel Sambuc f0(ip, dp); // expected-note{{instantiation}}
16f4a2713aSLionel Sambuc }
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc template<typename Ret, typename T, typename U>
f1(Ret * retty,T t,U u)19f4a2713aSLionel Sambuc Ret f1(Ret *retty, T t, U u) {
20f4a2713aSLionel Sambuc Ret r0(t, u); // expected-error{{no matching}}
21f4a2713aSLionel Sambuc return Ret(t, u); // expected-error{{no matching}}
22f4a2713aSLionel Sambuc }
23f4a2713aSLionel Sambuc
test_f1(X0 * x0,int * ip,float * fp,double * dp)24f4a2713aSLionel Sambuc void test_f1(X0 *x0, int *ip, float *fp, double *dp) {
25f4a2713aSLionel Sambuc f1(x0, ip, fp);
26f4a2713aSLionel Sambuc f1(x0, ip, dp); // expected-note{{instantiation}}
27f4a2713aSLionel Sambuc }
28f4a2713aSLionel Sambuc
29f4a2713aSLionel Sambuc namespace PR6457 {
XPR6457::X30f4a2713aSLionel Sambuc template <typename T> struct X { explicit X(T* p = 0) { }; };
31f4a2713aSLionel Sambuc template <typename T> struct Y { Y(int, const T& x); };
32f4a2713aSLionel Sambuc struct A { };
33f4a2713aSLionel Sambuc template <typename T>
34f4a2713aSLionel Sambuc struct B {
BPR6457::B35f4a2713aSLionel Sambuc B() : y(0, X<A>()) { }
36f4a2713aSLionel Sambuc Y<X<A> > y;
37f4a2713aSLionel Sambuc };
38f4a2713aSLionel Sambuc B<int> b;
39f4a2713aSLionel Sambuc }
40f4a2713aSLionel Sambuc
41f4a2713aSLionel Sambuc namespace PR6657 {
42f4a2713aSLionel Sambuc struct X
43f4a2713aSLionel Sambuc {
XPR6657::X44f4a2713aSLionel Sambuc X (int, int) { }
45f4a2713aSLionel Sambuc };
46f4a2713aSLionel Sambuc
47f4a2713aSLionel Sambuc template <typename>
f0()48f4a2713aSLionel Sambuc void f0()
49f4a2713aSLionel Sambuc {
50f4a2713aSLionel Sambuc X x = X(0, 0);
51f4a2713aSLionel Sambuc }
52f4a2713aSLionel Sambuc
f1()53f4a2713aSLionel Sambuc void f1()
54f4a2713aSLionel Sambuc {
55f4a2713aSLionel Sambuc f0<int>();
56f4a2713aSLionel Sambuc }
57f4a2713aSLionel Sambuc }
58f4a2713aSLionel Sambuc
59f4a2713aSLionel Sambuc // Instantiate out-of-line definitions of static data members which complete
60f4a2713aSLionel Sambuc // types through an initializer even when the only use of the member that would
61f4a2713aSLionel Sambuc // cause instantiation is in an unevaluated context, but one requiring its
62f4a2713aSLionel Sambuc // complete type.
63f4a2713aSLionel Sambuc namespace PR10001 {
64f4a2713aSLionel Sambuc template <typename T> struct S {
65f4a2713aSLionel Sambuc static const int arr[];
66f4a2713aSLionel Sambuc static const int x;
67f4a2713aSLionel Sambuc static int f();
68f4a2713aSLionel Sambuc };
69f4a2713aSLionel Sambuc
70f4a2713aSLionel Sambuc template <typename T> const int S<T>::arr[] = { 1, 2, 3 };
71f4a2713aSLionel Sambuc template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]);
f()72f4a2713aSLionel Sambuc template <typename T> int S<T>::f() { return x; }
73f4a2713aSLionel Sambuc
74f4a2713aSLionel Sambuc int x = S<int>::f();
75f4a2713aSLionel Sambuc }
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc namespace PR7985 {
78f4a2713aSLionel Sambuc template<int N> struct integral_c { };
79f4a2713aSLionel Sambuc
80f4a2713aSLionel Sambuc template <typename T, int N>
array_lengthof(T (& x)[N])81f4a2713aSLionel Sambuc 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<}}
82f4a2713aSLionel Sambuc
83f4a2713aSLionel Sambuc template<typename T>
84f4a2713aSLionel Sambuc struct Data {
85f4a2713aSLionel Sambuc T x;
86f4a2713aSLionel Sambuc };
87f4a2713aSLionel Sambuc
88f4a2713aSLionel Sambuc template<typename T>
89f4a2713aSLionel Sambuc struct Description {
90f4a2713aSLionel Sambuc static const Data<T> data[];
91f4a2713aSLionel Sambuc };
92f4a2713aSLionel Sambuc
93f4a2713aSLionel Sambuc template<typename T>
94f4a2713aSLionel Sambuc const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}}
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambuc template<>
97f4a2713aSLionel Sambuc const Data<float*> Description<float*>::data[];
98f4a2713aSLionel Sambuc
test()99f4a2713aSLionel Sambuc void test() {
100f4a2713aSLionel Sambuc integral_c<1> ic1 = array_lengthof(Description<int>::data);
101f4a2713aSLionel Sambuc (void)sizeof(array_lengthof(Description<float>::data));
102f4a2713aSLionel Sambuc
103f4a2713aSLionel Sambuc sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
104f4a2713aSLionel Sambuc Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
105f4a2713aSLionel Sambuc ));
106f4a2713aSLionel Sambuc
107f4a2713aSLionel Sambuc array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}}
108f4a2713aSLionel Sambuc }
109f4a2713aSLionel Sambuc }
110f4a2713aSLionel Sambuc
111f4a2713aSLionel Sambuc namespace PR13064 {
112f4a2713aSLionel Sambuc // Ensure that in-class direct-initialization is instantiated as
113f4a2713aSLionel Sambuc // direct-initialization and likewise copy-initialization is instantiated as
114f4a2713aSLionel Sambuc // copy-initialization.
115f4a2713aSLionel Sambuc struct A { explicit A(int); }; // expected-note{{here}}
116f4a2713aSLionel Sambuc template<typename T> struct B { T a { 0 }; };
117f4a2713aSLionel Sambuc B<A> b;
118*0a6a1f1dSLionel Sambuc // expected-note@+1 {{in instantiation of default member initializer}}
119f4a2713aSLionel Sambuc template<typename T> struct C { T a = { 0 }; }; // expected-error{{explicit}}
120f4a2713aSLionel Sambuc C<A> c; // expected-note{{here}}
121f4a2713aSLionel Sambuc }
122f4a2713aSLionel Sambuc
123f4a2713aSLionel Sambuc namespace PR16903 {
124f4a2713aSLionel Sambuc // Make sure we properly instantiate list-initialization.
125f4a2713aSLionel Sambuc template<typename T>
fun(T it)126f4a2713aSLionel Sambuc void fun (T it) {
127f4a2713aSLionel Sambuc int m = 0;
128f4a2713aSLionel Sambuc for (int i = 0; i < 4; ++i, ++it){
129f4a2713aSLionel Sambuc m |= long{char{*it}};
130f4a2713aSLionel Sambuc }
131f4a2713aSLionel Sambuc }
test()132f4a2713aSLionel Sambuc int test() {
133f4a2713aSLionel Sambuc char in[4] = {0,0,0,0};
134f4a2713aSLionel Sambuc fun(in);
135f4a2713aSLionel Sambuc }
136f4a2713aSLionel Sambuc }
137*0a6a1f1dSLionel Sambuc
138*0a6a1f1dSLionel Sambuc namespace ReturnStmtIsInitialization {
139*0a6a1f1dSLionel Sambuc struct X {
XReturnStmtIsInitialization::X140*0a6a1f1dSLionel Sambuc X() {}
141*0a6a1f1dSLionel Sambuc X(const X &) = delete;
142*0a6a1f1dSLionel Sambuc };
f()143*0a6a1f1dSLionel Sambuc template<typename T> X f() { return {}; }
144*0a6a1f1dSLionel Sambuc auto &&x = f<void>();
145*0a6a1f1dSLionel Sambuc }
146