2 // Test C++ name mangling.
3 // See Bugs 4059, 5148, 7024, 10058
6 import core.stdc.stdio;
8 extern (C++) int foob(int i, int j, int k);
12 extern (C++) int bar(int i, int j, int k)
14 printf("this = %p\n", this);
15 printf("i = %d\n", i);
16 printf("j = %d\n", j);
17 printf("k = %d\n", k);
24 int foo(int i, int j, int k)
26 printf("i = %d\n", i);
27 printf("j = %d\n", j);
28 printf("k = %d\n", k);
39 auto i = foob(1, 2, 3);
48 static assert(foo.mangleof == "_Z3fooiii");
49 static assert(foob.mangleof == "_Z4foobiii");
50 static assert(C.bar.mangleof == "_ZN1C3barEiii");
54 static assert(foo.mangleof == "?foo@@YAHHHH@Z");
55 static assert(foob.mangleof == "?foob@@YAHHHH@Z");
56 static assert(C.bar.mangleof == "?bar@C@@UAEHHHH@Z");
60 static assert(foo.mangleof == "?foo@@YAHHHH@Z");
61 static assert(foob.mangleof == "?foob@@YAHHHH@Z");
62 static assert(C.bar.mangleof == "?bar@C@@UEAAHHHH@Z");
65 /****************************************/
70 int bar(int i, int j, int k);
73 extern (C++) D getD();
78 int i = d.bar(9,10,11);
84 static assert (getD.mangleof == "_Z4getDv");
85 static assert (D.bar.mangleof == "_ZN1D3barEiii");
88 /****************************************/
90 extern (C++) int callE(E);
95 int bar(int i, int j, int k);
100 extern (C++) int bar(int i, int j, int k)
102 printf("F.bar: i = %d\n", i);
103 printf("F.bar: j = %d\n", j);
104 printf("F.bar: k = %d\n", k);
121 static assert (callE.mangleof == "_Z5callEP1E");
122 static assert (E.bar.mangleof == "_ZN1E3barEiii");
123 static assert (F.bar.mangleof == "_ZN1F3barEiii");
126 /****************************************/
128 extern (C++) void foo4(char* p);
137 static assert(foo4.mangleof == "_Z4foo4Pc");
140 /****************************************/
144 struct foo5 { int i; int j; void* p; }
156 foo5 f = b.getFoo(4);
157 printf("f.p = %p, b = %p\n", f.p, cast(void*)b);
158 assert(f.p == cast(void*)b);
163 static assert(bar5.getFoo.mangleof == "_ZN4bar56getFooEi");
164 static assert (newBar.mangleof == "_Z6newBarv");
167 /****************************************/
179 extern (C) int foosize6();
184 printf("%d %d\n", foosize6(), S6.sizeof);
185 assert(foosize6() == S6.sizeof);
187 printf("f.d = %g\n", f.d);
193 static assert (foo6.mangleof == "_Z4foo6v");
196 /****************************************/
198 extern (C) int foo7();
208 printf("%d %d\n", foo7(), S.sizeof);
209 assert(foo7() == S.sizeof);
212 /****************************************/
214 extern (C++) void foo8(const char *);
224 static assert(foo8.mangleof == "_Z4foo8PKc");
227 /****************************************/
232 extern(C++) void foobar9(elem9*, elem9*);
242 static assert(foobar9.mangleof == "_Z7foobar9P5elem9S0_");
245 /****************************************/
250 void foo10(const char*, const char*);
251 void foo10(const int, const int);
252 void foo10(const char, const char);
254 struct MyStructType { }
255 void foo10(const MyStructType s, const MyStructType t);
257 enum MyEnumType { onemember }
258 void foo10(const MyEnumType s, const MyEnumType t);
273 /**************************************/
278 void test10058a(void*) { }
279 void test10058b(void function(void*)) { }
280 void test10058c(void* function(void*)) { }
281 void test10058d(void function(void*), void*) { }
282 void test10058e(void* function(void*), void*) { }
283 void test10058f(void* function(void*), void* function(void*)) { }
284 void test10058g(void function(void*), void*, void*) { }
285 void test10058h(void* function(void*), void*, void*) { }
286 void test10058i(void* function(void*), void* function(void*), void*) { }
287 void test10058j(void* function(void*), void* function(void*), void* function(void*)) { }
288 void test10058k(void* function(void*), void* function(const (void)*)) { }
289 void test10058l(void* function(void*), void* function(const (void)*), const(void)* function(void*)) { }
294 static assert(test10058a.mangleof == "_Z10test10058aPv");
295 static assert(test10058b.mangleof == "_Z10test10058bPFvPvE");
296 static assert(test10058c.mangleof == "_Z10test10058cPFPvS_E");
297 static assert(test10058d.mangleof == "_Z10test10058dPFvPvES_");
298 static assert(test10058e.mangleof == "_Z10test10058ePFPvS_ES_");
299 static assert(test10058f.mangleof == "_Z10test10058fPFPvS_ES1_");
300 static assert(test10058g.mangleof == "_Z10test10058gPFvPvES_S_");
301 static assert(test10058h.mangleof == "_Z10test10058hPFPvS_ES_S_");
302 static assert(test10058i.mangleof == "_Z10test10058iPFPvS_ES1_S_");
303 static assert(test10058j.mangleof == "_Z10test10058jPFPvS_ES1_S1_");
304 static assert(test10058k.mangleof == "_Z10test10058kPFPvS_EPFS_PKvE");
305 static assert(test10058l.mangleof == "_Z10test10058lPFPvS_EPFS_PKvEPFS3_S_E");
308 /**************************************/
317 static void test11696a(Loc, Expression, Expression);
318 static void test11696b(Loc, Expression, Expression*);
319 static void test11696c(Loc, Expression*, Expression);
320 static void test11696d(Loc, Expression*, Expression*);
325 static assert(CallExp.test11696a.mangleof == "_ZN7CallExp10test11696aE3LocP10ExpressionS2_");
326 static assert(CallExp.test11696b.mangleof == "_ZN7CallExp10test11696bE3LocP10ExpressionPS2_");
327 static assert(CallExp.test11696c.mangleof == "_ZN7CallExp10test11696cE3LocPP10ExpressionS2_");
328 static assert(CallExp.test11696d.mangleof == "_ZN7CallExp10test11696dE3LocPP10ExpressionS3_");
331 /**************************************/
334 extern(C++, N13337a.N13337b.N13337c)
337 void foo13337(S13337 s);
342 static assert(foo13337.mangleof == "_ZN7N13337a7N13337b7N13337c8foo13337ENS1_6S13337E");
345 /**************************************/
348 extern (C++) void test15789a(T...)(T args);