]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gdc.test/runnable_cxx/extra-files/externmangle.cpp
d: Import dmd b8384668f, druntime e6caaab9, phobos 5ab9ad256 (v2.098.0-beta.1)
[thirdparty/gcc.git] / gcc / testsuite / gdc.test / runnable_cxx / extra-files / externmangle.cpp
CommitLineData
5fee5ec3 1#include <stddef.h>
b4c522fa
IB
2#include <stdint.h>
3
4template<class X>
5struct Foo
6{
7 X *v;
8};
9
10template<class X>
11struct Boo
12{
13 X *v;
14};
15
16void test1(Foo<int> arg1)
17{
18}
19
20
21void test2(int* arg2, Boo<int*> arg1)
22{
23}
24
25template<int X, int Y>
26struct Test3
27{
28
29};
30
31void test3(Test3<3,3> arg1)
32{
33}
34
35void test4(Foo<int*> arg1, Boo<int*> arg2, Boo<int*> arg3, int*, Foo<double>)
36{
37}
38
39void test5(Foo<int*> arg1, Boo<int*> arg2, Boo<int*> arg3)
40{
41}
42
43struct Goo
44{
45
46 template<class X>
47 struct Foo
48 {
49 X* v;
50 };
51
52 template<class X>
53 struct Boo
54 {
55 template<class Y>
56 struct Xoo
57 {
58 Y* v;
59 };
60 X* v;
61 };
62
63
64 void test6(Foo<Boo<Foo<void> > > arg1);
65 void test7(Boo<void>::Xoo<int> arg1);
66};
67
68void Goo::test6(Goo::Foo<Goo::Boo<Goo::Foo<void> > > arg1)
69{
70}
71
72void Goo::test7(Goo::Boo<void>::Xoo<int> arg1)
73{
74}
75
76struct P1
77{
78 template<class T>
79 struct Mem
80 {
81 };
82};
83
84struct P2
85{
86 template<class T>
87 struct Mem
88 {
89 };
90};
91
92void test8(P1::Mem<int>, P2::Mem<int>){}
93void test9(Foo<int**>, Foo<int*>, int**, int*){}
94
95
96
97class Test10
98{
99 private: void test10();
100 public: void test11();
101 protected: void test12();
102 public: void test13() const;
103
104 private: void test14(); // Private methods in D are always non-virtual
105 public: virtual void test15();
106 protected: virtual void test16();
107
108 private: static void test17();
109 public: static void test18();
110 protected: static void test19();
111};
112
113Test10* Test10Ctor()
114{
115 return new Test10();
116}
117
118void Test10Dtor(Test10*& ptr)
119{
120 delete ptr;
121 ptr = 0;
122}
123
124void Test10::test10(){}
125void Test10::test11(){}
126void Test10::test12(){}
127void Test10::test13() const{}
128void Test10::test14(){}
129void Test10::test15(){}
130void Test10::test16(){}
131void Test10::test17(){}
132void Test10::test18(){}
133void Test10::test19(){}
134
135struct Test20
136{
137 private: static int test20;
138 protected: static int test21;
139 public: static int test22;
140};
141
142int Test20::test20 = 20;
143int Test20::test21 = 21;
144int Test20::test22 = 22;
145
146int test23(Test10**, Test10*, Test10***, Test10 const *const)
147{
148 return 1;
149}
150
151int test23b(Test10 const *const *const, Test10 const* const, Test10*)
152{
153 return 1;
154}
155
156void test24(int(*)(int,int))
157{
158}
159
160void test25(int arr[2][5][6][291])
161{
162}
163
164int test26(int arr[5][6][291])
165{
166 return arr[1][1][1];
167}
168
169void test27(int, ...){}
170void test28(int){}
171
172void test29(float){}
173void test30(const float){}
174
175template<class T>
176struct Array
177{
178 int dim;
179};
180
181class Module
182{
183public:
184 static void imports(Module*);
185 static int dim(Array<Module*>*);
186};
187
188
189void Module::imports(Module*)
190{
191}
192
193int Module::dim(Array<Module*>* arr)
194{
195 return arr->dim;
196}
197
5fee5ec3 198uint64_t testlongmangle(int a, unsigned int b, int64_t c, uint64_t d)
b4c522fa
IB
199{
200 return a + b + c + d;
201}
5fee5ec3
IB
202
203unsigned long testCppLongMangle(long a, unsigned long b)
b4c522fa 204{
5fee5ec3
IB
205 return a + b;
206}
207
208unsigned long long testCppLongLongMangle(long long a, unsigned long long b)
209{
210 return a + b;
211}
212
213size_t testCppSizeTMangle(ptrdiff_t a, size_t b)
214{
215 return a + b;
b4c522fa 216}
b4c522fa
IB
217
218int test31[2][2][2] = {1, 1, 1, 1, 1, 1, 1, 1};
219int *test32 = 0;
220
221
222
223class Expression;
224
225typedef int (*apply_fp_t)(Expression*, void*);
226
227class Expression
228{
229 int type;
230public:
231 int apply(apply_fp_t fp, apply_fp_t fp2, void *param);
232 int getType();
233 static Expression* create(int v);
234 static void dispose(Expression*&);
235};
236
237int Expression::apply(apply_fp_t fp, apply_fp_t fp2, void *param)
238{
239 return fp(this, param) * fp2(this, param);
240}
241
242int Expression::getType()
243{
244 return type;
245}
246
247Expression* Expression::create(int v)
248{
249 Expression *e = new Expression();
250 e->type = v;
251 return e;
252}
253
254void Expression::dispose(Expression *&e)
255{
256 if (e)
257 delete e;
258 e = 0;
259}
260
261/*int test34(int v[0][0][0])
262{
263 return 0;
264}*/
265
266#ifndef _MSC_VER
267 int test35(long double arg)
268 {
269 return (int)arg;
270 }
271#endif
272
273const char *test36(const char *arg)
274{
275 return arg;
276}
277
278class Test37
279{
280public:
281 static Test37 *create();
282 bool test();
283};
284
285bool test37()
286{
287 Test37 *o = Test37::create();
288 return o->test();
289}
290
291class Test38
292{
293public:
294 int test(int, ...);
295 static Test38* create();
296 static void dispose(Test38*&);
297};
298
299int Test38::test(int a, ...)
300{
301 return a;
302}
303
304Test38* Test38::create()
305{
306 Test38 *t = new Test38();
307 return t;
308}
309
310void Test38::dispose(Test38 *&t)
311{
312 if (t)
313 delete t;
314 t = 0;
315}
316
317class S1
318{
319 int val;
320public:
321 static S1* init(int);
322 S1(int v) : val(v) {}
323 int value();
324};
325
326S1* S1::init(int x)
327{
328 return new S1(x);
329}
330
331int S1::value()
332{
333 return val;
334}
335
336template<class T>
337class S2
338{
339 T val;
340public:
341 static S2<T>* init(T);
342 S2(T v) : val(v) {}
343 T value();
344};
345
346template<>
347S2<int>* S2<int>::init(int x)
348{
349 return new S2<int>(x);
350}
351
352template<>
353int S2<int>::value()
354{
355 return val;
356}
357
358struct C1
359{
360 const char *data;
361
362 static C1* init(const char *p);
363
364 C1(const char* p) : data(p) { }
365
366 virtual const char* getDataCPP();
367 virtual const char* getDataD();
368};
369
370C1* C1::init(const char *p)
371{
372 return new C1(p);
373}
374
375const char* C1::getDataCPP()
376{
377 return data;
378}
379
380template<class T>
381struct C2
382{
383 const T *data;
384
385 static C2* init(const T *p);
386
387 C2(const T* p) : data(p) { }
388
389 virtual const T* getData();
390};
391
392template<>
393C2<char>* C2<char>::init(const char *p)
394{
395 return new C2<char>(p);
396}
397
398template<>
399const char* C2<char>::getData()
400{
401 return data;
402}
403
404int test39cpp(C2<char>* c2, S2<int>* s2)
405{
406 C2<char>* otherC2 = C2<char>::init(c2->getData());
407 if (c2->getData() != otherC2->getData())
408 return 1;
409 S2<int>* otherS2 = S2<int>::init(s2->value());
410 if (s2->value() != otherS2->value())
411 return 2;
412 return 0;
5fee5ec3
IB
413}
414
415namespace foo
416{
417 namespace bar
418 {
419 namespace baz
420 {
421 int doStuff(int i)
422 {
423 return i * 2;
424 }
425 }
426 }
427}
428
429#ifndef __DMC__ // DMC doesn't support c++11
430template<typename ...T> void foovargs(T... args);
431
432void test40()
433{
434 foovargs<int, float>(1, 2.0f);
435 char c = 'a';
436 foovargs<char*>(&c);
437}
438
439template<typename T, typename ...Args>
440void make_shared_poc(Args&... args);
441
442void test41()
443{
444 int a = 1;
445 int b = 2;
446 make_shared_poc<int, int, int>(a, b);
447
448}
449#endif