1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2f4a2713aSLionel Sambuc struct X0 { // expected-note{{candidate}}
3f4a2713aSLionel Sambuc X0(int); // expected-note{{candidate}}
4f4a2713aSLionel Sambuc template<typename T> X0(T); // expected-note {{candidate}}
5f4a2713aSLionel Sambuc template<typename T, typename U> X0(T*, U*); // expected-note {{candidate}}
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc // PR4761
X0X08f4a2713aSLionel Sambuc template<typename T> X0() : f0(T::foo) {} // expected-note {{candidate}}
9f4a2713aSLionel Sambuc int f0;
10f4a2713aSLionel Sambuc };
11f4a2713aSLionel Sambuc
12f4a2713aSLionel Sambuc void accept_X0(X0);
13f4a2713aSLionel Sambuc
test_X0(int i,float f)14f4a2713aSLionel Sambuc void test_X0(int i, float f) {
15f4a2713aSLionel Sambuc X0 x0a(i);
16f4a2713aSLionel Sambuc X0 x0b(f);
17f4a2713aSLionel Sambuc X0 x0c = i;
18f4a2713aSLionel Sambuc X0 x0d = f;
19f4a2713aSLionel Sambuc accept_X0(i);
20f4a2713aSLionel Sambuc accept_X0(&i);
21f4a2713aSLionel Sambuc accept_X0(f);
22f4a2713aSLionel Sambuc accept_X0(&f);
23f4a2713aSLionel Sambuc X0 x0e(&i, &f);
24f4a2713aSLionel Sambuc X0 x0f(&f, &i);
25f4a2713aSLionel Sambuc
26f4a2713aSLionel Sambuc X0 x0g(f, &i); // expected-error{{no matching constructor}}
27f4a2713aSLionel Sambuc }
28f4a2713aSLionel Sambuc
29f4a2713aSLionel Sambuc template<typename T>
30f4a2713aSLionel Sambuc struct X1 {
31f4a2713aSLionel Sambuc X1(const X1&);
32f4a2713aSLionel Sambuc template<typename U> X1(const X1<U>&);
33f4a2713aSLionel Sambuc };
34f4a2713aSLionel Sambuc
35f4a2713aSLionel Sambuc template<typename T>
36f4a2713aSLionel Sambuc struct Outer {
37f4a2713aSLionel Sambuc typedef X1<T> A;
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambuc A alloc;
40f4a2713aSLionel Sambuc
OuterOuter41f4a2713aSLionel Sambuc explicit Outer(const A& a) : alloc(a) { }
42f4a2713aSLionel Sambuc };
43f4a2713aSLionel Sambuc
test_X1(X1<int> xi)44f4a2713aSLionel Sambuc void test_X1(X1<int> xi) {
45f4a2713aSLionel Sambuc Outer<int> oi(xi);
46f4a2713aSLionel Sambuc Outer<float> of(xi);
47f4a2713aSLionel Sambuc }
48f4a2713aSLionel Sambuc
49f4a2713aSLionel Sambuc // PR4655
50f4a2713aSLionel Sambuc template<class C> struct A {};
51f4a2713aSLionel Sambuc template <> struct A<int>{A(const A<int>&);};
BB52f4a2713aSLionel Sambuc struct B { A<int> x; B(B& a) : x(a.x) {} };
53f4a2713aSLionel Sambuc
54f4a2713aSLionel Sambuc struct X2 {
55f4a2713aSLionel Sambuc X2(); // expected-note{{candidate constructor}}
56f4a2713aSLionel Sambuc X2(X2&); // expected-note {{candidate constructor}}
57*0a6a1f1dSLionel Sambuc template<typename T> X2(T); // expected-note {{candidate template ignored: instantiation would take its own class type by value}}
58f4a2713aSLionel Sambuc };
59f4a2713aSLionel Sambuc
test(bool Cond,X2 x2)60f4a2713aSLionel Sambuc X2 test(bool Cond, X2 x2) {
61f4a2713aSLionel Sambuc if (Cond)
62f4a2713aSLionel Sambuc return x2; // okay, uses copy constructor
63f4a2713aSLionel Sambuc
64f4a2713aSLionel Sambuc return X2(); // expected-error{{no matching constructor}}
65f4a2713aSLionel Sambuc }
66f4a2713aSLionel Sambuc
67f4a2713aSLionel Sambuc struct X3 {
68f4a2713aSLionel Sambuc template<typename T> X3(T);
69f4a2713aSLionel Sambuc };
70f4a2713aSLionel Sambuc
71f4a2713aSLionel Sambuc template<> X3::X3(X3); // expected-error{{must pass its first argument by reference}}
72f4a2713aSLionel Sambuc
73f4a2713aSLionel Sambuc struct X4 {
74f4a2713aSLionel Sambuc X4();
75f4a2713aSLionel Sambuc ~X4();
76f4a2713aSLionel Sambuc X4(X4&);
77f4a2713aSLionel Sambuc template<typename T> X4(const T&, int = 17);
78f4a2713aSLionel Sambuc };
79f4a2713aSLionel Sambuc
test_X4(bool Cond,X4 x4)80f4a2713aSLionel Sambuc X4 test_X4(bool Cond, X4 x4) {
81f4a2713aSLionel Sambuc X4 a(x4, 17); // okay, constructor template
82f4a2713aSLionel Sambuc X4 b(x4); // okay, copy constructor
83f4a2713aSLionel Sambuc return X4();
84f4a2713aSLionel Sambuc }
85f4a2713aSLionel Sambuc
86f4a2713aSLionel Sambuc // Instantiation of a non-dependent use of a constructor
87f4a2713aSLionel Sambuc struct DefaultCtorHasDefaultArg {
88f4a2713aSLionel Sambuc explicit DefaultCtorHasDefaultArg(int i = 17);
89f4a2713aSLionel Sambuc };
90f4a2713aSLionel Sambuc
91f4a2713aSLionel Sambuc template<typename T>
default_ctor_inst()92f4a2713aSLionel Sambuc void default_ctor_inst() {
93f4a2713aSLionel Sambuc DefaultCtorHasDefaultArg def;
94f4a2713aSLionel Sambuc }
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambuc template void default_ctor_inst<int>();
97f4a2713aSLionel Sambuc
98f4a2713aSLionel Sambuc template<typename T>
99f4a2713aSLionel Sambuc struct X5 {
100f4a2713aSLionel Sambuc X5();
101f4a2713aSLionel Sambuc X5(const T &);
102f4a2713aSLionel Sambuc };
103f4a2713aSLionel Sambuc
104f4a2713aSLionel Sambuc struct X6 {
105f4a2713aSLionel Sambuc template<typename T> X6(T);
106f4a2713aSLionel Sambuc };
107f4a2713aSLionel Sambuc
test_X5_X6()108f4a2713aSLionel Sambuc void test_X5_X6() {
109f4a2713aSLionel Sambuc X5<X6> tf;
110f4a2713aSLionel Sambuc X5<X6> tf2(tf);
111f4a2713aSLionel Sambuc }
112f4a2713aSLionel Sambuc
113f4a2713aSLionel Sambuc namespace PR8182 {
114f4a2713aSLionel Sambuc struct foo {
115f4a2713aSLionel Sambuc foo();
116f4a2713aSLionel Sambuc template<class T> foo(T&);
117f4a2713aSLionel Sambuc
118f4a2713aSLionel Sambuc private:
119f4a2713aSLionel Sambuc foo(const foo&);
120f4a2713aSLionel Sambuc };
121f4a2713aSLionel Sambuc
test_foo()122f4a2713aSLionel Sambuc void test_foo() {
123f4a2713aSLionel Sambuc foo f1;
124f4a2713aSLionel Sambuc foo f2(f1);
125f4a2713aSLionel Sambuc foo f3 = f1;
126f4a2713aSLionel Sambuc }
127f4a2713aSLionel Sambuc
128f4a2713aSLionel Sambuc }
129*0a6a1f1dSLionel Sambuc
130*0a6a1f1dSLionel Sambuc // Don't blow out the stack trying to call an illegal constructor
131*0a6a1f1dSLionel Sambuc // instantiation. We intentionally allow implicit instantiations to
132*0a6a1f1dSLionel Sambuc // exist, so make sure they're unusable.
133*0a6a1f1dSLionel Sambuc //
134*0a6a1f1dSLionel Sambuc // rdar://19199836
135*0a6a1f1dSLionel Sambuc namespace self_by_value {
136*0a6a1f1dSLionel Sambuc template <class T, class U> struct A {
Aself_by_value::A137*0a6a1f1dSLionel Sambuc A() {}
Aself_by_value::A138*0a6a1f1dSLionel Sambuc A(const A<T,U> &o) {}
Aself_by_value::A139*0a6a1f1dSLionel Sambuc A(A<T,T> o) {}
140*0a6a1f1dSLionel Sambuc };
141*0a6a1f1dSLionel Sambuc
142*0a6a1f1dSLionel Sambuc void helper(A<int,float>);
143*0a6a1f1dSLionel Sambuc
test1(A<int,int> a)144*0a6a1f1dSLionel Sambuc void test1(A<int,int> a) {
145*0a6a1f1dSLionel Sambuc helper(a);
146*0a6a1f1dSLionel Sambuc }
test2()147*0a6a1f1dSLionel Sambuc void test2() {
148*0a6a1f1dSLionel Sambuc helper(A<int,int>());
149*0a6a1f1dSLionel Sambuc }
150*0a6a1f1dSLionel Sambuc }
151*0a6a1f1dSLionel Sambuc
152*0a6a1f1dSLionel Sambuc namespace self_by_value_2 {
153*0a6a1f1dSLionel Sambuc template <class T, class U> struct A {
Aself_by_value_2::A154*0a6a1f1dSLionel Sambuc A() {} // expected-note {{not viable: requires 0 arguments}}
Aself_by_value_2::A155*0a6a1f1dSLionel Sambuc A(A<T,U> &o) {} // expected-note {{not viable: expects an l-value}}
Aself_by_value_2::A156*0a6a1f1dSLionel Sambuc A(A<T,T> o) {} // expected-note {{ignored: instantiation takes its own class type by value}}
157*0a6a1f1dSLionel Sambuc };
158*0a6a1f1dSLionel Sambuc
159*0a6a1f1dSLionel Sambuc void helper_A(A<int,int>); // expected-note {{passing argument to parameter here}}
test_A()160*0a6a1f1dSLionel Sambuc void test_A() {
161*0a6a1f1dSLionel Sambuc helper_A(A<int,int>()); // expected-error {{no matching constructor}}
162*0a6a1f1dSLionel Sambuc }
163*0a6a1f1dSLionel Sambuc }
164*0a6a1f1dSLionel Sambuc
165*0a6a1f1dSLionel Sambuc namespace self_by_value_3 {
166*0a6a1f1dSLionel Sambuc template <class T, class U> struct A {
Aself_by_value_3::A167*0a6a1f1dSLionel Sambuc A() {}
Aself_by_value_3::A168*0a6a1f1dSLionel Sambuc A(A<T,U> &o) {}
Aself_by_value_3::A169*0a6a1f1dSLionel Sambuc A(A<T,T> o) {}
170*0a6a1f1dSLionel Sambuc };
171*0a6a1f1dSLionel Sambuc
172*0a6a1f1dSLionel Sambuc void helper_A(A<int,int>);
test_A(A<int,int> b)173*0a6a1f1dSLionel Sambuc void test_A(A<int,int> b) {
174*0a6a1f1dSLionel Sambuc helper_A(b);
175*0a6a1f1dSLionel Sambuc }
176*0a6a1f1dSLionel Sambuc }
177