1 /*
2 GCC 5.1 introduced new implementations of std::string and std::list:
3 
4 https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
5 
6 This causes e.g. std::string to be actually defined as
7 std::__cxx11::string.
8 
9 On machines with GCC 5.1, this manifests as a linker error when
10 running the cppa.d / cppb.cpp test:
11 
12 cppa.o: In function `_D4cppa6test14FZv':
13 cppa.d:(.text._D4cppa6test14FZv+0x11): undefined reference to `foo14a(std::string*)'
14 cppa.d:(.text._D4cppa6test14FZv+0x18): undefined reference to `foo14b(std::basic_string<int, std::char_traits<int>, std::allocator<int> >*)'
15 cppa.d:(.text._D4cppa6test14FZv+0x3a): undefined reference to `foo14f(std::char_traits<char>*, std::string*, std::string*)'
16 cppa.o: In function `_D4cppa7testeh3FZv':
17 cppa.d:(.text._D4cppa7testeh3FZv+0x19): undefined reference to `throwle()'
18 collect2: error: ld returned 1 exit status
19 --- errorlevel 1
20 
21 When the .cpp file is compiled with g++ 5.3.0, the actual function
22 signatures in the cppb.o object file are:
23 
24 foo14a(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
25 foo14b(std::__cxx11::basic_string<int, std::char_traits<int>, std::allocator<int> >*)
26 foo14f(std::char_traits<char>*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
27 
28 Fortunately, it is easily possible to disable the new feature
29 by defining _GLIBCXX_USE_CXX11_ABI as 0 before including any standard
30 headers.
31 */
32 #define _GLIBCXX_USE_CXX11_ABI 0
33 
34 #include <stdio.h>
35 #include <stdint.h>
36 #include <assert.h>
37 #include <exception>
38 #include <cstdarg>
39 
40 #include "cppb.h"
41 
42 /**************************************/
43 
44 int foo(int i, int j, int k);
45 
foob(int i,int j,int k)46 int foob(int i, int j, int k)
47 {
48     printf("i = %d\n", i);
49     printf("j = %d\n", j);
50     printf("k = %d\n", k);
51     assert(i == 1);
52     assert(j == 2);
53     assert(k == 3);
54 
55     foo(i, j, k);
56 
57     return 7;
58 }
59 
60 /**************************************/
61 
62 class D *dthis;
63 
64 class D
65 {
66   public:
bar(int i,int j,int k)67     virtual int bar(int i, int j, int k)
68     {
69     printf("this = %p\n", this);
70     assert(this == dthis);
71     printf("D.bar: i = %d\n", i);
72     printf("D.bar: j = %d\n", j);
73     printf("D.bar: k = %d\n", k);
74     assert(i == 9);
75     assert(j == 10);
76     assert(k == 11);
77     return 8;
78     }
79 };
80 
81 
getD()82 D* getD()
83 {
84     D *d = new D();
85     dthis = d;
86     return d;
87 }
88 
89 /**************************************/
90 
91 class E
92 {
93   public:
94     virtual int bar(int i, int j, int k);
95 };
96 
97 
callE(E * e)98 int callE(E *e)
99 {
100     return e->bar(11,12,13);
101 }
102 
103 /**************************************/
104 
foo4(char * p)105 void foo4(char *p)
106 {
107 }
108 
109 /**************************************/
110 
111 struct foo5 { int i; int j; void *p; };
112 
113 class bar5
114 {
115 public:
getFoo(int i)116   virtual foo5 getFoo(int i){
117     printf("This = %p\n", this);
118     foo5 f;
119     f.i = 1;
120     f.j = 2 + i;
121     f.p = (void*)this;
122     return f;
123   }
124 };
125 
newBar()126 bar5* newBar()
127 {
128   bar5* b = new bar5();
129   printf("bar = %p\n", b);
130   return b;
131 }
132 
133 
134 /**************************************/
135 
136 struct A11802;
137 struct B11802;
138 
139 class C11802
140 {
141 public:
142     virtual void fun(A11802 *);
143     virtual void fun(B11802 *);
144 };
145 
146 class D11802 : public C11802
147 {
148 public:
149     void fun(A11802 *);
150     void fun(B11802 *);
151 };
152 
test11802x(D11802 * c)153 void test11802x(D11802 *c)
154 {
155     c->fun((A11802 *)0);
156     c->fun((B11802 *)0);
157 }
158 
159 /**************************************/
160 
161 typedef struct
162 {
163     int i;
164     double d;
165 } S6;
166 
167 union S6_2
168 {
169     int i;
170     double d;
171 };
172 
173 enum S6_3
174 {
175     A, B
176 };
177 
178 
foo6(void)179 S6 foo6(void)
180 {
181     S6 s;
182     s.i = 42;
183     s.d = 2.5;
184     return s;
185 }
186 
foo6_2(void)187 S6_2 foo6_2(void)
188 {
189     S6_2 s;
190     s.i = 42;
191     return s;
192 }
193 
foo6_3(void)194 S6_3 foo6_3(void)
195 {
196     S6_3 s = A;
197     return s;
198 }
199 
foosize6()200 extern "C" { int foosize6()
201 {
202     return sizeof(S6);
203 }
204 }
205 
206 /**************************************/
207 
208 typedef struct
209 {
210     int i;
211     long long d;
212 } S7;
213 
foo7()214 extern "C" { int foo7()
215 {
216     return sizeof(S7);
217 }
218 }
219 
220 /**************************************/
221 
222 struct S13955a
223 {
224     float a;
225     double b;
226 };
227 
228 struct S13955b
229 {
230     double a;
231     float b;
232 };
233 
234 struct S13955c
235 {
236     float a;
237     float b;
238 };
239 
240 struct S13955d
241 {
242     double a;
243     double b;
244 };
245 
246 void check13955(S13955a a, S13955b b, S13955c c, S13955d d);
247 
func13955(S13955a a,S13955b b,S13955c c,S13955d d)248 void func13955(S13955a a, S13955b b, S13955c c, S13955d d)
249 {
250     check13955(a, b, c, d);
251 }
252 
253 /**************************************/
254 
255 struct Struct10071
256 {
257     void *p;
258     long double r;
259 };
260 
offset10071()261 size_t offset10071()
262 {
263     Struct10071 s;
264     return (char *)&s.r - (char *)&s;
265 }
266 
267 /**************************************/
268 
foo8(const char * p)269 void foo8(const char *p)
270 {
271 }
272 
273 /**************************************/
274 // https://issues.dlang.org/show_bug.cgi?id=4059
275 
276 struct elem9 { };
foobar9(elem9 *,elem9 *)277 void foobar9(elem9*, elem9*) { }
278 
279 /**************************************/
280 // https://issues.dlang.org/show_bug.cgi?id=5148
281 
foo10(const char *,const char *)282 void foo10(const char*, const char*) { }
foo10(const int,const int)283 void foo10(const int, const int) { }
foo10(const char,const char)284 void foo10(const char, const char) { }
foo10(bool,bool)285 void foo10(bool, bool) { }
286 
287 struct MyStructType { };
foo10(const MyStructType s,const MyStructType t)288 void foo10(const MyStructType s, const MyStructType t) { }
289 
290 enum MyEnumType { onemember };
foo10(const MyEnumType s,const MyEnumType t)291 void foo10(const MyEnumType s, const MyEnumType t) { }
292 
293 /**************************************/
294 
bar11()295 namespace N11 { namespace M { void bar11() { } } }
296 
bar()297 namespace A11 { namespace B { namespace C { void bar() { } } } }
298 
299 /**************************************/
300 
301 void myvprintfx(const char* format, va_list);
302 
myvprintf(const char * format,va_list va)303 void myvprintf(const char* format, va_list va)
304 {
305     myvprintfx(format, va);
306 }
307 
308 /**************************************/
309 
310 class C13161
311 {
312 public:
dummyfunc()313         virtual void dummyfunc() {}
314         long long val_5;
315         unsigned val_9;
316 };
317 
318 class Test : public C13161
319 {
320 public:
321         unsigned val_0;
322         long long val_1;
323 };
324 
getoffset13161()325 size_t getoffset13161()
326 {
327     Test s;
328     return (char *)&s.val_0 - (char *)&s;
329 }
330 
331 class C13161a
332 {
333 public:
dummyfunc()334         virtual void dummyfunc() {}
335         long double val_5;
336         unsigned val_9;
337 };
338 
339 class Testa : public C13161a
340 {
341 public:
342         bool val_0;
343 };
344 
getoffset13161a()345 size_t getoffset13161a()
346 {
347     Testa s;
348     return (char *)&s.val_0 - (char *)&s;
349 }
350 
351 /****************************************************/
352 
353 #if __linux__ || __APPLE__ || __FreeBSD__ || __DragonFly__
354 #include <memory>
355 #include <vector>
356 #include <string>
357 
358 #if __linux__
359 template struct std::allocator<int>;
360 template struct std::vector<int>;
361 
foo15()362 void foo15()
363 {
364     std::allocator<int>* p;
365     p->deallocate(0, 0);
366 }
367 
368 #endif
369 
370 // _Z5foo14PSt6vectorIiSaIiEE
foo14(std::vector<int,std::allocator<int>> * p)371 void foo14(std::vector<int, std::allocator<int> > *p) { }
372 
foo14a(std::basic_string<char> * p)373 void foo14a(std::basic_string<char> *p) { }
foo14b(std::basic_string<int> * p)374 void foo14b(std::basic_string<int> *p) { }
foo14c(std::basic_istream<char> * p)375 void foo14c(std::basic_istream<char> *p) { }
foo14d(std::basic_ostream<char> * p)376 void foo14d(std::basic_ostream<char> *p) { }
foo14e(std::basic_iostream<char> * p)377 void foo14e(std::basic_iostream<char> *p) { }
378 
foo14f(std::char_traits<char> * x,std::basic_string<char> * p,std::basic_string<char> * q)379 void foo14f(std::char_traits<char>* x, std::basic_string<char> *p, std::basic_string<char> *q) { }
380 
381 #endif
382 
383 /**************************************/
384 
385 struct S13956
386 {
387 };
388 
389 void check13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
390 
func13956(S13956 arg0,int arg1,int arg2,int arg3,int arg4,int arg5,int arg6)391 void func13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
392 {
393     check13956(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
394 }
395 
396 /**************************************/
397 
f13289_cpp_wchar_t(wchar_t ch)398 wchar_t f13289_cpp_wchar_t(wchar_t ch)
399 {
400     if (ch <= L'z' && ch >= L'a')
401     {
402         return ch - (L'a' - L'A');
403     }
404     else
405     {
406         return ch;
407     }
408 }
409 #ifdef __DMC__
410 // DMC doesn't support c++11
411 #elif defined (_MSC_VER) //&& _MSC_VER <= 1800
412 // MSVC2013 doesn't support char16_t/char32_t
413 #else
414 #define TEST_UNICODE
415 #endif
416 #ifdef TEST_UNICODE
417 char16_t f13289_d_wchar(char16_t ch);
418 char32_t f13289_d_dchar(char32_t ch);
419 #endif
420 wchar_t f13289_d_wchar_t(wchar_t ch);
421 
f13289_cpp_test()422 bool f13289_cpp_test()
423 {
424     if (!(f13289_d_wchar_t(L'e') == L'E')) return false;
425     if (!(f13289_d_wchar_t(L'F') == L'F')) return false;
426 #ifdef TEST_UNICODE
427     if (!(f13289_d_wchar(u'c') == u'C')) return false;
428     if (!(f13289_d_wchar(u'D') == u'D')) return false;
429     if (!(f13289_d_dchar(U'e') == U'E')) return false;
430     if (!(f13289_d_dchar(U'F') == U'F')) return false;
431 #endif
432     return true;
433 }
434 
435 /******************************************/
436 
testld(long double ld)437 long double testld(long double ld)
438 {
439     assert(ld == 5);
440     return ld + 1;
441 }
442 
testldld(long double ld1,long double ld2)443 long double testldld(long double ld1, long double ld2)
444 {
445     assert(ld1 == 5);
446     return ld2 + 1;
447 }
448 
testl(long lng)449 long testl(long lng)
450 {
451     assert(lng == 5);
452     return lng + sizeof(long);
453 }
454 
testul(unsigned long ul)455 unsigned long testul(unsigned long ul)
456 {
457     assert(ul == 5);
458     return ul + sizeof(unsigned long);
459 }
460 
461 /******************************************/
462 
463 struct S13707
464 {
465     void* a;
466     void* b;
S13707S13707467     S13707(void *a, void* b)
468     {
469         this->a = a;
470         this->b = b;
471     }
472 };
473 
func13707()474 S13707 func13707()
475 {
476     S13707 pt(NULL, NULL);
477     return pt;
478 }
479 
480 /******************************************/
481 
482 template <int x> struct S13932
483 {
484     int member;
485 };
486 
func13932(S13932<-1> s)487 void func13932(S13932<-1> s) {}
488 
489 /******************************************/
490 
491 namespace N13337 {
492   namespace M13337 {
493     struct S13337 { };
foo13337(S13337 s)494     void foo13337(S13337 s) { }
495   }
496 }
497 
498 /****************************************/
499 // https://issues.dlang.org/show_bug.cgi?id=14195
500 
501 template <typename T>
502 struct Delegate1 {};
503 
504 template <typename R1>
505 struct Delegate1 < R1() > {};
506 
507 template <typename T1, typename T2>
508 struct Delegate2 {};
509 
510 template < typename R1, typename T1, typename T2, typename R2, typename T3, typename T4 >
511 struct Delegate2<R1(T1, T2), R2(T3, T4)> {};
512 
test14195a(Delegate1<void ()> func)513 void test14195a(Delegate1<void()> func) {}
514 
test14195b(Delegate2<int (float,double),int (float,double)> func)515 void test14195b(Delegate2<int(float, double), int(float, double)> func) {}
516 
517 /******************************************/
518 // https://issues.dlang.org/show_bug.cgi?id=14200
519 
test14200a(int a)520 void test14200a(int a) {};
test14200b(float a,int b,double c)521 void test14200b(float a, int b, double c) {};
522 
523 /******************************************/
524 // https://issues.dlang.org/show_bug.cgi?id=14956
525 
526 namespace std {
527     namespace N14956 {
528     struct S14956 { };
529     }
530 }
531 
test14956(std::N14956::S14956 s)532 void test14956(std::N14956::S14956 s) { }
533 
534 /******************************************/
535 // check order of overloads in vtable
536 
537 class Statement;
538 class ErrorStatement;
539 class PeelStatement;
540 class ExpStatement;
541 class DtorExpStatement;
542 
543 class Visitor
544 {
545 public:
visit(Statement *)546     virtual int visit(Statement*) { return 1; }
visit(ErrorStatement *)547     virtual int visit(ErrorStatement*) { return 2; }
visit(PeelStatement *)548     virtual int visit(PeelStatement*) { return 3; }
549 };
550 
551 class Visitor2 : public Visitor
552 {
553 public:
visit2(ExpStatement *)554     virtual int visit2(ExpStatement*) { return 4; }
visit2(DtorExpStatement *)555     virtual int visit2(DtorExpStatement*) { return 5; }
556 };
557 
testVtableCpp(Visitor2 * sv)558 bool testVtableCpp(Visitor2* sv)
559 {
560     if (sv->visit((Statement*)0) != 1) return false;
561     if (sv->visit((ErrorStatement*)0) != 2) return false;
562     if (sv->visit((PeelStatement*)0) != 3) return false;
563     if (sv->visit2((ExpStatement*)0) != 4) return false;
564     if (sv->visit2((DtorExpStatement*)0) != 5) return false;
565     return true;
566 }
567 
568 Visitor2 inst;
569 
getVisitor2()570 Visitor2* getVisitor2()
571 {
572     return &inst;
573 }
574 
575 /******************************************/
576 // issues detected by fuzzer
577 
578 void fuzz1_checkValues(int64_t arg10, int64_t arg11, bool arg12);
fuzz1_cppvararg(int64_t arg10,int64_t arg11,bool arg12)579 void fuzz1_cppvararg(int64_t arg10, int64_t arg11, bool arg12)
580 {
581     fuzz1_checkValues(arg10, arg11, arg12);
582 }
583 
584 void fuzz2_checkValues(uint64_t arg10, uint64_t arg11, bool arg12);
fuzz2_cppvararg(uint64_t arg10,uint64_t arg11,bool arg12)585 void fuzz2_cppvararg(uint64_t arg10, uint64_t arg11, bool arg12)
586 {
587     fuzz2_checkValues(arg10, arg11, arg12);
588 }
589 
590 #ifdef TEST_UNICODE
591 void fuzz3_checkValues(char16_t arg10, char32_t arg11, bool arg12);
fuzz3_cppvararg(char16_t arg10,char32_t arg11,bool arg12)592 void fuzz3_cppvararg(char16_t arg10, char32_t arg11, bool arg12)
593 {
594     fuzz3_checkValues(arg10, arg11, arg12);
595 }
596 #endif
597 
598 /******************************************/
599 
throwit()600 void throwit()
601 {
602 #if _WIN32
603 #else
604     std::exception se;
605     throw se;
606 #endif
607 }
608 
609 /******************************************/
610 
611 #if __linux__
612 #include <stdexcept>
613 
throwle()614 void throwle()
615 {
616      std::logic_error le("test");
617      throw le;
618 }
619 
620 #endif
621 
622 /******************************************/
623 // https://issues.dlang.org/show_bug.cgi?id=15579
624 
625 /******************************************/
626 // https://issues.dlang.org/show_bug.cgi?id=15579
627 
628 class Base
629 {
630 public:
631     //virtual ~Base() {}
632     virtual void base();
633     unsigned char x;
634 };
635 
636 class Interface
637 {
638 public:
639     virtual int MethodCPP() = 0;
640     virtual int MethodD() = 0;
641 };
642 
643 class Derived : public Base, public Interface
644 {
645 public:
646     Derived();
647     short y;
648     int MethodCPP();
649 #if _WIN32 || _WIN64
650     int MethodD();
651     virtual int Method();
652 #else
MethodD()653     int MethodD() { return 3; }  // need def or vtbl[] is not generated
Method()654     virtual int Method()  { return 6; }  // need def or vtbl[] is not generated
655 #endif
656 };
657 
base()658 void Base::base() { }
MethodCPP()659 int Derived::MethodCPP() {
660     printf("Derived::MethodCPP() this = %p, x = %d, y = %d\n", this, x, y);
661     assert(x == 4 || x == 7);
662     assert(y == 5 || y == 8);
663     return 30;
664 }
Derived()665 Derived::Derived() { }
666 
667 
cppfoo(Derived * d)668 Derived *cppfoo(Derived *d)
669 {
670     printf("cppfoo(): d = %p\n", d);
671     assert(d->x == 4);
672     assert(d->y == 5);
673     assert(d->MethodD() == 3);
674     assert(d->MethodCPP() == 30);
675     assert(d->Method() == 6);
676 
677     d = new Derived();
678     d->x = 7;
679     d->y = 8;
680     assert(d->MethodD() == 3);
681     assert(d->MethodCPP() == 30);
682     assert(d->Method() == 6);
683     printf("d1 = %p\n", d);
684     return d;
685 }
686 
cppfooi(Interface * i)687 Interface *cppfooi(Interface *i)
688 {
689     printf("cppfooi(): i = %p\n", i);
690     assert(i->MethodD() == 3);
691     assert(i->MethodCPP() == 30);
692 
693     Derived *d = new Derived();
694     d->x = 7;
695     d->y = 8;
696     printf("d = %p, i = %p\n", d, (Interface *)d);
697     return d;
698 }
699 
700 /******************************************/
701 // https://issues.dlang.org/show_bug.cgi?id=15610
702 
703 class Base2
704 {
705   public:
706     int i;
baser()707     virtual void baser() { }
708 };
709 
710 class Interface2
711 {
712   public:
713     virtual void f() = 0;
714 };
715 
716 class Derived2 : public Base2, public Interface2
717 {
718   public:
719     void f();
720 };
721 
f()722 void Derived2::f()
723 {
724     printf("Derived2::f() this = %p i = %d\n", this, i);
725     assert(i == 3);
726 }
727 
728 /******************************************/
729 // https://issues.dlang.org/show_bug.cgi?id=15455
730 
731 struct X6
732 {
733     unsigned short a;
734     unsigned short b;
735     unsigned char c;
736     unsigned char d;
737 };
738 
739 struct X8
740 {
741     unsigned short a;
742     X6 b;
743 };
744 
test15455b(X8 s)745 void test15455b(X8 s)
746 {
747     assert(sizeof(X6) == 6);
748     assert(sizeof(X8) == 8);
749     assert(s.a == 1);
750     assert(s.b.a == 2);
751     assert(s.b.b == 3);
752     assert(s.b.c == 4);
753     assert(s.b.d == 5);
754 }
755 
756 /******************************************/
757 // https://issues.dlang.org/show_bug.cgi?id=15372
758 
759 template <typename T>
foo15372(int value)760 int foo15372(int value)
761 {
762     return value;
763 }
764 
test15372b()765 void test15372b()
766 {
767     int t = foo15372<int>(1);
768 }
769 
770 /****************************************/
771 // https://issues.dlang.org/show_bug.cgi?id=15576
772 
773 namespace ns15576
774 {
775     int global15576;
776 
777     namespace ns
778     {
779         int n_global15576;
780     }
781 }
782 
783 /****************************************/
784 // https://issues.dlang.org/show_bug.cgi?id=15802
785 
786 template <typename T>
787 class Foo15802
788 {
789 public:
boo(int value)790     static int boo(int value)
791     {
792         return value;
793     }
794 };
795 
test15802b()796 void test15802b()
797 {
798     int t = Foo15802<int>::boo(1);
799 }
800 
801 
802 /****************************************/
803 // https://issues.dlang.org/show_bug.cgi?id=16536
804 // mangling mismatch on OSX
805 
806 #if defined(__APPLE__)
pass16536(uint64_t a)807 uint64_t pass16536(uint64_t a)
808 {
809     return a;
810 }
811 #endif
812 
813 /****************************************/
814 // https://issues.dlang.org/show_bug.cgi?id=15589
815 // extern(C++) virtual destructors are not put in vtbl[]
816 
817 class A15589
818 {
819 public:
820     struct S
821     {
822     public:
823         int x;
824     };
825     virtual int foo();
826     virtual ~A15589();
827     S s1;
828     S s2;
829 };
830 class B15589 : public A15589
831 {
832 public:
833     virtual int bar();
834     virtual ~B15589();
835     S s3;
836 };
837 
test15589b(A15589 * p)838 void test15589b(A15589 *p)
839 {
840     assert(p->foo() == 100);
841     assert(((B15589*)p)->bar() == 200);
842     p->~A15589();
843 }
844 
845 
846 /////////////////
847 void trace15589(int ch);
848 
~Cpp15589Base()849 Cpp15589Base::~Cpp15589Base()
850 {
851     trace15589('b');
852 }
853 
Cpp15589Derived()854 Cpp15589Derived::Cpp15589Derived()
855 {
856     b = 1;
857 }
858 
~Cpp15589Derived()859 Cpp15589Derived::~Cpp15589Derived()
860 {
861     trace15589('B');
862 }
863 
Cpp15589BaseVirtual()864 Cpp15589BaseVirtual::Cpp15589BaseVirtual()
865 {
866     c = 2;
867 }
868 
~Cpp15589BaseVirtual()869 Cpp15589BaseVirtual::~Cpp15589BaseVirtual()
870 {
871     trace15589('v');
872 }
873 
Cpp15589DerivedVirtual()874 Cpp15589DerivedVirtual::Cpp15589DerivedVirtual()
875 {
876     d = 3;
877 }
878 
~Cpp15589DerivedVirtual()879 Cpp15589DerivedVirtual::~Cpp15589DerivedVirtual()
880 {
881     trace15589('V');
882 }
883 
Cpp15589IntroducingVirtual()884 Cpp15589IntroducingVirtual::Cpp15589IntroducingVirtual()
885 {
886     e = 4;
887 }
888 
~Cpp15589IntroducingVirtual()889 Cpp15589IntroducingVirtual::~Cpp15589IntroducingVirtual()
890 {
891     trace15589('I');
892 }
893 
~Cpp15589Struct()894 Cpp15589Struct::~Cpp15589Struct()
895 {
896     trace15589('s');
897 }
898 
899 /****************************************/
900 // https://issues.dlang.org/show_bug.cgi?id=18928
901 
902 struct Small18928
903 {
904     int x;
905 };
906 
907 class CC18928
908 {
909 public:
910     virtual Small18928 getVirtual();
911     Small18928 getFinal();
912     static Small18928 getStatic();
913 };
914 
getVirtual()915 Small18928 CC18928::getVirtual() { Small18928 s = {3}; return s; }
getFinal()916 Small18928 CC18928::getFinal()   { Small18928 s = {4}; return s; }
getStatic()917 Small18928 CC18928::getStatic()  { Small18928 s = {5}; return s; }
918 
newCC18928()919 CC18928* newCC18928()
920 {
921     return new CC18928();
922 }
923 
924 /****************************************/
925 // https://issues.dlang.org/show_bug.cgi?id=18966
Base18966()926 Base18966::Base18966() { x = 10; }
~Base18966()927 Base18966::~Base18966() {}
vf()928 void Base18966::vf()
929 {
930     x = 100;
931 }
932 
A18966()933 A18966::A18966() : calledOverloads(/*zero-init*/), i(0) { foo(); }
foo()934 void A18966::foo() { calledOverloads[i++] = 'A'; }
935 
B18966()936 B18966::B18966() { foo(); }
foo()937 void B18966::foo() { calledOverloads[i++] = 'B'; }
938 
939 #if _WIN32 // otherwise defined in C header files!
940 // https://issues.dlang.org/show_bug.cgi?id=18955
941 namespace std
942 {
943     template<typename Char>
944     struct char_traits
945     {
946     };
947     template<typename Char>
948     class allocator
949     {
950     };
951     template<typename Char, typename Traits, typename Alloc>
952     class basic_string
953     {
954     };
955     typedef basic_string<char, char_traits<char>, allocator<char> > string;
956 }
957 #endif // _WIN32
958 
959 void callback18955(const std::string& s);
960 
test18955()961 void test18955()
962 {
963     std::string s;
964 // TODO: on OSX and FreeBSD, std is mangled as std::__1
965 #if !__APPLE__ && !__FreeBSD__
966     callback18955(s);
967 #endif
968 }
969