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