blob: c5306a6e32f4a584278d4eaf39870ff6b7c78a1e [file] [log] [blame]
Daniel Dunbar3573b2c2009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor050cabf2009-08-21 18:42:58 +00002struct X0 { // expected-note{{candidate}}
3 X0(int); // expected-note{{candidate}}
John McCall8b29f572009-12-16 08:11:27 +00004 template<typename T> X0(T); // expected-note {{candidate}}
5 template<typename T, typename U> X0(T*, U*); // expected-note {{candidate}}
Douglas Gregor84164f02009-08-24 11:57:43 +00006
7 // PR4761
John McCall8b29f572009-12-16 08:11:27 +00008 template<typename T> X0() : f0(T::foo) {} // expected-note {{candidate}}
Douglas Gregor84164f02009-08-24 11:57:43 +00009 int f0;
Douglas Gregor050cabf2009-08-21 18:42:58 +000010};
11
12void accept_X0(X0);
13
14void test_X0(int i, float f) {
15 X0 x0a(i);
16 X0 x0b(f);
17 X0 x0c = i;
18 X0 x0d = f;
19 accept_X0(i);
20 accept_X0(&i);
21 accept_X0(f);
22 accept_X0(&f);
23 X0 x0e(&i, &f);
24 X0 x0f(&f, &i);
25
26 X0 x0g(f, &i); // expected-error{{no matching constructor}}
27}
Douglas Gregor088fc242009-09-15 18:26:13 +000028
29template<typename T>
30struct X1 {
31 X1(const X1&);
32 template<typename U> X1(const X1<U>&);
33};
34
35template<typename T>
36struct Outer {
37 typedef X1<T> A;
38
39 A alloc;
40
41 explicit Outer(const A& a) : alloc(a) { }
42};
43
44void test_X1(X1<int> xi) {
45 Outer<int> oi(xi);
46 Outer<float> of(xi);
47}
Douglas Gregor4ec1aca2009-09-15 21:14:05 +000048
49// PR4655
50template<class C> struct A {};
51template <> struct A<int>{A(const A<int>&);};
52struct B { A<int> x; B(B& a) : x(a.x) {} };
Douglas Gregord87f5a72009-11-03 01:35:08 +000053
Douglas Gregore0eb15e2009-11-14 01:20:54 +000054struct X2 {
John McCall84b499e2010-01-06 09:43:14 +000055 X2(); // expected-note{{candidate constructor}}
56 X2(X2&); // expected-note {{candidate constructor}}
Stephen Hines0e2c34f2015-03-23 12:09:02 -070057 template<typename T> X2(T); // expected-note {{candidate template ignored: instantiation would take its own class type by value}}
Douglas Gregore0eb15e2009-11-14 01:20:54 +000058};
59
60X2 test(bool Cond, X2 x2) {
61 if (Cond)
62 return x2; // okay, uses copy constructor
63
Douglas Gregorccfe15e2009-12-18 05:02:21 +000064 return X2(); // expected-error{{no matching constructor}}
Douglas Gregore0eb15e2009-11-14 01:20:54 +000065}
66
67struct X3 {
68 template<typename T> X3(T);
69};
70
71template<> X3::X3(X3); // expected-error{{must pass its first argument by reference}}
72
73struct X4 {
Douglas Gregor49faccd2010-11-08 17:16:59 +000074 X4();
Douglas Gregore0eb15e2009-11-14 01:20:54 +000075 ~X4();
Douglas Gregor49faccd2010-11-08 17:16:59 +000076 X4(X4&);
Douglas Gregore0eb15e2009-11-14 01:20:54 +000077 template<typename T> X4(const T&, int = 17);
78};
79
80X4 test_X4(bool Cond, X4 x4) {
81 X4 a(x4, 17); // okay, constructor template
82 X4 b(x4); // okay, copy constructor
Douglas Gregor49faccd2010-11-08 17:16:59 +000083 return X4();
Douglas Gregore0eb15e2009-11-14 01:20:54 +000084}
Douglas Gregordcbf08f2009-12-14 19:27:10 +000085
86// Instantiation of a non-dependent use of a constructor
87struct DefaultCtorHasDefaultArg {
88 explicit DefaultCtorHasDefaultArg(int i = 17);
89};
90
91template<typename T>
92void default_ctor_inst() {
93 DefaultCtorHasDefaultArg def;
94}
95
96template void default_ctor_inst<int>();
Douglas Gregor317e07e2010-04-17 22:01:05 +000097
98template<typename T>
99struct X5 {
100 X5();
101 X5(const T &);
102};
103
104struct X6 {
105 template<typename T> X6(T);
106};
107
108void test_X5_X6() {
109 X5<X6> tf;
110 X5<X6> tf2(tf);
111}
Douglas Gregor49faccd2010-11-08 17:16:59 +0000112
113namespace PR8182 {
114 struct foo {
115 foo();
116 template<class T> foo(T&);
117
118 private:
119 foo(const foo&);
120 };
121
122 void test_foo() {
123 foo f1;
124 foo f2(f1);
125 foo f3 = f1;
126 }
127
128}
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700129
130// Don't blow out the stack trying to call an illegal constructor
131// instantiation. We intentionally allow implicit instantiations to
132// exist, so make sure they're unusable.
133//
134// rdar://19199836
135namespace self_by_value {
136 template <class T, class U> struct A {
137 A() {}
138 A(const A<T,U> &o) {}
139 A(A<T,T> o) {}
140 };
141
142 void helper(A<int,float>);
143
144 void test1(A<int,int> a) {
145 helper(a);
146 }
147 void test2() {
148 helper(A<int,int>());
149 }
150}
151
152namespace self_by_value_2 {
153 template <class T, class U> struct A {
154 A() {} // expected-note {{not viable: requires 0 arguments}}
155 A(A<T,U> &o) {} // expected-note {{not viable: expects an l-value}}
156 A(A<T,T> o) {} // expected-note {{ignored: instantiation takes its own class type by value}}
157 };
158
159 void helper_A(A<int,int>); // expected-note {{passing argument to parameter here}}
160 void test_A() {
161 helper_A(A<int,int>()); // expected-error {{no matching constructor}}
162 }
163}
164
165namespace self_by_value_3 {
166 template <class T, class U> struct A {
167 A() {}
168 A(A<T,U> &o) {}
169 A(A<T,T> o) {}
170 };
171
172 void helper_A(A<int,int>);
173 void test_A(A<int,int> b) {
174 helper_A(b);
175 }
176}