[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaTemplate / default-expr-arguments.cpp
blob438f5b1aa95f743fe5033fe5fc97ae8ddb4c6a76
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
5 template<typename T>
6 class C { C(int a0 = 0); };
8 template<>
9 C<char>::C(int a0);
11 struct S { }; // expected-note 3 {{candidate constructor (the implicit copy constructor)}}
12 #if __cplusplus >= 201103L // C++11 or later
13 // expected-note@-2 3 {{candidate constructor (the implicit move constructor) not viable}}
14 #endif
16 template<typename T> void f1(T a, T b = 10) { } // expected-error{{no viable conversion}} \
17 // expected-note{{passing argument to parameter 'b' here}}
19 template<typename T> void f2(T a, T b = T()) { }
21 template<typename T> void f3(T a, T b = T() + T()); // expected-error{{invalid operands to binary expression ('S' and 'S')}}
23 void g() {
24 f1(10);
25 f1(S()); // expected-note{{in instantiation of default function argument expression for 'f1<S>' required here}}
27 f2(10);
28 f2(S());
30 f3(10);
31 f3(S()); // expected-note{{in instantiation of default function argument expression for 'f3<S>' required here}}
34 template<typename T> struct F {
35 F(T t = 10); // expected-error{{no viable conversion}} \
36 // expected-note{{passing argument to parameter 't' here}}
37 void f(T t = 10); // expected-error{{no viable conversion}} \
38 // expected-note{{passing argument to parameter 't' here}}
41 struct FD : F<int> { };
43 void g2() {
44 F<int> f;
45 FD fd;
48 void g3(F<int> f, F<struct S> s) {
49 f.f();
50 s.f(); // expected-note{{in instantiation of default function argument expression for 'f<S>' required here}}
52 F<int> f2;
53 F<S> s2; // expected-note{{in instantiation of default function argument expression for 'F<S>' required here}}
56 template<typename T> struct G {
57 G(T) {}
60 void s(G<int> flags = 10) { }
62 // Test default arguments
63 template<typename T>
64 struct X0 {
65 void f(T = T()); // expected-error{{no matching}}
68 template<typename U>
69 void X0<U>::f(U) { }
71 void test_x0(X0<int> xi) {
72 xi.f();
73 xi.f(17);
76 struct NotDefaultConstructible { // expected-note 2 {{candidate constructor (the implicit copy constructor) not viable}}
77 #if __cplusplus >= 201103L // C++11 or later
78 // expected-note@-2 2 {{candidate constructor (the implicit move constructor) not viable}}
79 #endif
80 NotDefaultConstructible(int); // expected-note 2{{candidate}}
83 void test_x0_not_default_constructible(X0<NotDefaultConstructible> xn) {
84 xn.f(NotDefaultConstructible(17));
85 xn.f(42);
86 xn.f(); // expected-note{{in instantiation of default function argument}}
89 template<typename T>
90 struct X1 {
91 typedef T value_type;
92 X1(const value_type& value = value_type());
95 void test_X1() {
96 X1<int> x1;
99 template<typename T>
100 struct X2 {
101 void operator()(T = T()); // expected-error{{no matching}}
104 void test_x2(X2<int> x2i, X2<NotDefaultConstructible> x2n) {
105 x2i();
106 x2i(17);
107 x2n(NotDefaultConstructible(17));
108 x2n(); // expected-note{{in instantiation of default function argument}}
111 // PR5283
112 namespace PR5283 {
113 template<typename T> struct A {
114 A(T = 1); // expected-error 3 {{cannot initialize a parameter of type 'int *' with an rvalue of type 'int'}} \
115 // expected-note 3{{passing argument to parameter here}}
118 struct B : A<int*> {
119 B();
121 B::B() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
123 struct C : virtual A<int*> {
124 C();
126 C::C() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
128 struct D {
129 D();
131 A<int*> a;
133 D::D() { } // expected-note {{in instantiation of default function argument expression for 'A<int *>' required he}}
136 // PR5301
137 namespace pr5301 {
138 void f(int, int = 0);
140 template <typename T>
141 void g(T, T = 0);
143 template <int I>
144 void i(int a = I);
146 template <typename T>
147 void h(T t) {
148 f(0);
149 g(1);
150 g(t);
151 i<2>();
154 void test() {
155 h(0);
159 // PR5810
160 namespace PR5810 {
161 template<typename T>
162 struct allocator {
163 allocator() { int a[sizeof(T) ? -1 : -1]; } // expected-error2 {{array with a negative size}}
166 template<typename T>
167 struct vector {
168 vector(const allocator<T>& = allocator<T>()) {} // expected-note2 {{instantiation of}}
171 struct A { };
172 struct B { };
174 template<typename>
175 void FilterVTs() {
176 vector<A> Result;
179 void f() {
180 vector<A> Result;
183 template<typename T>
184 struct X {
185 vector<B> bs;
186 X() { }
189 void f2() {
190 X<float> x; // expected-note{{member function}}
194 template<typename T> void f4(T, int = 17);
195 template<> void f4<int>(int, int);
197 void f4_test(int i) {
198 f4(i);
201 // Instantiate for initialization
202 namespace InstForInit {
203 template<typename T>
204 struct Ptr {
205 typedef T* type;
206 Ptr(type);
209 template<typename T>
210 struct Holder {
211 Holder(int i, Ptr<T> ptr = 0);
214 void test_holder(int i) {
215 Holder<int> h(i);
219 namespace PR5810b {
220 template<typename T>
221 T broken() {
222 T t;
223 double**** not_it = t;
226 void f(int = broken<int>());
227 void g() { f(17); }
230 namespace PR5810c {
231 template<typename T>
232 struct X {
233 X() {
234 T t;
235 double *****p = t; // expected-error{{cannot initialize a variable of type 'double *****' with an lvalue of type 'int'}}
237 X(const X&) { }
240 struct Y : X<int> { // expected-note{{instantiation of}}
243 void f(Y y = Y());
245 void g() { f(); }
248 namespace PR8127 {
249 template< typename T > class PointerClass {
250 public:
251 PointerClass( T * object_p ) : p_( object_p ) {
252 p_->acquire();
254 private:
255 T * p_;
258 class ExternallyImplementedClass;
260 class MyClass {
261 void foo( PointerClass<ExternallyImplementedClass> = 0 );
265 namespace rdar8427926 {
266 template<typename T>
267 struct Boom {
268 ~Boom() {
269 T t;
270 double *******ptr = t; // expected-error 2{{cannot initialize}}
274 Boom<float> *bfp;
276 struct X {
277 void f(Boom<int> = Boom<int>()) { } // expected-note{{requested here}}
278 void g(int x = (delete bfp, 0)); // expected-note{{requested here}}
281 void test(X *x) {
282 x->f();
283 x->g();
287 namespace PR8401 {
288 template<typename T>
289 struct A {
290 A() { T* x = 1; } // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
293 template<typename T>
294 struct B {
295 B(const A<T>& a = A<T>()); // expected-note{{in instantiation of}}
298 void f(B<int> b = B<int>());
300 void g() {
301 f();
305 namespace PR12581 {
306 const int a = 0;
307 template < typename > struct A;
308 template < typename MatrixType, int =
309 A < MatrixType >::Flags ? : A < MatrixType >::Flags & a > class B;
310 void
311 fn1 ()
316 namespace PR13758 {
317 template <typename T> struct move_from {
318 T invalid;
320 template <class K>
321 struct unordered_map {
322 explicit unordered_map(int n = 42);
323 unordered_map(move_from<K> other);
325 template<typename T>
326 void StripedHashTable() {
327 new unordered_map<void>();
328 new unordered_map<void>;
330 void tt() {
331 StripedHashTable<int>();