[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaTemplate / instantiate-init.cpp
blob6db33a972f86db6141c169fcd50badcf27fc12c2
1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
3 namespace std {
4 template<typename T> struct initializer_list {
5 T *p;
6 __SIZE_TYPE__ n;
7 initializer_list(T*, __SIZE_TYPE__);
8 };
11 struct X0 { // expected-note 8{{candidate}}
12 X0(int*, float*); // expected-note 4{{candidate}}
15 template<typename T, typename U>
16 X0 f0(T t, U u) {
17 X0 x0(t, u); // expected-error{{no matching}}
18 return X0(t, u); // expected-error{{no matching}}
21 void test_f0(int *ip, float *fp, double *dp) {
22 f0(ip, fp);
23 f0(ip, dp); // expected-note{{instantiation}}
26 template<typename Ret, typename T, typename U>
27 Ret f1(Ret *retty, T t, U u) {
28 Ret r0(t, u); // expected-error{{no matching}}
29 return Ret(t, u); // expected-error{{no matching}}
32 void test_f1(X0 *x0, int *ip, float *fp, double *dp) {
33 f1(x0, ip, fp);
34 f1(x0, ip, dp); // expected-note{{instantiation}}
37 namespace PR6457 {
38 template <typename T> struct X { explicit X(T* p = 0) { }; };
39 template <typename T> struct Y { Y(int, const T& x); };
40 struct A { };
41 template <typename T>
42 struct B {
43 B() : y(0, X<A>()) { }
44 Y<X<A> > y;
46 B<int> b;
49 namespace PR6657 {
50 struct X
52 X (int, int) { }
55 template <typename>
56 void f0()
58 X x = X(0, 0);
61 void f1()
63 f0<int>();
67 // Instantiate out-of-line definitions of static data members which complete
68 // types through an initializer even when the only use of the member that would
69 // cause instantiation is in an unevaluated context, but one requiring its
70 // complete type.
71 namespace PR10001 {
72 template <typename T> struct S {
73 static const int arr[];
74 static const int x;
75 static int f();
78 template <typename T> const int S<T>::arr[] = { 1, 2, 3 };
79 template <typename T> const int S<T>::x = sizeof(arr) / sizeof(arr[0]);
80 template <typename T> int S<T>::f() { return x; }
82 int x = S<int>::f();
85 namespace PR7985 {
86 template<int N> struct integral_c { };
88 template <typename T, int N>
89 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<}}
91 template<typename T>
92 struct Data {
93 T x;
96 template<typename T>
97 struct Description {
98 static const Data<T> data[];
101 template<typename T>
102 const Data<T> Description<T>::data[] = {{ 1 }}; // expected-error{{cannot initialize a member subobject of type 'int *' with an rvalue of type 'int'}}
104 template<>
105 const Data<float*> Description<float*>::data[];
107 void test() {
108 integral_c<1> ic1 = array_lengthof(Description<int>::data);
109 (void)sizeof(array_lengthof(Description<float>::data));
111 (void)sizeof(array_lengthof( // expected-error{{no matching function for call to 'array_lengthof'}}
112 Description<int*>::data // expected-note{{in instantiation of static data member 'PR7985::Description<int *>::data' requested here}}
115 array_lengthof(Description<float*>::data); // expected-error{{no matching function for call to 'array_lengthof'}}
119 namespace PR13064 {
120 // Ensure that in-class direct-initialization is instantiated as
121 // direct-initialization and likewise copy-initialization is instantiated as
122 // copy-initialization.
123 struct A { explicit A(int); }; // expected-note{{here}}
124 template<typename T> struct B { T a { 0 }; };
125 B<A> b;
126 template <typename T> struct C { // expected-note {{in instantiation of default member initializer}}
127 T a = {0}; // expected-error{{explicit}}
129 C<A> c; // expected-note {{in evaluation of exception spec}}
132 namespace PR16903 {
133 // Make sure we properly instantiate list-initialization.
134 template<typename T>
135 void fun (T it) {
136 int m = 0;
137 for (int i = 0; i < 4; ++i, ++it){
138 m |= long{char{*it}};
141 int test() {
142 char in[4] = {0,0,0,0};
143 fun(in);
147 namespace ReturnStmtIsInitialization {
148 struct X {
149 X() {}
150 X(const X &) = delete;
152 template<typename T> X f() { return {}; }
153 auto &&x = f<void>();
156 namespace InitListUpdate {
157 struct A { int n; };
158 using AA = A[1];
160 // Check that an init list update doesn't "lose" the pack-ness of an expression.
161 template <int... N> void f() {
162 g(AA{0, [0].n = N} ...); // expected-warning 3{{extension}} expected-note {{here}} expected-warning 3{{overrides prior init}} expected-note 3{{previous init}}
163 g(AA{N, [0].n = 0} ...); // expected-warning 3{{extension}} expected-note {{here}} expected-warning 3{{overrides prior init}} expected-note 3{{previous init}}
166 void g(AA, AA);
167 void h() { f<1, 2>(); } // expected-note {{instantiation of}}
170 namespace RebuildStdInitList {
171 struct A { A(std::initializer_list<int>, int = 0) {} };
172 struct B : A { using A::A; };
173 struct PES { PES(B); };
175 // Check we can rebuild the use of the default argument here. This requires
176 // going to the original (base class) constructor, because we don't copy
177 // default arguments onto our fake derived class inherited constructors.
178 template<typename U> void f() { PES({1, 2, 3}); }
179 void g() { f<int>(); }