-d1a606599e7c2bea8fda8bf5e3ddceb486ae69ac
+3e10e2dd29e583f1d94d84de5e4bd858e0303669
The first line of this file holds the git revision number of the last
merge done from the dlang/dmd repository.
+2020-03-29 Iain Buclaw <ibuclaw@gdcproject.org>
+
+ * gdc.test/runnable_cxx/runnable_cxx.exp: New file.
+ * lib/gdc-utils.exp (gdc-do-test): Add case for runnable_cxx.
+ * lib/gdc.exp (gdc_include_flags): Only add flags for libstdc++-v3 if
+ GDC_INCLUDE_CXX_FLAGS is true.
+ (gdc_link_flags): Likewise.
+ (gdc_init): Move setting of default gdc test flags to...
+ (gdc_target_compile): ...here.
+
2020-03-29 Iain Buclaw <ibuclaw@gdcproject.org>
* gdc.test/compilable/compilable.exp: New file.
+++ /dev/null
-
-// EXTRA_CPP_SOURCES: cabi2.cpp
-
-import core.stdc.stdio;
-import core.stdc.config;
-
-struct Foo1 { char c; }
-struct Foo2 { short s; }
-struct Foo3 { char c; short s; }
-struct Foo4 { int i; }
-struct Foo5 { int i, j; }
-struct Foo6 { int i, j, k; }
-struct S7 { float a, b; }
-
-extern (C) Foo1 ctest1();
-extern (C) Foo2 ctest2();
-extern (C) Foo3 ctest3();
-extern (C) Foo4 ctest4();
-extern (C) Foo5 ctest5();
-extern (C) Foo6 ctest6();
-extern (C) S7 ctest10();
-
-version(Windows)
- version = Windows_or_32bit;
-else version(X86)
- version = Windows_or_32bit;
-
-
-void test1()
-{
- Foo1 f1 = ctest1();
- assert(f1.c == 3);
-
- Foo2 f2 = ctest2();
- assert(f2.s == 0x1234);
-
- Foo3 f3 = ctest3();
- assert(f3.s == 0x5678);
-
- Foo4 f4 = ctest4();
- assert(f4.i == 0x12345678);
-
- Foo5 f5 = ctest5();
- assert(f5.i == 0x12345678);
- assert(f5.j == 0x21436587);
-
-version(Windows_or_32bit)
-{
- Foo6 f6 = ctest6();
- assert(f6.i == 0x12345678);
- assert(f6.j == 0x21463587);
- assert(f6.k == 0x24163857);
-}
-
- S7 s7 = ctest10();
- assert(s7.a == 2.5);
- assert(s7.b == 1.5);
-}
-
-/*******************************************/
-
-extern (C)
-{
- char ctest7(char);
- ubyte ctest8(ubyte);
- byte ctest9(byte);
-}
-
-void test2()
-{
- assert(ctest7('a') == 'b');
- assert(ctest8(7) == 8);
- assert(ctest9(3) == 4);
-}
-
-/******************************************/
-
-extern (C)
-{
- void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, c_long_double a, int b, c_long_double c);
-}
-
-void test3()
-{
- ctestrir(1,2,3,4,5,6, c_long_double(100.0), 67, c_long_double(200.0));
-}
-
-/******************************************/
-
-extern (C) void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, c_long_double a, int b, c_long_double c)
-{
- assert(a == 300.0);
- assert(b == 68);
- assert(c == 401.0);
-}
-
-extern (C) void test4();
-
-/******************************************/
-
-struct S11 { ubyte a, b, c; }
-
-extern (C) S11 ctest11(ubyte x, S11, ubyte y);
-
-void test11()
-{
- version (X86)
- {
- S11 t;
- assert(S11.sizeof == 3);
- t.a = 2;
- t.b = 3;
- t.c = 4;
- auto s = ctest11(1, t, 5);
- assert(s.a == 2);
- assert(s.b == 3);
- assert(s.c == 4);
- }
-}
-
-/******************************************/
-
-struct S12 { char a,d; char b,e; ubyte c; }
-
-extern (C) S12 ctest12(ubyte x, S12, ubyte y);
-
-void test12()
-{
- version (X86)
- {
- S12 t;
- printf("D sz = %d\n", cast(int)S12.sizeof);
-// assert(S12.sizeof == 5);
- t.a = 2;
- t.b = 3;
- t.c = 4;
- auto s = ctest12(1, t, 5);
- assert(s.a == 2);
- assert(s.b == 3);
- assert(s.c == 4);
- }
-}
-
-/******************************************/
-
-struct S13 { ushort a, b, c; }
-
-extern (C) S13 ctest13(ubyte x, S13, ubyte y);
-
-void test13()
-{
- version (X86)
- {
- S13 t;
- assert(S13.sizeof == 6);
- t.a = 2;
- t.b = 3;
- t.c = 4;
- auto s = ctest13(1, t, 5);
- assert(s.a == 2);
- assert(s.b == 3);
- assert(s.c == 4);
- }
-}
-
-/******************************************/
-
-struct S14 { char a,d,e,f; char b,g; ubyte c; }
-
-extern (C) S14 ctest14(ubyte x, S14, ubyte y);
-
-void test14()
-{
- version (X86)
- {
- S14 t;
- assert(S14.sizeof == 7);
- t.a = 2;
- t.b = 3;
- t.c = 4;
- auto s = ctest14(1, t, 5);
- assert(s.a == 2);
- assert(s.b == 3);
- assert(s.c == 4);
- }
-}
-
-/******************************************/
-
-struct S15 { char a,d,e,f; char b,g,h,i; ubyte c; }
-
-extern (C) S15 ctest15(ubyte x, S15, ubyte y);
-
-void test15()
-{
- version (X86)
- {
- S15 t;
- assert(S15.sizeof == 9);
- t.a = 2;
- t.b = 3;
- t.c = 4;
- auto s = ctest15(1, t, 5);
- assert(s.a == 2);
- assert(s.b == 3);
- assert(s.c == 4);
- }
-}
-
-/******************************************/
-
-// see https://issues.dlang.org/show_bug.cgi?id=17277
-struct S16 {
- char[5] a;
- struct {
- char b;
- align(1) int c;
- }
-}
-
-extern (C) S16 ctest16(ubyte x, S16, ubyte y);
-
-void test16()
-{
- version (X86) // misaligned field
- {
- S16 t;
- assert(S16.sizeof == 10);
- assert(S16.alignof == 1);
- t.a = "hello";
- t.b = 3;
- t.c = 0x11223344;
- auto s = ctest16(1, t, 5);
- assert(s.a == "hello");
- assert(s.b == 3);
- assert(s.c == 0x11223344);
- }
-}
-
-/******************************************/
-
-int main()
-{
- test1();
- test2();
- test3();
-version (Win64)
-{
-}
-else
-{
- test4();
-}
- test11();
- test12();
- test13();
- test14();
- test15();
- test16();
-
- return 0;
-}
+++ /dev/null
-// EXTRA_CPP_SOURCES: cpp_abi_tests.cpp
-
-extern(C++) {
-
-struct S
-{
- float a = 1;
-}
-
-bool passthrough(bool value);
-byte passthrough(byte value);
-ubyte passthrough(ubyte value);
-char passthrough(char value);
-dchar passthrough(dchar value);
-short passthrough(short value);
-ushort passthrough(ushort value);
-int passthrough(int value);
-uint passthrough(uint value);
-long passthrough(long value);
-ulong passthrough(ulong value);
-float passthrough(float value);
-double passthrough(double value);
-S passthrough(S value);
-
-bool passthrough_ptr(bool *value);
-byte passthrough_ptr(byte *value);
-ubyte passthrough_ptr(ubyte *value);
-char passthrough_ptr(char *value);
-dchar passthrough_ptr(dchar *value);
-short passthrough_ptr(short *value);
-ushort passthrough_ptr(ushort *value);
-int passthrough_ptr(int *value);
-uint passthrough_ptr(uint *value);
-long passthrough_ptr(long *value);
-ulong passthrough_ptr(ulong *value);
-float passthrough_ptr(float *value);
-double passthrough_ptr(double *value);
-S passthrough_ptr(S *value);
-
-bool passthrough_ref(ref bool value);
-byte passthrough_ref(ref byte value);
-ubyte passthrough_ref(ref ubyte value);
-char passthrough_ref(ref char value);
-dchar passthrough_ref(ref dchar value);
-short passthrough_ref(ref short value);
-ushort passthrough_ref(ref ushort value);
-int passthrough_ref(ref int value);
-uint passthrough_ref(ref uint value);
-long passthrough_ref(ref long value);
-ulong passthrough_ref(ref ulong value);
-float passthrough_ref(ref float value);
-double passthrough_ref(ref double value);
-S passthrough_ref(ref S value);
-}
-
-template IsSigned(T)
-{
- enum IsSigned = is(T==byte) ||
- is(T==short) ||
- is(T==int) ||
- is(T==long);
-}
-
-template IsUnsigned(T)
-{
- enum IsUnsigned = is(T==ubyte) ||
- is(T==ushort) ||
- is(T==uint) ||
- is(T==ulong);
-}
-
-template IsIntegral(T)
-{
- enum IsIntegral = IsSigned!T || IsUnsigned!T;
-}
-
-template IsFloatingPoint(T)
-{
- enum IsFloatingPoint = is(T==float) || is(T==double) || is(T==real);
-}
-
-template IsBoolean(T)
-{
- enum IsBoolean = is(T==bool);
-}
-
-template IsSomeChar(T)
-{
- enum IsSomeChar = is(T==char) || is(T==dchar);
-}
-
-void check(T)(T actual, T expected)
-{
- assert(actual is expected);
-}
-
-void check(T)(T value)
-{
- check(passthrough(value), value);
- check(passthrough_ptr(&value), value);
- check(passthrough_ref(value), value);
-}
-
-T[] values(T)()
-{
- T[] values;
- static if(IsBoolean!T)
- {
- values ~= true;
- values ~= false;
- }
- else static if(IsSomeChar!T)
- {
- values ~= T.init;
- values ~= T('a');
- values ~= T('z');
- }
- else
- {
- values ~= T(0);
- values ~= T(1);
- static if(IsIntegral!T)
- {
- static if(IsSigned!T) values ~= T.min;
- values ~= T.max;
- }
- else static if(IsFloatingPoint!T)
- {
- values ~= T.nan;
- values ~= T.min_normal;
- values ~= T.max;
- }
- else
- {
- assert(0);
- }
- }
- return values;
-}
-
-void main()
-{
- foreach(bool val; values!bool()) check(val);
- foreach(byte val; values!byte()) check(val);
- foreach(ubyte val; values!ubyte()) check(val);
- foreach(char val; values!char()) check(val);
- foreach(dchar val; values!dchar()) check(val);
- foreach(short val; values!short()) check(val);
- foreach(ushort val; values!ushort()) check(val);
- foreach(int val; values!int()) check(val);
- foreach(uint val; values!uint()) check(val);
- foreach(long val; values!long()) check(val);
- foreach(ulong val; values!ulong()) check(val);
- foreach(float val; values!float()) check(val);
- foreach(double val; values!double()) check(val);
- check(S());
-}
+++ /dev/null
-// PERMUTE_ARGS: -g
-// EXTRA_CPP_SOURCES: cppb.cpp
-
-import core.stdc.stdio;
-import core.stdc.stdarg;
-import core.stdc.config;
-
-extern (C++)
- int foob(int i, int j, int k);
-
-class C
-{
- extern (C++) int bar(int i, int j, int k)
- {
- printf("this = %p\n", this);
- printf("i = %d\n", i);
- printf("j = %d\n", j);
- printf("k = %d\n", k);
- return 1;
- }
-}
-
-
-extern (C++)
- int foo(int i, int j, int k)
-{
- printf("i = %d\n", i);
- printf("j = %d\n", j);
- printf("k = %d\n", k);
- assert(i == 1);
- assert(j == 2);
- assert(k == 3);
- return 1;
-}
-
-void test1()
-{
- foo(1, 2, 3);
-
- auto i = foob(1, 2, 3);
- assert(i == 7);
-
- C c = new C();
- c.bar(4, 5, 6);
-}
-
-/****************************************/
-
-extern (C++) interface D
-{
- int bar(int i, int j, int k);
-}
-
-extern (C++) D getD();
-
-void test2()
-{
- D d = getD();
- int i = d.bar(9,10,11);
- assert(i == 8);
-}
-
-/****************************************/
-
-extern (C++) int callE(E);
-
-extern (C++) interface E
-{
- int bar(int i, int j, int k);
-}
-
-class F : E
-{
- extern (C++) int bar(int i, int j, int k)
- {
- printf("F.bar: i = %d\n", i);
- printf("F.bar: j = %d\n", j);
- printf("F.bar: k = %d\n", k);
- assert(i == 11);
- assert(j == 12);
- assert(k == 13);
- return 8;
- }
-}
-
-void test3()
-{
- F f = new F();
- int i = callE(f);
- assert(i == 8);
-}
-
-/****************************************/
-
-extern (C++) void foo4(char* p);
-
-void test4()
-{
- foo4(null);
-}
-
-/****************************************/
-
-extern(C++)
-{
- struct foo5 { int i; int j; void* p; }
-
- interface bar5{
- foo5 getFoo(int i);
- }
-
- bar5 newBar();
-}
-
-void test5()
-{
- bar5 b = newBar();
- foo5 f = b.getFoo(4);
- printf("f.p = %p, b = %p\n", f.p, cast(void*)b);
- assert(f.p == cast(void*)b);
-}
-
-
-/****************************************/
-
-extern(C++)
-{
- struct S6
- {
- int i;
- double d;
- }
-
- union S6_2
- {
- int i;
- double d;
- }
-
- enum S6_3
- {
- A, B
- }
-
- S6 foo6();
- S6_2 foo6_2();
- S6_3 foo6_3();
-}
-
-extern (C) int foosize6();
-
-void test6()
-{
- S6 f = foo6();
- printf("%d %d\n", foosize6(), S6.sizeof);
- assert(foosize6() == S6.sizeof);
-version (X86)
-{
- assert(f.i == 42);
- printf("f.d = %g\n", f.d);
- assert(f.d == 2.5);
- assert(foo6_2().i == 42);
- assert(foo6_3() == S6_3.A);
-}
-}
-
-/****************************************/
-
-extern (C) int foo7();
-
-struct S
-{
- int i;
- long l;
-}
-
-void test7()
-{
- printf("%d %d\n", foo7(), S.sizeof);
- assert(foo7() == S.sizeof);
-}
-
-/****************************************/
-
-extern (C++) void foo8(const(char)*);
-
-void test8()
-{
- char c;
- foo8(&c);
-}
-
-/****************************************/
-// 4059
-
-struct elem9 { }
-
-extern(C++) void foobar9(elem9*, elem9*);
-
-void test9()
-{
- elem9 *a;
- foobar9(a, a);
-}
-
-/****************************************/
-
-
-struct A11802;
-struct B11802;
-
-extern(C++) class C11802
-{
- int x;
- void fun(A11802*) { x += 2; }
- void fun(B11802*) { x *= 2; }
-}
-
-extern(C++) class D11802 : C11802
-{
- override void fun(A11802*) { x += 3; }
- override void fun(B11802*) { x *= 3; }
-}
-
-extern(C++) void test11802x(D11802);
-
-void test11802()
-{
- auto x = new D11802();
- x.x = 0;
- test11802x(x);
- assert(x.x == 9);
-}
-
-
-/****************************************/
-
-struct S13956
-{
-}
-
-extern(C++) void func13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
-
-extern(C++) void check13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
-{
- assert(arg0 == S13956());
- assert(arg1 == 1);
- assert(arg2 == 2);
- assert(arg3 == 3);
- assert(arg4 == 4);
- assert(arg5 == 5);
- version (OSX)
- {
- version (D_LP64)
- assert(arg6 == 6);
- // fails on OSX 32-bit
- }
- else
- assert(arg6 == 6);
-}
-
-void test13956()
-{
- func13956(S13956(), 1, 2, 3, 4, 5, 6);
-}
-
-/****************************************/
-// 5148
-
-extern (C++)
-{
- void foo10(const(char)*, const(char)*);
- void foo10(const int, const int);
- void foo10(const char, const char);
- void foo10(bool, bool);
-
- struct MyStructType { }
- void foo10(const MyStructType s, const MyStructType t);
-
- enum MyEnumType { onemember }
- void foo10(const MyEnumType s, const MyEnumType t);
-}
-
-void test10()
-{
- char* p;
- foo10(p, p);
- foo10(1,2);
- foo10('c','d');
- MyStructType s;
- foo10(s,s);
- MyEnumType e;
- foo10(e,e);
-}
-
-/****************************************/
-
-extern (C++, N11.M) { void bar11(); }
-
-extern (C++, A11.B) { extern (C++, C) { void bar(); }}
-
-void test11()
-{
- bar11();
- A11.B.C.bar();
-}
-/****************************************/
-
-struct Struct10071
-{
- void *p;
- c_long_double r;
-}
-
-extern(C++) size_t offset10071();
-void test10071()
-{
- assert(offset10071() == Struct10071.r.offsetof);
-}
-
-/****************************************/
-
-char[100] valistbuffer;
-
-extern(C++) void myvprintfx(const(char)* format, va_list va)
-{
- vsprintf(valistbuffer.ptr, format, va);
-}
-extern(C++) void myvprintf(const(char)*, va_list);
-extern(C++) void myprintf(const(char)* format, ...)
-{
- va_list ap;
- va_start(ap, format);
- myvprintf(format, ap);
- va_end(ap);
-}
-
-void testvalist()
-{
- myprintf("hello %d", 999);
- assert(valistbuffer[0..9] == "hello 999");
-}
-
-/****************************************/
-// 12825
-
-extern(C++) class C12825
-{
- uint a = 0x12345678;
-}
-
-void test12825()
-{
- auto c = new C12825();
-}
-
-/****************************************/
-
-struct S13955a
-{
- float a;
- double b;
-}
-
-struct S13955b
-{
- double a;
- float b;
-}
-
-struct S13955c
-{
- float a;
- float b;
-}
-
-struct S13955d
-{
- double a;
- double b;
-}
-
-extern(C++) void check13955(S13955a a, S13955b b, S13955c c, S13955d d)
-{
- assert(a.a == 2);
- assert(a.b == 4);
- assert(b.a == 8);
- assert(b.b == 16);
- assert(c.a == 32);
- assert(c.b == 64);
- assert(d.a == 128);
- assert(d.b == 256);
-}
-
-extern(C++) void func13955(S13955a a, S13955b b, S13955c c, S13955d d);
-
-void test13955()
-{
- func13955(S13955a(2, 4), S13955b(8, 16), S13955c(32, 64), S13955d(128, 256));
-}
-
-/****************************************/
-
-extern(C++) class C13161
-{
- void dummyfunc();
- long val_5;
- uint val_9;
-}
-
-extern(C++) class Test : C13161
-{
- uint val_0;
- long val_1;
-}
-
-extern(C++) size_t getoffset13161();
-
-extern(C++) class C13161a
-{
- void dummyfunc();
- c_long_double val_5;
- uint val_9;
-}
-
-extern(C++) class Testa : C13161a
-{
- bool val_0;
-}
-
-extern(C++) size_t getoffset13161a();
-
-void test13161()
-{
- assert(getoffset13161() == Test.val_0.offsetof);
- assert(getoffset13161a() == Testa.val_0.offsetof);
-}
-
-/****************************************/
-
-version (linux)
-{
- extern(C++, __gnu_cxx)
- {
- struct new_allocator(T)
- {
- alias size_type = size_t;
- static if (is(T : char))
- void deallocate(T*, size_type) { }
- else
- void deallocate(T*, size_type);
- }
- }
-}
-
-extern (C++, std)
-{
- struct allocator(T)
- {
- version (linux)
- {
- alias size_type = size_t;
- void deallocate(T* p, size_type sz)
- { (cast(__gnu_cxx.new_allocator!T*)&this).deallocate(p, sz); }
- }
- }
-
- version (linux)
- {
- class vector(T, A = allocator!T)
- {
- final void push_back(ref const T);
- }
-
- struct char_traits(T)
- {
- }
-
- // https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
- version (none)
- {
- extern (C++, __cxx11)
- {
- struct basic_string(T, C = char_traits!T, A = allocator!T)
- {
- }
- }
- }
- else
- {
- struct basic_string(T, C = char_traits!T, A = allocator!T)
- {
- }
- }
-
- struct basic_istream(T, C = char_traits!T)
- {
- }
-
- struct basic_ostream(T, C = char_traits!T)
- {
- }
-
- struct basic_iostream(T, C = char_traits!T)
- {
- }
- }
-
- class exception { }
-
- // 14956
- extern(C++, N14956)
- {
- struct S14956 { }
- }
-}
-
-extern (C++)
-{
- version (linux)
- {
- void foo14(std.vector!(int) p);
- void foo14a(std.basic_string!(char) *p);
- void foo14b(std.basic_string!(int) *p);
- void foo14c(std.basic_istream!(char) *p);
- void foo14d(std.basic_ostream!(char) *p);
- void foo14e(std.basic_iostream!(char) *p);
-
- void foo14f(std.char_traits!char* x, std.basic_string!char* p, std.basic_string!char* q);
- }
-}
-
-void test14()
-{
- version (linux)
- {
- std.vector!int p;
- foo14(p);
-
- foo14a(null);
- foo14b(null);
- foo14c(null);
- foo14d(null);
- foo14e(null);
- foo14f(null, null, null);
- }
-}
-
-version (linux)
-{
- void test14a(std.allocator!int * pa)
- {
- pa.deallocate(null, 0);
- }
-
- void gun(std.vector!int pa)
- {
- int x = 42;
- pa.push_back(x);
- }
-}
-
-void test13289()
-{
- assert(f13289_cpp_wchar_t('a') == 'A');
- assert(f13289_cpp_wchar_t('B') == 'B');
- assert(f13289_d_wchar('c') == 'C');
- assert(f13289_d_wchar('D') == 'D');
- assert(f13289_d_dchar('e') == 'E');
- assert(f13289_d_dchar('F') == 'F');
- assert(f13289_cpp_test());
-}
-
-extern(C++)
-{
- bool f13289_cpp_test();
-
- version(Posix)
- {
- dchar f13289_cpp_wchar_t(dchar);
- }
- else version(Windows)
- {
- wchar f13289_cpp_wchar_t(wchar);
- }
-
- wchar f13289_d_wchar(wchar ch)
- {
- if (ch <= 'z' && ch >= 'a')
- {
- return cast(wchar)(ch - ('a' - 'A'));
- }
- else
- {
- return ch;
- }
- }
- dchar f13289_d_dchar(dchar ch)
- {
- if (ch <= 'z' && ch >= 'a')
- {
- return ch - ('a' - 'A');
- }
- else
- {
- return ch;
- }
- }
-}
-
-/****************************************/
-
-version (CRuntime_Microsoft)
-{
- enum __c_long_double : double;
- alias __c_long_double myld;
-}
-else
- alias c_long_double myld;
-
-extern (C++) myld testld(myld);
-extern (C++) myld testldld(myld, myld);
-
-
-void test15()
-{
- myld ld = 5.0;
- ld = testld(ld);
- assert(ld == 6.0);
-
- myld ld2 = 5.0;
- ld2 = testldld(ld2, ld2);
- assert(ld2 == 6.0);
-}
-
-/****************************************/
-
-version( Windows )
-{
- alias int x_long;
- alias uint x_ulong;
-}
-else
-{
- static if( (void*).sizeof > int.sizeof )
- {
- alias long x_long;
- alias ulong x_ulong;
- }
- else
- {
- alias int x_long;
- alias uint x_ulong;
- }
-}
-
-enum __c_long : x_long;
-enum __c_ulong : x_ulong;
-alias __c_long mylong;
-alias __c_ulong myulong;
-
-extern (C++) mylong testl(mylong);
-extern (C++) myulong testul(myulong);
-
-
-void test16()
-{
- {
- mylong ld = 5;
- ld = testl(ld);
- assert(ld == 5 + mylong.sizeof);
- }
- {
- myulong ld = 5;
- ld = testul(ld);
- assert(ld == 5 + myulong.sizeof);
- }
-
- static if (__c_long.sizeof == long.sizeof)
- {
- static assert(__c_long.max == long.max);
- static assert(__c_long.min == long.min);
- static assert(__c_long.init == long.init);
- static assert(__c_ulong.max == ulong.max);
- static assert(__c_ulong.min == ulong.min);
- static assert(__c_ulong.init == ulong.init);
- __c_long cl = 0;
- cl = cl + 1;
- long l = cl;
- cl = l;
- __c_ulong cul = 0;
- cul = cul + 1;
- ulong ul = cul;
- cul = ul;
- }
- else static if (__c_long.sizeof == int.sizeof)
- {
- static assert(__c_long.max == int.max);
- static assert(__c_long.min == int.min);
- static assert(__c_long.init == int.init);
- static assert(__c_ulong.max == uint.max);
- static assert(__c_ulong.min == uint.min);
- static assert(__c_ulong.init == uint.init);
- __c_long cl = 0;
- cl = cl + 1;
- int i = cl;
- cl = i;
- __c_ulong cul = 0;
- cul = cul + 1;
- uint u = cul;
- cul = u;
- }
- else
- static assert(0);
-}
-
-/****************************************/
-
-struct S13707
-{
- void* a;
- void* b;
- this(void* a, void* b)
- {
- this.a = a;
- this.b = b;
- }
-}
-
-extern(C++) S13707 func13707();
-
-void test13707()
-{
- auto p = func13707();
- assert(p.a == null);
- assert(p.b == null);
-}
-
-/****************************************/
-
-struct S13932(int x)
-{
- int member;
-}
-
-extern(C++) void func13932(S13932!(-1) s);
-
-/****************************************/
-
-extern(C++, N13337.M13337)
-{
- struct S13337{}
- void foo13337(S13337 s);
-}
-
-/****************************************/
-// 14195
-
-struct Delegate1(T) {}
-struct Delegate2(T1, T2) {}
-
-template Signature(T)
-{
- alias Signature = typeof(*(T.init));
-}
-
-extern(C++)
-{
- alias del1_t = Delegate1!(Signature!(void function()));
- alias del2_t = Delegate2!(Signature!(int function(float, double)), Signature!(int function(float, double)));
- void test14195a(del1_t);
- void test14195b(del2_t);
-}
-
-void test14195()
-{
- test14195a(del1_t());
- test14195b(del2_t());
-}
-
-
-/****************************************/
-// 14200
-
-template Tuple14200(T...)
-{
- alias Tuple14200 = T;
-}
-
-extern(C++) void test14200a(Tuple14200!(int));
-extern(C++) void test14200b(float, Tuple14200!(int, double));
-
-void test14200()
-{
- test14200a(1);
- test14200b(1.0f, 1, 1.0);
-}
-
-/****************************************/
-// 14956
-
-extern(C++) void test14956(S14956 s);
-
-/****************************************/
-// check order of overloads in vtable
-
-extern (C++) class Statement {}
-extern (C++) class ErrorStatement {}
-extern (C++) class PeelStatement {}
-extern (C++) class ExpStatement {}
-extern (C++) class DtorExpStatement {}
-
-extern (C++) class Visitor
-{
-public:
- int visit(Statement) { return 1; }
- int visit(ErrorStatement) { return 2; }
- int visit(PeelStatement) { return 3; }
-}
-
-extern (C++) class Visitor2 : Visitor
-{
- int visit2(ExpStatement) { return 4; }
- int visit2(DtorExpStatement) { return 5; }
-}
-
-extern(C++) bool testVtableCpp(Visitor2 sv);
-extern(C++) Visitor2 getVisitor2();
-
-bool testVtableD(Visitor2 sv)
-{
- Statement s1;
- ErrorStatement s2;
- PeelStatement s3;
- ExpStatement s4;
- DtorExpStatement s5;
-
- if (sv.visit(s1) != 1) return false;
- if (sv.visit(s2) != 2) return false;
- if (sv.visit(s3) != 3) return false;
- if (sv.visit2(s4) != 4) return false;
- if (sv.visit2(s5) != 5) return false;
- return true;
-}
-
-void testVtable()
-{
- Visitor2 dinst = new Visitor2;
- if (!testVtableCpp(dinst))
- assert(0);
-
- Visitor2 cppinst = getVisitor2();
- if (!testVtableD(cppinst))
- assert(0);
-}
-
-/****************************************/
-/* problems detected by fuzzer */
-extern(C++) void fuzz1_cppvararg(long arg10, long arg11, bool arg12);
-extern(C++) void fuzz1_dvararg(long arg10, long arg11, bool arg12)
-{
- fuzz1_checkValues(arg10, arg11, arg12);
-}
-
-extern(C++) void fuzz1_checkValues(long arg10, long arg11, bool arg12)
-{
- assert(arg10 == 103);
- assert(arg11 == 104);
- assert(arg12 == false);
-}
-
-void fuzz1()
-{
- long arg10 = 103;
- long arg11 = 104;
- bool arg12 = false;
- fuzz1_dvararg(arg10, arg11, arg12);
- fuzz1_cppvararg(arg10, arg11, arg12);
-}
-
-////////
-extern(C++) void fuzz2_cppvararg(ulong arg10, ulong arg11, bool arg12);
-extern(C++) void fuzz2_dvararg(ulong arg10, ulong arg11, bool arg12)
-{
- fuzz2_checkValues(arg10, arg11, arg12);
-}
-
-extern(C++) void fuzz2_checkValues(ulong arg10, ulong arg11, bool arg12)
-{
- assert(arg10 == 103);
- assert(arg11 == 104);
- assert(arg12 == false);
-}
-
-void fuzz2()
-{
- ulong arg10 = 103;
- ulong arg11 = 104;
- bool arg12 = false;
- fuzz2_dvararg(arg10, arg11, arg12);
- fuzz2_cppvararg(arg10, arg11, arg12);
-}
-
-////////
-extern(C++) void fuzz3_cppvararg(wchar arg10, wchar arg11, bool arg12);
-extern(C++) void fuzz3_dvararg(wchar arg10, wchar arg11, bool arg12)
-{
- fuzz2_checkValues(arg10, arg11, arg12);
-}
-
-extern(C++) void fuzz3_checkValues(wchar arg10, wchar arg11, bool arg12)
-{
- assert(arg10 == 103);
- assert(arg11 == 104);
- assert(arg12 == false);
-}
-
-void fuzz3()
-{
- wchar arg10 = 103;
- wchar arg11 = 104;
- bool arg12 = false;
- fuzz3_dvararg(arg10, arg11, arg12);
- fuzz3_cppvararg(arg10, arg11, arg12);
-}
-
-void fuzz()
-{
- fuzz1();
- fuzz2();
- fuzz3();
-}
-
-/****************************************/
-
-extern (C++)
-{
- void throwit();
-}
-
-void testeh()
-{
- printf("testeh()\n");
- version (linux)
- {
- version (X86_64)
- {
- bool caught;
- try
- {
- throwit();
- }
- catch (std.exception e)
- {
- caught = true;
- }
- assert(caught);
- }
- }
-}
-
-/****************************************/
-
-version (linux)
-{
- version (X86_64)
- {
- bool raii_works = false;
- struct RAIITest
- {
- ~this()
- {
- raii_works = true;
- }
- }
-
- void dFunction()
- {
- RAIITest rt;
- throwit();
- }
-
- void testeh2()
- {
- printf("testeh2()\n");
- try
- {
- dFunction();
- }
- catch(std.exception e)
- {
- assert(raii_works);
- }
- }
- }
- else
- void testeh2() { }
-}
-else
- void testeh2() { }
-
-/****************************************/
-
-extern (C++) { void throwle(); void throwpe(); }
-
-void testeh3()
-{
- printf("testeh3()\n");
- version (linux)
- {
- version (X86_64)
- {
- bool caught = false;
- try
- {
- throwle();
- }
- catch (std.exception e) //polymorphism test.
- {
- caught = true;
- }
- assert(caught);
- }
- }
-}
-
-/****************************************/
-// 15576
-
-extern (C++, ns15576)
-{
- extern __gshared int global15576;
-
- extern (C++, ns)
- {
- extern __gshared int n_global15576;
- }
-}
-
-void test15576()
-{
- global15576 = n_global15576 = 123;
-}
-
-/****************************************/
-// 15579
-
-extern (C++)
-{
- class Base
- {
- //~this() {}
- void based() { }
- ubyte x = 4;
- }
-
- interface Interface
- {
- int MethodCPP();
- int MethodD();
- }
-
- class Derived : Base, Interface
- {
- short y = 5;
- int MethodCPP();
- int MethodD() {
- printf("Derived.MethodD(): this = %p, x = %d, y = %d\n", this, x, y);
- Derived p = this;
- //p = cast(Derived)(cast(void*)p - 16);
- assert(p.x == 4 || p.x == 7);
- assert(p.y == 5 || p.y == 8);
- return 3;
- }
- int Method() { return 6; }
- }
-
- Derived cppfoo(Derived);
- Interface cppfooi(Interface);
-}
-
-void test15579()
-{
- Derived d = new Derived();
- printf("d = %p\n", d);
- assert(d.x == 4);
- assert(d.y == 5);
- assert((cast(Interface)d).MethodCPP() == 30);
- assert((cast(Interface)d).MethodD() == 3);
- assert(d.MethodCPP() == 30);
- assert(d.MethodD() == 3);
- assert(d.Method() == 6);
-
- d = cppfoo(d);
- assert(d.x == 7);
- assert(d.y == 8);
-
- printf("d2 = %p\n", d);
-
- /* Casting to an interface involves thunks in the vtbl[].
- * g++ puts the thunks for MethodD in the same COMDAT as MethodD.
- * But D doesn't, so when the linker "picks one" of the D generated MethodD
- * or the g++ generated MethodD, it may wind up with a messed up thunk,
- * resulting in a seg fault. The solution is to not expect objects of the same
- * type to be constructed on both sides of the D/C++ divide if the same member
- * function (in this case, MethodD) is also defined on both sides.
- */
- version (Windows)
- {
- assert((cast(Interface)d).MethodD() == 3);
- }
- assert((cast(Interface)d).MethodCPP() == 30);
-
- assert(d.Method() == 6);
-
- printf("d = %p, i = %p\n", d, cast(Interface)d);
- version (Windows)
- {
- Interface i = cppfooi(d);
- printf("i2: %p\n", i);
- assert(i.MethodD() == 3);
- assert(i.MethodCPP() == 30);
- }
- printf("test15579() done\n");
-}
-
-/****************************************/
-// 15610
-
-extern(C++) class Base2
-{
- int i;
- void baser() { }
-}
-
-extern(C++) interface Interface2 { abstract void f(); }
-
-extern(C++) class Derived2 : Base2, Interface2
-{
- final
- override void f();
-}
-
-
-void test15610()
-{
- auto c = new Derived2();
- printf("test15610(): c = %p\n", c);
- c.i = 3;
- c.f();
-}
-
-/******************************************/
-// 15455
-
-struct X6
-{
- ushort a;
- ushort b;
- ubyte c;
- ubyte d;
-}
-
-static assert(X6.sizeof == 6);
-
-struct X8
-{
- ushort a;
- X6 b;
-}
-
-static assert(X8.sizeof == 8);
-
-void test15455a(X8 s)
-{
- assert(s.a == 1);
- assert(s.b.a == 2);
- assert(s.b.b == 3);
- assert(s.b.c == 4);
- assert(s.b.d == 5);
-}
-
-extern (C++) void test15455b(X8 s);
-
-void test15455()
-{
- X8 s;
-
- s.a = 1;
- s.b.a = 2;
- s.b.b = 3;
- s.b.c = 4;
- s.b.d = 5;
- test15455a(s);
- test15455b(s);
-}
-
-/****************************************/
-// 15372
-
-extern(C++) int foo15372(T)(T v);
-
-void test15372()
-{
- version(Windows){}
- else
- assert(foo15372!int(1) == 1);
-}
-
-/****************************************/
-// 15802
-
-extern(C++) {
- template Foo15802(T) {
- static int boo(T v);
- }
-}
-
-void test15802()
-{
- version(Windows){}
- else
- assert(Foo15802!(int).boo(1) == 1);
-}
-
-/****************************************/
-// 16536 - mangling mismatch on OSX
-
-version(OSX) extern(C++) ulong pass16536(ulong);
-
-void test16536()
-{
- version(OSX) assert(pass16536(123) == 123);
-}
-
-/****************************************/
-
-void main()
-{
- test1();
- test2();
- test3();
- test4();
- test13956();
- test5();
- test6();
- test10071();
- test7();
- test8();
- test11802();
- test9();
- test10();
- test13955();
- test11();
- testvalist();
- test12825();
- test13161();
- test14();
- test13289();
- test15();
- test16();
- func13707();
- func13932(S13932!(-1)(0));
- foo13337(S13337());
- test14195();
- test14200();
- test14956(S14956());
- testVtable();
- fuzz();
- testeh();
- testeh2();
- testeh3();
- test15576();
- test15579();
- test15610();
- test15455();
- test15372();
- test15802();
- test16536();
-
- printf("Success\n");
-}
+++ /dev/null
-// EXTRA_CPP_SOURCES: externmangle.cpp
-
-extern(C++):
-
-struct Foo(X)
-{
- X* v;
-}
-
-
-struct Boo(X)
-{
- X* v;
-}
-
-
-void test1(Foo!int arg1);
-void test2(int* arg2, Boo!(int*) arg1);
-
-
-struct Test3(int X, int Y)
-{
-}
-
-void test3(Test3!(3,3) arg1);
-
-void test4(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3, int*, Foo!(double));
-
-void test5(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3);
-
-
-struct Goo
-{
- struct Foo(X)
- {
- X* v;
- }
-
- struct Boo(X)
- {
- struct Xoo(Y)
- {
- Y* v;
- };
- X* v;
- }
-
-
- void test6(Foo!(Boo!(Foo!(void))) arg1);
- void test7(Boo!(void).Xoo!(int) arg1);
-}
-
-struct P1
-{
- struct Mem(T)
- {
- }
-}
-
-struct P2
-{
- struct Mem(T)
- {
- }
-}
-
-void test8(P1.Mem!int, P2.Mem!int);
-void test9(Foo!(int**), Foo!(int*), int**, int*);
-
-
-interface Test10
-{
- private final void test10();
- public final void test11();
- protected final void test12();
- public final void test13() const;
-
- private void test14();
- public void test15();
- protected void test16();
-
- private static void test17();
- public static void test18();
- protected static void test19();
-};
-
-Test10 Test10Ctor();
-void Test10Dtor(ref Test10 ptr);
-
-struct Test20
-{
- __gshared:
- private extern int test20;
- protected extern int test21;
- public extern int test22;
-};
-
-
-int test23(Test10*, Test10, Test10**, const(Test10));
-int test23b(const Test10*, const Test10, Test10);
-
-void test24(int function(int,int));
-
-void test25(int[291][6][5]* arr);
-int test26(int[291][6]* arr);
-
-void test27(int, ...);
-void test28(int);
-
-void test29(float);
-void test30(const float);
-
-struct Array(T)
-{
- int dim;
-}
-
-
-interface Module
-{
- public static void imports(Module);
- public static int dim(Array!Module*);
-};
-
-ulong testlongmangle(int a, uint b, long c, ulong d);
-
-__gshared extern int[2][2][2] test31;
-__gshared extern int* test32;
-
-
-alias int function(Expression , void* ) apply_fp_t;
-
-interface Expression
-{
- public final int apply(apply_fp_t fp, apply_fp_t fp2, void* param);
- public final int getType();
- public static Expression create(int);
- public static void dispose(ref Expression);
-}
-
-//int test34(int[0][0]*);
-version(CRuntime_Microsoft){}
-else
-{
- int test35(real arg);
-}
-
-const(char)* test36(const(char)*);
-
-final class Test37
-{
- static Test37 create()
- {
- return new Test37;
- }
-
- bool test()
- {
- return true;
- }
-}
-
-bool test37();
-
-interface Test38
-{
- final int test(int, ...);
- public static Test38 create();
- public static void dispose(ref Test38);
-}
-
-extern(C++) int test39cpp(C2!char, S2!(int)*);
-
-extern(C++, class)
-struct S1
-{
- private int val;
- static S1* init(int);
- int value();
-}
-
-extern(C++, class)
-struct S2(T)
-{
- private T val;
- static S2!T* init(int);
- T value();
-}
-
-extern(C++, struct)
-class C1
-{
- const(char)* data;
-
- static C1 init(const(char)* p);
- const(char)* getDataCPP();
- extern(C++) const(char)* getDataD()
- {
- return data;
- }
-}
-
-extern(C++, struct)
-class C2(T)
-{
- const(T)* data;
-
- static C2!T init(const(T)* p);
- const(T)* getData();
-}
-
-void test39()
-{
- S1* s1 = S1.init(42);
- assert(s1.value == 42);
- assert(S2!int.init(43).value == 43);
- const(char)* ptr = "test".ptr;
- C1 c1 = C1.init(ptr);
- assert(c1.getDataCPP() == ptr);
- assert(c1.getDataD() == ptr);
- C2!char c2 = C2!char.init(ptr);
- assert(c2.getData() == ptr);
- auto result = test39cpp(c2, S2!int.init(43));
- assert(result == 0);
-}
-
-
-void main()
-{
- test1(Foo!int());
- test2(null, Boo!(int*)());
- test3(Test3!(3,3)());
- test4(Foo!(int*)(), Boo!(int*)(), Boo!(int*)(), null, Foo!(double)());
- test5(Foo!(int*)(), Boo!(int*)(), Boo!(int*)());
- Goo goo;
- goo.test6(Goo.Foo!(Goo.Boo!(Goo.Foo!(void)))());
- goo.test7(Goo.Boo!(void).Xoo!(int)());
-
- test8(P1.Mem!int(), P2.Mem!int());
- test9(Foo!(int**)(), Foo!(int*)(), null, null);
-
- auto t10 = Test10Ctor();
- scope(exit) Test10Dtor(t10);
-
- t10.test10();
- t10.test11();
- t10.test12();
- t10.test13();
- t10.test14();
- t10.test15();
- t10.test16();
- t10.test17();
- t10.test18();
- t10.test19();
-
- assert(Test20.test20 == 20);
- assert(Test20.test21 == 21);
- assert(Test20.test22 == 22);
-
- assert(test23(null, null, null, null) == 1);
- assert(test23b(null, null, null) == 1);
-
- extern(C++) static int cb(int a, int b){return a+b;}
-
- test24(&cb);
- int[291][6][5] arr;
- arr[1][1][1] = 42;
- test25(&arr);
- assert(test26(&arr[0]) == 42);
-
- test27(3,4,5);
- test28(3);
-
- test29(3.14f);
- test30(3.14f);
-
- auto t32 = &Module.imports;
- Array!Module arr2;
- arr2.dim = 20;
- assert(Module.dim(&arr2) == 20);
-
- assert(testlongmangle(1, 2, 3, 4) == 10);
- assert(test31 == [[[1, 1], [1, 1]], [[1, 1], [1, 1]]]);
- assert(test32 == null);
-
- auto ee = Expression.create(42);
- extern(C++) static int efun(Expression e, void* p)
- {
- return cast(int)(cast(size_t)p ^ e.getType());
- }
-
- extern(C++) static int efun2(Expression e, void* p)
- {
- return cast(int)(cast(size_t)p * e.getType());
- }
-
- auto test33 = ee.apply(&efun, &efun2, cast(void*)&Expression.create);
- assert(test33 == cast(int)(cast(size_t)cast(void*)&Expression.create ^ 42) * cast(int)(cast(size_t)cast(void*)&Expression.create * 42));
- Expression.dispose(ee);
- assert(ee is null);
- //assert(test34(null) == 0);
- version(CRuntime_Microsoft){}
- else
- {
- assert(test35(3.14L) == 3);
- }
- const char* hello = "hello";
- assert(test36(hello) == hello);
- assert(test37());
- auto t38 = Test38.create();
- assert(t38.test(1, 2, 3) == 1);
- Test38.dispose(t38);
- test39();
-}
+++ /dev/null
-// EXTRA_CPP_SOURCES: externmangle2.cpp
-
-version(Windows)
-{
- void main()
- {
- }
-}
-else
-{
- extern(C++):
-
- struct Test32NS1
- {
- struct Foo(X)
- {
- X *v;
- }
-
-
- struct Bar(X)
- {
- X *v;
- }
-
- };
-
- struct Test32NS2
- {
- struct Foo(X)
- {
- X *v;
- }
- };
-
- struct Test32(alias Y, alias Z)
- {
- Y!(int)* field;
- };
-
-
- void test32a(Test32!(Test32NS1.Foo, Test32NS1.Foo) arg);
- void test32b(Test32!(Test32NS1.Foo, Test32NS1.Bar) arg);
- void test32c(Test32!(Test32NS1.Foo, Test32NS2.Foo) arg);
- void test32d(Test32!(Test32NS1.Foo, Test32NS2.Foo) arg1, Test32!(Test32NS2.Foo, Test32NS1.Foo) arg2);
-
- interface XXX
- {
- }
-
- void test33a(XXX, XXX*);
-
-
- struct Test33(alias A, alias B)
- {
- }
-
- /*
- void test33(XXX, Test33!(test33a, test33a) arg, XXX);
-
-
- struct Test34(alias A)
- {
- };
-
- struct Test34A
- {
- static void foo(int);
- };
-
-
- void test34(Test34!(Test34A.foo) arg);
- */
-
- __gshared extern int test36;
-
- /*
- struct Test37(alias A)
- {
- };
-
- struct Test37A
- {
- __gshared extern int t38;
- };
-
- void test37(Test37!(test36) arg);
- void test38(Test37!(Test37A.t38) arg);
- */
-
- struct Test39
- {
- struct T39A(X)
- {
- }
- }
-
- struct T39A
- {
- }
-
- void test39(Test39.T39A!(.T39A));
-
- version(none)
- {
- version(Posix) //Only for g++ with -std=c++0x and Visual Studio 2013+
- {
-
- struct Test40(T, V...)
- {
-
- }
-
- void test40(Test40!(int, double, void))
- {
- }
- }
- else version(Win64) //Only for g++ with -std=c++0x and Visual Studio 2013+
- {
-
- struct Test40(T, V...)
- {
-
- }
-
- void test40(Test40!(int, double, void))
- {
- }
- }
- }
-
-
- __gshared extern const XXX test41;
- struct Test42
- {
- __gshared extern const XXX test42;
- }
- __gshared extern int[4] test43;
- const(XXX) test44();
-
- void main()
- {
- test32a(Test32!(Test32NS1.Foo, Test32NS1.Foo)());
- test32b(Test32!(Test32NS1.Foo, Test32NS1.Bar)());
- test32c(Test32!(Test32NS1.Foo, Test32NS2.Foo)());
- test32d(Test32!(Test32NS1.Foo, Test32NS2.Foo)(), Test32!(Test32NS2.Foo, Test32NS1.Foo)());
-
- //test33a(null, null);
- //test33(null, Test33!(test33a, test33a)(), null);
-
- //test34(Test34!(Test34A.foo)());
-
- assert(test36 == 36);
-
- //test37(Test37!(test36)());
- //test38(Test37!(Test37A.t38)());
- test39(Test39.T39A!(.T39A)());
-
- assert(test41 is null);
- assert(Test42.test42 is null);
- assert(test43 == [1, 2, 3, 4]);
- auto ptr = &test44;
- }
-}
+++ /dev/null
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdint.h>
-
-#if __cplusplus
-extern "C" {
-#endif
-
-struct Foo1 { char c; };
-
-struct Foo1 ctest1()
-{
- struct Foo1 f;
-
- f.c = 3;
- return f;
-}
-
-struct Foo2 { short s; };
-
-struct Foo2 ctest2()
-{
- struct Foo2 f;
-
- f.s = 0x1234;
- return f;
-}
-
-struct Foo3 { char c; short s; };
-
-struct Foo3 ctest3()
-{
- struct Foo3 f;
-
- f.s = 0x5678;
- return f;
-}
-
-
-struct Foo4 { int i; };
-
-struct Foo4 ctest4()
-{
- struct Foo4 f;
-
- f.i = 0x12345678;
- return f;
-}
-
-struct Foo5 { int i, j; };
-
-struct Foo5 ctest5()
-{
- struct Foo5 f;
-
- f.i = 0x12345678;
- f.j = 0x21436587;
- return f;
-}
-
-
-struct Foo6 { int i, j, k; };
-
-struct Foo6 ctest6()
-{
- struct Foo6 f;
-
- f.i = 0x12345678;
- f.j = 0x21463587;
- f.k = 0x24163857;
- return f;
-}
-
-struct S7 { float a,b; };
-
-struct S7 ctest10()
-{
- struct S7 f;
-
- f.a = 2.5;
- f.b = 1.5;
- return f;
-}
-
-// =================================
-
-char ctest7(char c)
-{
- return c + 1;
-}
-
-unsigned char ctest8(unsigned char c)
-{
- return c + 1;
-}
-
-signed char ctest9(signed char c)
-{
- return c + 1;
-}
-
-/***********************************************/
-
-void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c)
-{
- assert(a == 100.0);
- assert(b == 67);
- assert(c == 200.0);
-}
-
-/***********************************************/
-
-extern void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c);
-
-void test4()
-{
- dtestrir(1,2,3,4,5,6, 300.0, 68, 401.0);
-}
-
-/**********************************************/
-
-typedef struct S11 {
- char a;
- char b;
- char c;
-} S11;
-
-S11 ctest11(char x, S11 s, char y) {
- printf("C sz = %d\n", (int)sizeof(S11));
- assert(sizeof(S11) == 3);
- printf("x = %d\n", (int)x);
- printf("s.a = %d\n", (int)s.a);
- printf("s.b = %d\n", (int)s.b);
- printf("s.c = %d\n", (int)s.c);
- printf("y = %d\n", (int)y);
- return s;
-}
-
-/**********************************************/
-
-typedef struct S12 {
- char a,d;
- char b,e;
- char c;
-} S12;
-
-S12 ctest12(char x, S12 s, char y) {
- printf("C sz = %d\n", (int)sizeof(S12));
- assert(sizeof(S12) == 5);
- printf("x = %d\n", (int)x);
- printf("s.a = %d\n", (int)s.a);
- printf("s.b = %d\n", (int)s.b);
- printf("s.c = %d\n", (int)s.c);
- printf("y = %d\n", (int)y);
- return s;
-}
-
-
-/**********************************************/
-
-typedef struct S13 {
- short a;
- short b;
- short c;
-} S13;
-
-S13 ctest13(char x, S13 s, char y) {
- printf("C sz = %d\n", (int)sizeof(S13));
- assert(sizeof(S13) == 6);
- printf("x = %d\n", (int)x);
- printf("s.a = %d\n", (int)s.a);
- printf("s.b = %d\n", (int)s.b);
- printf("s.c = %d\n", (int)s.c);
- printf("y = %d\n", (int)y);
- return s;
-}
-
-
-/**********************************************/
-
-typedef struct S14 {
- char a,d,e,f;
- char b,g;
- char c;
-} S14;
-
-S14 ctest14(char x, S14 s, char y) {
- printf("C sz = %d\n", (int)sizeof(S14));
- assert(sizeof(S14) == 7);
- printf("x = %d\n", (int)x);
- printf("s.a = %d\n", (int)s.a);
- printf("s.b = %d\n", (int)s.b);
- printf("s.c = %d\n", (int)s.c);
- printf("y = %d\n", (int)y);
- return s;
-}
-
-
-/**********************************************/
-
-typedef struct S15 {
- char a,d,e,f;
- char b,g,h,i;
- char c;
-} S15;
-
-S15 ctest15(char x, S15 s, char y) {
- printf("C sz = %d\n", (int)sizeof(S15));
- assert(sizeof(S15) == 9);
- printf("x = %d\n", (int)x);
- printf("s.a = %d\n", (int)s.a);
- printf("s.b = %d\n", (int)s.b);
- printf("s.c = %d\n", (int)s.c);
- printf("y = %d\n", (int)y);
- return s;
-}
-
-
-/**********************************************/
-
-typedef struct S16 {
- char a[5];
-#ifdef __GNUC__
- struct __attribute__((packed))
-#else
- #pragma pack(push, 1)
- struct
-#endif
- {
- char b;
- int c;
- };
-#ifndef __GNUC__
- #pragma pack(pop)
-#endif
-} S16;
-
-S16 ctest16(char x, S16 s, char y) {
- printf("C sz = %d\n", (int)sizeof(S16));
- assert(sizeof(S16) == 10);
- printf("x = %d\n", (int)x);
- printf("s.a = %.*s\n", 5, s.a);
- printf("s.b = %d\n", (int)s.b);
- printf("s.c = %d\n", s.c);
- printf("y = %d\n", (int)y);
- return s;
-}
-
-
-
-#if __cplusplus
-}
-#endif
-
+++ /dev/null
-struct S{
- float a;
-};
-
-bool passthrough(bool value) { return value; }
-signed char passthrough(signed char value) { return value; }
-unsigned char passthrough(unsigned char value) { return value; }
-char passthrough(char value) { return value; }
-wchar_t passthrough(wchar_t value) { return value; }
-short passthrough(short value) { return value; }
-unsigned short passthrough(unsigned short value) { return value; }
-int passthrough(int value) { return value; }
-unsigned int passthrough(unsigned int value) { return value; }
-long passthrough(long value) { return value; }
-unsigned long passthrough(unsigned long value) { return value; }
-long long passthrough(long long value) { return value; }
-unsigned long long passthrough(unsigned long long value) { return value; }
-float passthrough(float value) { return value; }
-double passthrough(double value) { return value; }
-S passthrough(S value) { return value; }
-
-bool passthrough_ptr(bool *value) { return *value; }
-signed char passthrough_ptr(signed char *value) { return *value; }
-unsigned char passthrough_ptr(unsigned char *value) { return *value; }
-char passthrough_ptr(char *value) { return *value; }
-wchar_t passthrough_ptr(wchar_t *value) { return *value; }
-short passthrough_ptr(short *value) { return *value; }
-unsigned short passthrough_ptr(unsigned short *value) { return *value; }
-int passthrough_ptr(int *value) { return *value; }
-unsigned int passthrough_ptr(unsigned int *value) { return *value; }
-long passthrough_ptr(long *value) { return *value; }
-unsigned long passthrough_ptr(unsigned long *value) { return *value; }
-long long passthrough_ptr(long long *value) { return *value; }
-unsigned long long passthrough_ptr(unsigned long long *value) { return *value; }
-float passthrough_ptr(float *value) { return *value; }
-double passthrough_ptr(double *value) { return *value; }
-S passthrough_ptr(S *value) { return *value; }
-
-bool passthrough_ref(bool &value) { return value; }
-signed char passthrough_ref(signed char &value) { return value; }
-unsigned char passthrough_ref(unsigned char &value) { return value; }
-char passthrough_ref(char &value) { return value; }
-wchar_t passthrough_ref(wchar_t &value) { return value; }
-short passthrough_ref(short &value) { return value; }
-unsigned short passthrough_ref(unsigned short &value) { return value; }
-int passthrough_ref(int &value) { return value; }
-unsigned int passthrough_ref(unsigned int &value) { return value; }
-long passthrough_ref(long &value) { return value; }
-unsigned long passthrough_ref(unsigned long &value) { return value; }
-long long passthrough_ref(long long &value) { return value; }
-unsigned long long passthrough_ref(unsigned long long &value) { return value; }
-float passthrough_ref(float &value) { return value; }
-double passthrough_ref(double &value) { return value; }
-S passthrough_ref(S &value) { return value; }
-
-// Uncomment when mangling is fixed
-// typedef void(*fn0)();
-// fn0 passthrough_fn0 (fn0 value) { return value; }
-// typedef int (*fn1)(int);
-// fn1 passthrough_fn1 (fn1 value) { return value; }
+++ /dev/null
-/*
-GCC 5.1 introduced new implementations of std::string and std::list:
-
-https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
-
-This causes e.g. std::string to be actually defined as
-std::__cxx11::string.
-
-On machines with GCC 5.1, this manifests as a linker error when
-running the cppa.d / cppb.cpp test:
-
-cppa.o: In function `_D4cppa6test14FZv':
-cppa.d:(.text._D4cppa6test14FZv+0x11): undefined reference to `foo14a(std::string*)'
-cppa.d:(.text._D4cppa6test14FZv+0x18): undefined reference to `foo14b(std::basic_string<int, std::char_traits<int>, std::allocator<int> >*)'
-cppa.d:(.text._D4cppa6test14FZv+0x3a): undefined reference to `foo14f(std::char_traits<char>*, std::string*, std::string*)'
-cppa.o: In function `_D4cppa7testeh3FZv':
-cppa.d:(.text._D4cppa7testeh3FZv+0x19): undefined reference to `throwle()'
-collect2: error: ld returned 1 exit status
---- errorlevel 1
-
-When the .cpp file is compiled with g++ 5.3.0, the actual function
-signatures in the cppb.o object file are:
-
-foo14a(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
-foo14b(std::__cxx11::basic_string<int, std::char_traits<int>, std::allocator<int> >*)
-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> >*)
-
-Fortunately, it is easily possible to disable the new feature
-by defining _GLIBCXX_USE_CXX11_ABI as 0 before including any standard
-headers.
-*/
-#define _GLIBCXX_USE_CXX11_ABI 0
-
-#include <stdio.h>
-#include <assert.h>
-#include <exception>
-#include <cstdarg>
-
-/**************************************/
-
-int foo(int i, int j, int k);
-
-int foob(int i, int j, int k)
-{
- printf("i = %d\n", i);
- printf("j = %d\n", j);
- printf("k = %d\n", k);
- assert(i == 1);
- assert(j == 2);
- assert(k == 3);
-
- foo(i, j, k);
-
- return 7;
-}
-
-/**************************************/
-
-class D *dthis;
-
-class D
-{
- public:
- virtual int bar(int i, int j, int k)
- {
- printf("this = %p\n", this);
- assert(this == dthis);
- printf("D.bar: i = %d\n", i);
- printf("D.bar: j = %d\n", j);
- printf("D.bar: k = %d\n", k);
- assert(i == 9);
- assert(j == 10);
- assert(k == 11);
- return 8;
- }
-};
-
-
-D* getD()
-{
- D *d = new D();
- dthis = d;
- return d;
-}
-
-/**************************************/
-
-class E
-{
- public:
- virtual int bar(int i, int j, int k);
-};
-
-
-int callE(E *e)
-{
- return e->bar(11,12,13);
-}
-
-/**************************************/
-
-void foo4(char *p)
-{
-}
-
-/**************************************/
-
-struct foo5 { int i; int j; void *p; };
-
-class bar5
-{
-public:
- virtual foo5 getFoo(int i){
- printf("This = %p\n", this);
- foo5 f;
- f.i = 1;
- f.j = 2 + i;
- f.p = (void*)this;
- return f;
- }
-};
-
-bar5* newBar()
-{
- bar5* b = new bar5();
- printf("bar = %p\n", b);
- return b;
-}
-
-
-/**************************************/
-
-struct A11802;
-struct B11802;
-
-class C11802
-{
-public:
- virtual void fun(A11802 *);
- virtual void fun(B11802 *);
-};
-
-class D11802 : public C11802
-{
-public:
- void fun(A11802 *);
- void fun(B11802 *);
-};
-
-void test11802x(D11802 *c)
-{
- c->fun((A11802 *)0);
- c->fun((B11802 *)0);
-}
-
-/**************************************/
-
-typedef struct
-{
- int i;
- double d;
-} S6;
-
-union S6_2
-{
- int i;
- double d;
-};
-
-enum S6_3
-{
- A, B
-};
-
-
-S6 foo6(void)
-{
- S6 s;
- s.i = 42;
- s.d = 2.5;
- return s;
-}
-
-S6_2 foo6_2(void)
-{
- S6_2 s;
- s.i = 42;
- return s;
-}
-
-S6_3 foo6_3(void)
-{
- S6_3 s = A;
- return s;
-}
-
-extern "C" { int foosize6()
-{
- return sizeof(S6);
-}
-}
-
-/**************************************/
-
-typedef struct
-{
- int i;
- long long d;
-} S7;
-
-extern "C" { int foo7()
-{
- return sizeof(S7);
-}
-}
-
-/**************************************/
-
-struct S13955a
-{
- float a;
- double b;
-};
-
-struct S13955b
-{
- double a;
- float b;
-};
-
-struct S13955c
-{
- float a;
- float b;
-};
-
-struct S13955d
-{
- double a;
- double b;
-};
-
-void check13955(S13955a a, S13955b b, S13955c c, S13955d d);
-
-void func13955(S13955a a, S13955b b, S13955c c, S13955d d)
-{
- check13955(a, b, c, d);
-}
-
-/**************************************/
-
-struct Struct10071
-{
- void *p;
- long double r;
-};
-
-size_t offset10071()
-{
- Struct10071 s;
- return (char *)&s.r - (char *)&s;
-}
-
-/**************************************/
-
-void foo8(const char *p)
-{
-}
-
-/**************************************/
-// 4059
-
-struct elem9 { };
-void foobar9(elem9*, elem9*) { }
-
-/**************************************/
-// 5148
-
-void foo10(const char*, const char*) { }
-void foo10(const int, const int) { }
-void foo10(const char, const char) { }
-void foo10(bool, bool) { }
-
-struct MyStructType { };
-void foo10(const MyStructType s, const MyStructType t) { }
-
-enum MyEnumType { onemember };
-void foo10(const MyEnumType s, const MyEnumType t) { }
-
-/**************************************/
-
-namespace N11 { namespace M { void bar11() { } } }
-
-namespace A11 { namespace B { namespace C { void bar() { } } } }
-
-/**************************************/
-
-void myvprintfx(const char* format, va_list);
-
-void myvprintf(const char* format, va_list va)
-{
- myvprintfx(format, va);
-}
-
-/**************************************/
-
-class C13161
-{
-public:
- virtual void dummyfunc() {}
- long long val_5;
- unsigned val_9;
-};
-
-class Test : public C13161
-{
-public:
- unsigned val_0;
- long long val_1;
-};
-
-size_t getoffset13161()
-{
- Test s;
- return (char *)&s.val_0 - (char *)&s;
-}
-
-class C13161a
-{
-public:
- virtual void dummyfunc() {}
- long double val_5;
- unsigned val_9;
-};
-
-class Testa : public C13161a
-{
-public:
- bool val_0;
-};
-
-size_t getoffset13161a()
-{
- Testa s;
- return (char *)&s.val_0 - (char *)&s;
-}
-
-/****************************************************/
-
-#if __linux__ || __APPLE__ || __FreeBSD__
-#include <memory>
-#include <vector>
-#include <string>
-
-#if __linux__
-template struct std::allocator<int>;
-template struct std::vector<int>;
-
-void foo15()
-{
- std::allocator<int>* p;
- p->deallocate(0, 0);
-}
-
-#endif
-
-// _Z5foo14PSt6vectorIiSaIiEE
-void foo14(std::vector<int, std::allocator<int> > *p) { }
-
-void foo14a(std::basic_string<char> *p) { }
-void foo14b(std::basic_string<int> *p) { }
-void foo14c(std::basic_istream<char> *p) { }
-void foo14d(std::basic_ostream<char> *p) { }
-void foo14e(std::basic_iostream<char> *p) { }
-
-void foo14f(std::char_traits<char>* x, std::basic_string<char> *p, std::basic_string<char> *q) { }
-
-#endif
-
-/**************************************/
-
-struct S13956
-{
-};
-
-void check13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
-
-void func13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
-{
- check13956(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
-}
-
-/**************************************/
-
-wchar_t f13289_cpp_wchar_t(wchar_t ch)
-{
- if (ch <= L'z' && ch >= L'a')
- {
- return ch - (L'a' - L'A');
- }
- else
- {
- return ch;
- }
-}
-
-#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun || __NetBSD__
-unsigned short f13289_d_wchar(unsigned short ch);
-wchar_t f13289_d_dchar(wchar_t ch);
-#elif _WIN32
-wchar_t f13289_d_wchar(wchar_t ch);
-unsigned int f13289_d_dchar(unsigned int ch);
-#endif
-
-bool f13289_cpp_test()
-{
-#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun || __NetBSD__
- if (!(f13289_d_wchar((unsigned short)'c') == (unsigned short)'C')) return false;
- if (!(f13289_d_wchar((unsigned short)'D') == (unsigned short)'D')) return false;
- if (!(f13289_d_dchar(L'e') == L'E')) return false;
- if (!(f13289_d_dchar(L'F') == L'F')) return false;
- return true;
-#elif _WIN32
- if (!(f13289_d_wchar(L'c') == L'C')) return false;
- if (!(f13289_d_wchar(L'D') == L'D')) return false;
- if (!(f13289_d_dchar((unsigned int)'e') == (unsigned int)'E')) return false;
- if (!(f13289_d_dchar((unsigned int)'F') == (unsigned int)'F')) return false;
- return true;
-#else
- return false;
-#endif
-}
-
-/******************************************/
-
-long double testld(long double ld)
-{
- assert(ld == 5);
- return ld + 1;
-}
-
-long double testldld(long double ld1, long double ld2)
-{
- assert(ld1 == 5);
- return ld2 + 1;
-}
-
-long testl(long lng)
-{
- assert(lng == 5);
- return lng + sizeof(long);
-}
-
-unsigned long testul(unsigned long ul)
-{
- assert(ul == 5);
- return ul + sizeof(unsigned long);
-}
-
-/******************************************/
-
-struct S13707
-{
- void* a;
- void* b;
- S13707(void *a, void* b)
- {
- this->a = a;
- this->b = b;
- }
-};
-
-S13707 func13707()
-{
- S13707 pt(NULL, NULL);
- return pt;
-}
-
-/******************************************/
-
-template <int x> struct S13932
-{
- int member;
-};
-
-void func13932(S13932<-1> s) {}
-
-/******************************************/
-
-namespace N13337 {
- namespace M13337 {
- struct S13337 { };
- void foo13337(S13337 s) { }
- }
-}
-
-/****************************************/
-// 14195
-
-template <typename T>
-struct Delegate1 {};
-
-template <typename R1>
-struct Delegate1 < R1() > {};
-
-template <typename T1, typename T2>
-struct Delegate2 {};
-
-template < typename R1, typename T1, typename T2, typename R2, typename T3, typename T4 >
-struct Delegate2<R1(T1, T2), R2(T3, T4)> {};
-
-void test14195a(Delegate1<void()> func) {}
-
-void test14195b(Delegate2<int(float, double), int(float, double)> func) {}
-
-/******************************************/
-// 14200
-
-void test14200a(int a) {};
-void test14200b(float a, int b, double c) {};
-
-/******************************************/
-// 14956
-
-namespace std {
- namespace N14956 {
- struct S14956 { };
- }
-}
-
-void test14956(std::N14956::S14956 s) { }
-
-/******************************************/
-// check order of overloads in vtable
-
-class Statement;
-class ErrorStatement;
-class PeelStatement;
-class ExpStatement;
-class DtorExpStatement;
-
-class Visitor
-{
-public:
- virtual int visit(Statement*) { return 1; }
- virtual int visit(ErrorStatement*) { return 2; }
- virtual int visit(PeelStatement*) { return 3; }
-};
-
-class Visitor2 : public Visitor
-{
-public:
- virtual int visit2(ExpStatement*) { return 4; }
- virtual int visit2(DtorExpStatement*) { return 5; }
-};
-
-bool testVtableCpp(Visitor2* sv)
-{
- if (sv->visit((Statement*)0) != 1) return false;
- if (sv->visit((ErrorStatement*)0) != 2) return false;
- if (sv->visit((PeelStatement*)0) != 3) return false;
- if (sv->visit2((ExpStatement*)0) != 4) return false;
- if (sv->visit2((DtorExpStatement*)0) != 5) return false;
- return true;
-}
-
-Visitor2 inst;
-
-Visitor2* getVisitor2()
-{
- return &inst;
-}
-
-/******************************************/
-// issues detected by fuzzer
-#if _LP64
-#define longlong long
-#else
-#define longlong long long
-#endif
-
-void fuzz1_checkValues(longlong arg10, longlong arg11, bool arg12);
-void fuzz1_cppvararg(longlong arg10, longlong arg11, bool arg12)
-{
- fuzz1_checkValues(arg10, arg11, arg12);
-}
-
-void fuzz2_checkValues(unsigned longlong arg10, unsigned longlong arg11, bool arg12);
-void fuzz2_cppvararg(unsigned longlong arg10, unsigned longlong arg11, bool arg12)
-{
- fuzz2_checkValues(arg10, arg11, arg12);
-}
-
-#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun || __NetBSD__
-#define wchar unsigned short
-#elif _WIN32
-#define wchar wchar_t
-#endif
-
-void fuzz3_checkValues(wchar arg10, wchar arg11, bool arg12);
-void fuzz3_cppvararg(wchar arg10, wchar arg11, bool arg12)
-{
- fuzz3_checkValues(arg10, arg11, arg12);
-}
-
-/******************************************/
-
-void throwit()
-{
-#if _WIN32
-#else
- std::exception se;
- throw se;
-#endif
-}
-
-/******************************************/
-
-#if linux
-#include <stdexcept>
-
-void throwle()
-{
- std::logic_error le("test");
- throw le;
-}
-
-#endif
-
-/******************************************/
-// 15579
-
-/******************************************/
-// 15579
-
-class Base
-{
-public:
- //virtual ~Base() {}
- virtual void base();
- unsigned char x;
-};
-
-class Interface
-{
-public:
- virtual int MethodCPP() = 0;
- virtual int MethodD() = 0;
-};
-
-class Derived : public Base, public Interface
-{
-public:
- Derived();
- short y;
- int MethodCPP();
-#if _WIN32 || _WIN64
- int MethodD();
- virtual int Method();
-#else
- int MethodD() { return 3; } // need def or vtbl[] is not generated
- virtual int Method() { return 6; } // need def or vtbl[] is not generated
-#endif
-};
-
-void Base::base() { }
-int Derived::MethodCPP() {
- printf("Derived::MethodCPP() this = %p, x = %d, y = %d\n", this, x, y);
- assert(x == 4 || x == 7);
- assert(y == 5 || y == 8);
- return 30;
-}
-Derived::Derived() { }
-
-
-Derived *cppfoo(Derived *d)
-{
- printf("cppfoo(): d = %p\n", d);
- assert(d->x == 4);
- assert(d->y == 5);
- assert(d->MethodD() == 3);
- assert(d->MethodCPP() == 30);
- assert(d->Method() == 6);
-
- d = new Derived();
- d->x = 7;
- d->y = 8;
- assert(d->MethodD() == 3);
- assert(d->MethodCPP() == 30);
- assert(d->Method() == 6);
- printf("d1 = %p\n", d);
- return d;
-}
-
-Interface *cppfooi(Interface *i)
-{
- printf("cppfooi(): i = %p\n", i);
- assert(i->MethodD() == 3);
- assert(i->MethodCPP() == 30);
-
- Derived *d = new Derived();
- d->x = 7;
- d->y = 8;
- printf("d = %p, i = %p\n", d, (Interface *)d);
- return d;
-}
-
-/******************************************/
-// 15610
-
-class Base2
-{
- public:
- int i;
- virtual void baser() { }
-};
-
-class Interface2
-{
- public:
- virtual void f() = 0;
-};
-
-class Derived2 : public Base2, public Interface2
-{
- public:
- void f();
-};
-
-void Derived2::f()
-{
- printf("Derived2::f() this = %p i = %d\n", this, i);
- assert(i == 3);
-}
-
-/******************************************/
-// 15455
-
-struct X6
-{
- unsigned short a;
- unsigned short b;
- unsigned char c;
- unsigned char d;
-};
-
-struct X8
-{
- unsigned short a;
- X6 b;
-};
-
-void test15455b(X8 s)
-{
- assert(sizeof(X6) == 6);
- assert(sizeof(X8) == 8);
- assert(s.a == 1);
- assert(s.b.a == 2);
- assert(s.b.b == 3);
- assert(s.b.c == 4);
- assert(s.b.d == 5);
-}
-
-/******************************************/
-// 15372
-
-template <typename T>
-int foo15372(int value)
-{
- return value;
-}
-
-void test15372b()
-{
- int t = foo15372<int>(1);
-}
-
-/****************************************/
-// 15576
-
-namespace ns15576
-{
- int global15576;
-
- namespace ns
- {
- int n_global15576;
- }
-}
-
-/****************************************/
-// 15802
-
-template <typename T>
-class Foo15802
-{
-public:
- static int boo(int value)
- {
- return value;
- }
-};
-
-void test15802b()
-{
- int t = Foo15802<int>::boo(1);
-}
-
-
-/****************************************/
-// 16536 - mangling mismatch on OSX
-
-#if defined(__APPLE__)
-__UINTMAX_TYPE__ pass16536(__UINTMAX_TYPE__ a)
-{
- return a;
-}
-#endif
+++ /dev/null
-#include <stdint.h>
-
-template<class X>
-struct Foo
-{
- X *v;
-};
-
-template<class X>
-struct Boo
-{
- X *v;
-};
-
-void test1(Foo<int> arg1)
-{
-}
-
-
-void test2(int* arg2, Boo<int*> arg1)
-{
-}
-
-template<int X, int Y>
-struct Test3
-{
-
-};
-
-void test3(Test3<3,3> arg1)
-{
-}
-
-void test4(Foo<int*> arg1, Boo<int*> arg2, Boo<int*> arg3, int*, Foo<double>)
-{
-}
-
-void test5(Foo<int*> arg1, Boo<int*> arg2, Boo<int*> arg3)
-{
-}
-
-struct Goo
-{
-
- template<class X>
- struct Foo
- {
- X* v;
- };
-
- template<class X>
- struct Boo
- {
- template<class Y>
- struct Xoo
- {
- Y* v;
- };
- X* v;
- };
-
-
- void test6(Foo<Boo<Foo<void> > > arg1);
- void test7(Boo<void>::Xoo<int> arg1);
-};
-
-void Goo::test6(Goo::Foo<Goo::Boo<Goo::Foo<void> > > arg1)
-{
-}
-
-void Goo::test7(Goo::Boo<void>::Xoo<int> arg1)
-{
-}
-
-struct P1
-{
- template<class T>
- struct Mem
- {
- };
-};
-
-struct P2
-{
- template<class T>
- struct Mem
- {
- };
-};
-
-void test8(P1::Mem<int>, P2::Mem<int>){}
-void test9(Foo<int**>, Foo<int*>, int**, int*){}
-
-
-
-class Test10
-{
- private: void test10();
- public: void test11();
- protected: void test12();
- public: void test13() const;
-
- private: void test14(); // Private methods in D are always non-virtual
- public: virtual void test15();
- protected: virtual void test16();
-
- private: static void test17();
- public: static void test18();
- protected: static void test19();
-};
-
-Test10* Test10Ctor()
-{
- return new Test10();
-}
-
-void Test10Dtor(Test10*& ptr)
-{
- delete ptr;
- ptr = 0;
-}
-
-void Test10::test10(){}
-void Test10::test11(){}
-void Test10::test12(){}
-void Test10::test13() const{}
-void Test10::test14(){}
-void Test10::test15(){}
-void Test10::test16(){}
-void Test10::test17(){}
-void Test10::test18(){}
-void Test10::test19(){}
-
-struct Test20
-{
- private: static int test20;
- protected: static int test21;
- public: static int test22;
-};
-
-int Test20::test20 = 20;
-int Test20::test21 = 21;
-int Test20::test22 = 22;
-
-int test23(Test10**, Test10*, Test10***, Test10 const *const)
-{
- return 1;
-}
-
-int test23b(Test10 const *const *const, Test10 const* const, Test10*)
-{
- return 1;
-}
-
-void test24(int(*)(int,int))
-{
-}
-
-void test25(int arr[2][5][6][291])
-{
-}
-
-int test26(int arr[5][6][291])
-{
- return arr[1][1][1];
-}
-
-void test27(int, ...){}
-void test28(int){}
-
-void test29(float){}
-void test30(const float){}
-
-template<class T>
-struct Array
-{
- int dim;
-};
-
-class Module
-{
-public:
- static void imports(Module*);
- static int dim(Array<Module*>*);
-};
-
-
-void Module::imports(Module*)
-{
-}
-
-int Module::dim(Array<Module*>* arr)
-{
- return arr->dim;
-}
-
-#if _LP64
-unsigned long testlongmangle(int32_t a, uint32_t b, long c, unsigned long d)
-{
- return a + b + c + d;
-}
-#else
-unsigned long long testlongmangle(int a, unsigned int b, long long c, unsigned long long d)
-{
- return a + b + c + d;
-}
-#endif
-
-int test31[2][2][2] = {1, 1, 1, 1, 1, 1, 1, 1};
-int *test32 = 0;
-
-
-
-class Expression;
-
-typedef int (*apply_fp_t)(Expression*, void*);
-
-class Expression
-{
- int type;
-public:
- int apply(apply_fp_t fp, apply_fp_t fp2, void *param);
- int getType();
- static Expression* create(int v);
- static void dispose(Expression*&);
-};
-
-int Expression::apply(apply_fp_t fp, apply_fp_t fp2, void *param)
-{
- return fp(this, param) * fp2(this, param);
-}
-
-int Expression::getType()
-{
- return type;
-}
-
-Expression* Expression::create(int v)
-{
- Expression *e = new Expression();
- e->type = v;
- return e;
-}
-
-void Expression::dispose(Expression *&e)
-{
- if (e)
- delete e;
- e = 0;
-}
-
-/*int test34(int v[0][0][0])
-{
- return 0;
-}*/
-
-#ifndef _MSC_VER
- int test35(long double arg)
- {
- return (int)arg;
- }
-#endif
-
-const char *test36(const char *arg)
-{
- return arg;
-}
-
-class Test37
-{
-public:
- static Test37 *create();
- bool test();
-};
-
-bool test37()
-{
- Test37 *o = Test37::create();
- return o->test();
-}
-
-class Test38
-{
-public:
- int test(int, ...);
- static Test38* create();
- static void dispose(Test38*&);
-};
-
-int Test38::test(int a, ...)
-{
- return a;
-}
-
-Test38* Test38::create()
-{
- Test38 *t = new Test38();
- return t;
-}
-
-void Test38::dispose(Test38 *&t)
-{
- if (t)
- delete t;
- t = 0;
-}
-
-class S1
-{
- int val;
-public:
- static S1* init(int);
- S1(int v) : val(v) {}
- int value();
-};
-
-S1* S1::init(int x)
-{
- return new S1(x);
-}
-
-int S1::value()
-{
- return val;
-}
-
-template<class T>
-class S2
-{
- T val;
-public:
- static S2<T>* init(T);
- S2(T v) : val(v) {}
- T value();
-};
-
-template<>
-S2<int>* S2<int>::init(int x)
-{
- return new S2<int>(x);
-}
-
-template<>
-int S2<int>::value()
-{
- return val;
-}
-
-struct C1
-{
- const char *data;
-
- static C1* init(const char *p);
-
- C1(const char* p) : data(p) { }
-
- virtual const char* getDataCPP();
- virtual const char* getDataD();
-};
-
-C1* C1::init(const char *p)
-{
- return new C1(p);
-}
-
-const char* C1::getDataCPP()
-{
- return data;
-}
-
-template<class T>
-struct C2
-{
- const T *data;
-
- static C2* init(const T *p);
-
- C2(const T* p) : data(p) { }
-
- virtual const T* getData();
-};
-
-template<>
-C2<char>* C2<char>::init(const char *p)
-{
- return new C2<char>(p);
-}
-
-template<>
-const char* C2<char>::getData()
-{
- return data;
-}
-
-int test39cpp(C2<char>* c2, S2<int>* s2)
-{
- C2<char>* otherC2 = C2<char>::init(c2->getData());
- if (c2->getData() != otherC2->getData())
- return 1;
- S2<int>* otherS2 = S2<int>::init(s2->value());
- if (s2->value() != otherS2->value())
- return 2;
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-
-struct Test32NS1
-{
- template<class X>
- struct Foo
- {
- X *v;
- };
-
- template<class X>
- struct Bar
- {
- X *v;
- };
-
-};
-
-struct Test32NS2
-{
- template<class X>
- struct Foo
- {
- X *v;
- };
-};
-
-template <template <class X> class Y, template <class X> class Z>
-struct Test32
-{
- Y<int>* field;
-};
-
-
-void test32a(Test32<Test32NS1::Foo, Test32NS1::Foo> arg)
-{
-}
-
-void test32b(Test32<Test32NS1::Foo, Test32NS1::Bar> arg)
-{
-}
-
-void test32c(Test32<Test32NS1::Foo, Test32NS2::Foo> arg)
-{
-}
-
-void test32d(Test32<Test32NS1::Foo, Test32NS2::Foo> arg1, Test32<Test32NS2::Foo, Test32NS1::Foo> arg2)
-{
-}
-
-
-class XXX
-{
-};
-template <void (&Goo)(XXX*, XXX**), void (&Xoo)(XXX*, XXX**)>
-struct Test33
-{
-};
-
-void test33a(XXX*, XXX**){}
-
-void test33(XXX*, Test33<test33a, test33a> arg, XXX*)
-{
-}
-
-template <void (&Goo)(int)>
-struct Test34
-{
-};
-
-struct Test34A
-{
- static void foo(int);
-};
-
-void Test34A::foo(int) {}
-void test34(Test34<Test34A::foo> arg)
-{
-}
-
-int test36= 36;
-
-template <int& XREF>
-struct Test37
-{
-};
-
-struct Test37A
-{
- static int t38;
-};
-
-int Test37A::t38 = 42;
-
-void test37(Test37<test36> arg)
-{
-}
-
-void test38(Test37<Test37A::t38> arg)
-{
-}
-
-struct Test39
-{
- template <class X>
- struct T39A
- {
- };
-};
-
-struct T39A
-{
-};
-
-void test39(Test39::T39A< ::T39A >)
-{
-}
-
-#if 0 //only for g++ with -std=c++0x and Visual C++ >= 2013
- #if defined(__GNUG__) || (defined(_MSC_VER) && _MSC_VER >= 1200)
- template<class... VarArg> struct Test40
- {
- };
-
- void test40(Test40<int, double, void> arg)
- {
- }
- #endif
-
-
-#endif
-
-
-extern XXX const * const test41 = 0;
-
-namespace Test42
-{
- extern XXX const * const test42 = 0;
-}
-
-int test43[4] = {1, 2, 3, 4};
-
-XXX const* const test44()
-{
- return new XXX;
-}
--- /dev/null
+
+// EXTRA_CPP_SOURCES: cabi2.cpp
+
+import core.stdc.stdio;
+import core.stdc.config;
+
+struct Foo1 { char c; }
+struct Foo2 { short s; }
+struct Foo3 { char c; short s; }
+struct Foo4 { int i; }
+struct Foo5 { int i, j; }
+struct Foo6 { int i, j, k; }
+struct S7 { float a, b; }
+
+extern (C) Foo1 ctest1();
+extern (C) Foo2 ctest2();
+extern (C) Foo3 ctest3();
+extern (C) Foo4 ctest4();
+extern (C) Foo5 ctest5();
+extern (C) Foo6 ctest6();
+extern (C) S7 ctest10();
+
+version(Windows)
+ version = Windows_or_32bit;
+else version(X86)
+ version = Windows_or_32bit;
+
+
+void test1()
+{
+ Foo1 f1 = ctest1();
+ assert(f1.c == 3);
+
+ Foo2 f2 = ctest2();
+ assert(f2.s == 0x1234);
+
+ Foo3 f3 = ctest3();
+ assert(f3.s == 0x5678);
+
+ Foo4 f4 = ctest4();
+ assert(f4.i == 0x12345678);
+
+ Foo5 f5 = ctest5();
+ assert(f5.i == 0x12345678);
+ assert(f5.j == 0x21436587);
+
+version(Windows_or_32bit)
+{
+ Foo6 f6 = ctest6();
+ assert(f6.i == 0x12345678);
+ assert(f6.j == 0x21463587);
+ assert(f6.k == 0x24163857);
+}
+
+ S7 s7 = ctest10();
+ assert(s7.a == 2.5);
+ assert(s7.b == 1.5);
+}
+
+/*******************************************/
+
+extern (C)
+{
+ char ctest7(char);
+ ubyte ctest8(ubyte);
+ byte ctest9(byte);
+}
+
+void test2()
+{
+ assert(ctest7('a') == 'b');
+ assert(ctest8(7) == 8);
+ assert(ctest9(3) == 4);
+}
+
+/******************************************/
+
+extern (C)
+{
+ void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, c_long_double a, int b, c_long_double c);
+}
+
+void test3()
+{
+ ctestrir(1,2,3,4,5,6, c_long_double(100.0), 67, c_long_double(200.0));
+}
+
+/******************************************/
+
+extern (C) void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, c_long_double a, int b, c_long_double c)
+{
+ assert(a == 300.0);
+ assert(b == 68);
+ assert(c == 401.0);
+}
+
+extern (C) void test4();
+
+/******************************************/
+
+struct S11 { ubyte a, b, c; }
+
+extern (C) S11 ctest11(ubyte x, S11, ubyte y);
+
+void test11()
+{
+ version (X86)
+ {
+ S11 t;
+ assert(S11.sizeof == 3);
+ t.a = 2;
+ t.b = 3;
+ t.c = 4;
+ auto s = ctest11(1, t, 5);
+ assert(s.a == 2);
+ assert(s.b == 3);
+ assert(s.c == 4);
+ }
+}
+
+/******************************************/
+
+struct S12 { char a,d; char b,e; ubyte c; }
+
+extern (C) S12 ctest12(ubyte x, S12, ubyte y);
+
+void test12()
+{
+ version (X86)
+ {
+ S12 t;
+ printf("D sz = %d\n", cast(int)S12.sizeof);
+// assert(S12.sizeof == 5);
+ t.a = 2;
+ t.b = 3;
+ t.c = 4;
+ auto s = ctest12(1, t, 5);
+ assert(s.a == 2);
+ assert(s.b == 3);
+ assert(s.c == 4);
+ }
+}
+
+/******************************************/
+
+struct S13 { ushort a, b, c; }
+
+extern (C) S13 ctest13(ubyte x, S13, ubyte y);
+
+void test13()
+{
+ version (X86)
+ {
+ S13 t;
+ assert(S13.sizeof == 6);
+ t.a = 2;
+ t.b = 3;
+ t.c = 4;
+ auto s = ctest13(1, t, 5);
+ assert(s.a == 2);
+ assert(s.b == 3);
+ assert(s.c == 4);
+ }
+}
+
+/******************************************/
+
+struct S14 { char a,d,e,f; char b,g; ubyte c; }
+
+extern (C) S14 ctest14(ubyte x, S14, ubyte y);
+
+void test14()
+{
+ version (X86)
+ {
+ S14 t;
+ assert(S14.sizeof == 7);
+ t.a = 2;
+ t.b = 3;
+ t.c = 4;
+ auto s = ctest14(1, t, 5);
+ assert(s.a == 2);
+ assert(s.b == 3);
+ assert(s.c == 4);
+ }
+}
+
+/******************************************/
+
+struct S15 { char a,d,e,f; char b,g,h,i; ubyte c; }
+
+extern (C) S15 ctest15(ubyte x, S15, ubyte y);
+
+void test15()
+{
+ version (X86)
+ {
+ S15 t;
+ assert(S15.sizeof == 9);
+ t.a = 2;
+ t.b = 3;
+ t.c = 4;
+ auto s = ctest15(1, t, 5);
+ assert(s.a == 2);
+ assert(s.b == 3);
+ assert(s.c == 4);
+ }
+}
+
+/******************************************/
+
+// see https://issues.dlang.org/show_bug.cgi?id=17277
+struct S16 {
+ char[5] a;
+ struct {
+ char b;
+ align(1) int c;
+ }
+}
+
+extern (C) S16 ctest16(ubyte x, S16, ubyte y);
+
+void test16()
+{
+ version (X86) // misaligned field
+ {
+ S16 t;
+ assert(S16.sizeof == 10);
+ assert(S16.alignof == 1);
+ t.a = "hello";
+ t.b = 3;
+ t.c = 0x11223344;
+ auto s = ctest16(1, t, 5);
+ assert(s.a == "hello");
+ assert(s.b == 3);
+ assert(s.c == 0x11223344);
+ }
+}
+
+/******************************************/
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+version (Win64)
+{
+}
+else
+{
+ test4();
+}
+ test11();
+ test12();
+ test13();
+ test14();
+ test15();
+ test16();
+
+ return 0;
+}
--- /dev/null
+// EXTRA_CPP_SOURCES: cpp_abi_tests.cpp
+
+extern(C++) {
+
+struct S
+{
+ float a = 1;
+}
+
+bool passthrough(bool value);
+byte passthrough(byte value);
+ubyte passthrough(ubyte value);
+char passthrough(char value);
+dchar passthrough(dchar value);
+short passthrough(short value);
+ushort passthrough(ushort value);
+int passthrough(int value);
+uint passthrough(uint value);
+long passthrough(long value);
+ulong passthrough(ulong value);
+float passthrough(float value);
+double passthrough(double value);
+S passthrough(S value);
+
+bool passthrough_ptr(bool *value);
+byte passthrough_ptr(byte *value);
+ubyte passthrough_ptr(ubyte *value);
+char passthrough_ptr(char *value);
+dchar passthrough_ptr(dchar *value);
+short passthrough_ptr(short *value);
+ushort passthrough_ptr(ushort *value);
+int passthrough_ptr(int *value);
+uint passthrough_ptr(uint *value);
+long passthrough_ptr(long *value);
+ulong passthrough_ptr(ulong *value);
+float passthrough_ptr(float *value);
+double passthrough_ptr(double *value);
+S passthrough_ptr(S *value);
+
+bool passthrough_ref(ref bool value);
+byte passthrough_ref(ref byte value);
+ubyte passthrough_ref(ref ubyte value);
+char passthrough_ref(ref char value);
+dchar passthrough_ref(ref dchar value);
+short passthrough_ref(ref short value);
+ushort passthrough_ref(ref ushort value);
+int passthrough_ref(ref int value);
+uint passthrough_ref(ref uint value);
+long passthrough_ref(ref long value);
+ulong passthrough_ref(ref ulong value);
+float passthrough_ref(ref float value);
+double passthrough_ref(ref double value);
+S passthrough_ref(ref S value);
+}
+
+template IsSigned(T)
+{
+ enum IsSigned = is(T==byte) ||
+ is(T==short) ||
+ is(T==int) ||
+ is(T==long);
+}
+
+template IsUnsigned(T)
+{
+ enum IsUnsigned = is(T==ubyte) ||
+ is(T==ushort) ||
+ is(T==uint) ||
+ is(T==ulong);
+}
+
+template IsIntegral(T)
+{
+ enum IsIntegral = IsSigned!T || IsUnsigned!T;
+}
+
+template IsFloatingPoint(T)
+{
+ enum IsFloatingPoint = is(T==float) || is(T==double) || is(T==real);
+}
+
+template IsBoolean(T)
+{
+ enum IsBoolean = is(T==bool);
+}
+
+template IsSomeChar(T)
+{
+ enum IsSomeChar = is(T==char) || is(T==dchar);
+}
+
+void check(T)(T actual, T expected)
+{
+ assert(actual is expected);
+}
+
+void check(T)(T value)
+{
+ check(passthrough(value), value);
+ check(passthrough_ptr(&value), value);
+ check(passthrough_ref(value), value);
+}
+
+T[] values(T)()
+{
+ T[] values;
+ static if(IsBoolean!T)
+ {
+ values ~= true;
+ values ~= false;
+ }
+ else static if(IsSomeChar!T)
+ {
+ values ~= T.init;
+ values ~= T('a');
+ values ~= T('z');
+ }
+ else
+ {
+ values ~= T(0);
+ values ~= T(1);
+ static if(IsIntegral!T)
+ {
+ static if(IsSigned!T) values ~= T.min;
+ values ~= T.max;
+ }
+ else static if(IsFloatingPoint!T)
+ {
+ values ~= T.nan;
+ values ~= T.min_normal;
+ values ~= T.max;
+ }
+ else
+ {
+ assert(0);
+ }
+ }
+ return values;
+}
+
+void main()
+{
+ foreach(bool val; values!bool()) check(val);
+ foreach(byte val; values!byte()) check(val);
+ foreach(ubyte val; values!ubyte()) check(val);
+ foreach(char val; values!char()) check(val);
+ foreach(dchar val; values!dchar()) check(val);
+ foreach(short val; values!short()) check(val);
+ foreach(ushort val; values!ushort()) check(val);
+ foreach(int val; values!int()) check(val);
+ foreach(uint val; values!uint()) check(val);
+ foreach(long val; values!long()) check(val);
+ foreach(ulong val; values!ulong()) check(val);
+ foreach(float val; values!float()) check(val);
+ foreach(double val; values!double()) check(val);
+ check(S());
+}
--- /dev/null
+// PERMUTE_ARGS: -g
+// EXTRA_CPP_SOURCES: cppb.cpp
+
+import core.stdc.stdio;
+import core.stdc.stdarg;
+import core.stdc.config;
+
+extern (C++)
+ int foob(int i, int j, int k);
+
+class C
+{
+ extern (C++) int bar(int i, int j, int k)
+ {
+ printf("this = %p\n", this);
+ printf("i = %d\n", i);
+ printf("j = %d\n", j);
+ printf("k = %d\n", k);
+ return 1;
+ }
+}
+
+
+extern (C++)
+ int foo(int i, int j, int k)
+{
+ printf("i = %d\n", i);
+ printf("j = %d\n", j);
+ printf("k = %d\n", k);
+ assert(i == 1);
+ assert(j == 2);
+ assert(k == 3);
+ return 1;
+}
+
+void test1()
+{
+ foo(1, 2, 3);
+
+ auto i = foob(1, 2, 3);
+ assert(i == 7);
+
+ C c = new C();
+ c.bar(4, 5, 6);
+}
+
+/****************************************/
+
+extern (C++) interface D
+{
+ int bar(int i, int j, int k);
+}
+
+extern (C++) D getD();
+
+void test2()
+{
+ D d = getD();
+ int i = d.bar(9,10,11);
+ assert(i == 8);
+}
+
+/****************************************/
+
+extern (C++) int callE(E);
+
+extern (C++) interface E
+{
+ int bar(int i, int j, int k);
+}
+
+class F : E
+{
+ extern (C++) int bar(int i, int j, int k)
+ {
+ printf("F.bar: i = %d\n", i);
+ printf("F.bar: j = %d\n", j);
+ printf("F.bar: k = %d\n", k);
+ assert(i == 11);
+ assert(j == 12);
+ assert(k == 13);
+ return 8;
+ }
+}
+
+void test3()
+{
+ F f = new F();
+ int i = callE(f);
+ assert(i == 8);
+}
+
+/****************************************/
+
+extern (C++) void foo4(char* p);
+
+void test4()
+{
+ foo4(null);
+}
+
+/****************************************/
+
+extern(C++)
+{
+ struct foo5 { int i; int j; void* p; }
+
+ interface bar5{
+ foo5 getFoo(int i);
+ }
+
+ bar5 newBar();
+}
+
+void test5()
+{
+ bar5 b = newBar();
+ foo5 f = b.getFoo(4);
+ printf("f.p = %p, b = %p\n", f.p, cast(void*)b);
+ assert(f.p == cast(void*)b);
+}
+
+
+/****************************************/
+
+extern(C++)
+{
+ struct S6
+ {
+ int i;
+ double d;
+ }
+
+ union S6_2
+ {
+ int i;
+ double d;
+ }
+
+ enum S6_3
+ {
+ A, B
+ }
+
+ S6 foo6();
+ S6_2 foo6_2();
+ S6_3 foo6_3();
+}
+
+extern (C) int foosize6();
+
+void test6()
+{
+ S6 f = foo6();
+ printf("%d %d\n", foosize6(), S6.sizeof);
+ assert(foosize6() == S6.sizeof);
+version (X86)
+{
+ assert(f.i == 42);
+ printf("f.d = %g\n", f.d);
+ assert(f.d == 2.5);
+ assert(foo6_2().i == 42);
+ assert(foo6_3() == S6_3.A);
+}
+}
+
+/****************************************/
+
+extern (C) int foo7();
+
+struct S
+{
+ int i;
+ long l;
+}
+
+void test7()
+{
+ printf("%d %d\n", foo7(), S.sizeof);
+ assert(foo7() == S.sizeof);
+}
+
+/****************************************/
+
+extern (C++) void foo8(const(char)*);
+
+void test8()
+{
+ char c;
+ foo8(&c);
+}
+
+/****************************************/
+// 4059
+
+struct elem9 { }
+
+extern(C++) void foobar9(elem9*, elem9*);
+
+void test9()
+{
+ elem9 *a;
+ foobar9(a, a);
+}
+
+/****************************************/
+
+
+struct A11802;
+struct B11802;
+
+extern(C++) class C11802
+{
+ int x;
+ void fun(A11802*) { x += 2; }
+ void fun(B11802*) { x *= 2; }
+}
+
+extern(C++) class D11802 : C11802
+{
+ override void fun(A11802*) { x += 3; }
+ override void fun(B11802*) { x *= 3; }
+}
+
+extern(C++) void test11802x(D11802);
+
+void test11802()
+{
+ auto x = new D11802();
+ x.x = 0;
+ test11802x(x);
+ assert(x.x == 9);
+}
+
+
+/****************************************/
+
+struct S13956
+{
+}
+
+extern(C++) void func13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
+
+extern(C++) void check13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
+{
+ assert(arg0 == S13956());
+ assert(arg1 == 1);
+ assert(arg2 == 2);
+ assert(arg3 == 3);
+ assert(arg4 == 4);
+ assert(arg5 == 5);
+ version (OSX)
+ {
+ version (D_LP64)
+ assert(arg6 == 6);
+ // fails on OSX 32-bit
+ }
+ else
+ assert(arg6 == 6);
+}
+
+void test13956()
+{
+ func13956(S13956(), 1, 2, 3, 4, 5, 6);
+}
+
+/****************************************/
+// 5148
+
+extern (C++)
+{
+ void foo10(const(char)*, const(char)*);
+ void foo10(const int, const int);
+ void foo10(const char, const char);
+ void foo10(bool, bool);
+
+ struct MyStructType { }
+ void foo10(const MyStructType s, const MyStructType t);
+
+ enum MyEnumType { onemember }
+ void foo10(const MyEnumType s, const MyEnumType t);
+}
+
+void test10()
+{
+ char* p;
+ foo10(p, p);
+ foo10(1,2);
+ foo10('c','d');
+ MyStructType s;
+ foo10(s,s);
+ MyEnumType e;
+ foo10(e,e);
+}
+
+/****************************************/
+
+extern (C++, N11.M) { void bar11(); }
+
+extern (C++, A11.B) { extern (C++, C) { void bar(); }}
+
+void test11()
+{
+ bar11();
+ A11.B.C.bar();
+}
+/****************************************/
+
+struct Struct10071
+{
+ void *p;
+ c_long_double r;
+}
+
+extern(C++) size_t offset10071();
+void test10071()
+{
+ assert(offset10071() == Struct10071.r.offsetof);
+}
+
+/****************************************/
+
+char[100] valistbuffer;
+
+extern(C++) void myvprintfx(const(char)* format, va_list va)
+{
+ vsprintf(valistbuffer.ptr, format, va);
+}
+extern(C++) void myvprintf(const(char)*, va_list);
+extern(C++) void myprintf(const(char)* format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ myvprintf(format, ap);
+ va_end(ap);
+}
+
+void testvalist()
+{
+ myprintf("hello %d", 999);
+ assert(valistbuffer[0..9] == "hello 999");
+}
+
+/****************************************/
+// 12825
+
+extern(C++) class C12825
+{
+ uint a = 0x12345678;
+}
+
+void test12825()
+{
+ auto c = new C12825();
+}
+
+/****************************************/
+
+struct S13955a
+{
+ float a;
+ double b;
+}
+
+struct S13955b
+{
+ double a;
+ float b;
+}
+
+struct S13955c
+{
+ float a;
+ float b;
+}
+
+struct S13955d
+{
+ double a;
+ double b;
+}
+
+extern(C++) void check13955(S13955a a, S13955b b, S13955c c, S13955d d)
+{
+ assert(a.a == 2);
+ assert(a.b == 4);
+ assert(b.a == 8);
+ assert(b.b == 16);
+ assert(c.a == 32);
+ assert(c.b == 64);
+ assert(d.a == 128);
+ assert(d.b == 256);
+}
+
+extern(C++) void func13955(S13955a a, S13955b b, S13955c c, S13955d d);
+
+void test13955()
+{
+ func13955(S13955a(2, 4), S13955b(8, 16), S13955c(32, 64), S13955d(128, 256));
+}
+
+/****************************************/
+
+extern(C++) class C13161
+{
+ void dummyfunc();
+ long val_5;
+ uint val_9;
+}
+
+extern(C++) class Test : C13161
+{
+ uint val_0;
+ long val_1;
+}
+
+extern(C++) size_t getoffset13161();
+
+extern(C++) class C13161a
+{
+ void dummyfunc();
+ c_long_double val_5;
+ uint val_9;
+}
+
+extern(C++) class Testa : C13161a
+{
+ bool val_0;
+}
+
+extern(C++) size_t getoffset13161a();
+
+void test13161()
+{
+ assert(getoffset13161() == Test.val_0.offsetof);
+ assert(getoffset13161a() == Testa.val_0.offsetof);
+}
+
+/****************************************/
+
+version (linux)
+{
+ extern(C++, __gnu_cxx)
+ {
+ struct new_allocator(T)
+ {
+ alias size_type = size_t;
+ static if (is(T : char))
+ void deallocate(T*, size_type) { }
+ else
+ void deallocate(T*, size_type);
+ }
+ }
+}
+
+extern (C++, std)
+{
+ struct allocator(T)
+ {
+ version (linux)
+ {
+ alias size_type = size_t;
+ void deallocate(T* p, size_type sz)
+ { (cast(__gnu_cxx.new_allocator!T*)&this).deallocate(p, sz); }
+ }
+ }
+
+ version (linux)
+ {
+ class vector(T, A = allocator!T)
+ {
+ final void push_back(ref const T);
+ }
+
+ struct char_traits(T)
+ {
+ }
+
+ // https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
+ version (none)
+ {
+ extern (C++, __cxx11)
+ {
+ struct basic_string(T, C = char_traits!T, A = allocator!T)
+ {
+ }
+ }
+ }
+ else
+ {
+ struct basic_string(T, C = char_traits!T, A = allocator!T)
+ {
+ }
+ }
+
+ struct basic_istream(T, C = char_traits!T)
+ {
+ }
+
+ struct basic_ostream(T, C = char_traits!T)
+ {
+ }
+
+ struct basic_iostream(T, C = char_traits!T)
+ {
+ }
+ }
+
+ class exception { }
+
+ // 14956
+ extern(C++, N14956)
+ {
+ struct S14956 { }
+ }
+}
+
+extern (C++)
+{
+ version (linux)
+ {
+ void foo14(std.vector!(int) p);
+ void foo14a(std.basic_string!(char) *p);
+ void foo14b(std.basic_string!(int) *p);
+ void foo14c(std.basic_istream!(char) *p);
+ void foo14d(std.basic_ostream!(char) *p);
+ void foo14e(std.basic_iostream!(char) *p);
+
+ void foo14f(std.char_traits!char* x, std.basic_string!char* p, std.basic_string!char* q);
+ }
+}
+
+void test14()
+{
+ version (linux)
+ {
+ std.vector!int p;
+ foo14(p);
+
+ foo14a(null);
+ foo14b(null);
+ foo14c(null);
+ foo14d(null);
+ foo14e(null);
+ foo14f(null, null, null);
+ }
+}
+
+version (linux)
+{
+ void test14a(std.allocator!int * pa)
+ {
+ pa.deallocate(null, 0);
+ }
+
+ void gun(std.vector!int pa)
+ {
+ int x = 42;
+ pa.push_back(x);
+ }
+}
+
+void test13289()
+{
+ assert(f13289_cpp_wchar_t('a') == 'A');
+ assert(f13289_cpp_wchar_t('B') == 'B');
+ assert(f13289_d_wchar('c') == 'C');
+ assert(f13289_d_wchar('D') == 'D');
+ assert(f13289_d_dchar('e') == 'E');
+ assert(f13289_d_dchar('F') == 'F');
+ assert(f13289_cpp_test());
+}
+
+extern(C++)
+{
+ bool f13289_cpp_test();
+
+ version(Posix)
+ {
+ dchar f13289_cpp_wchar_t(dchar);
+ }
+ else version(Windows)
+ {
+ wchar f13289_cpp_wchar_t(wchar);
+ }
+
+ wchar f13289_d_wchar(wchar ch)
+ {
+ if (ch <= 'z' && ch >= 'a')
+ {
+ return cast(wchar)(ch - ('a' - 'A'));
+ }
+ else
+ {
+ return ch;
+ }
+ }
+ dchar f13289_d_dchar(dchar ch)
+ {
+ if (ch <= 'z' && ch >= 'a')
+ {
+ return ch - ('a' - 'A');
+ }
+ else
+ {
+ return ch;
+ }
+ }
+}
+
+/****************************************/
+
+version (CRuntime_Microsoft)
+{
+ enum __c_long_double : double;
+ alias __c_long_double myld;
+}
+else
+ alias c_long_double myld;
+
+extern (C++) myld testld(myld);
+extern (C++) myld testldld(myld, myld);
+
+
+void test15()
+{
+ myld ld = 5.0;
+ ld = testld(ld);
+ assert(ld == 6.0);
+
+ myld ld2 = 5.0;
+ ld2 = testldld(ld2, ld2);
+ assert(ld2 == 6.0);
+}
+
+/****************************************/
+
+version( Windows )
+{
+ alias int x_long;
+ alias uint x_ulong;
+}
+else
+{
+ static if( (void*).sizeof > int.sizeof )
+ {
+ alias long x_long;
+ alias ulong x_ulong;
+ }
+ else
+ {
+ alias int x_long;
+ alias uint x_ulong;
+ }
+}
+
+enum __c_long : x_long;
+enum __c_ulong : x_ulong;
+alias __c_long mylong;
+alias __c_ulong myulong;
+
+extern (C++) mylong testl(mylong);
+extern (C++) myulong testul(myulong);
+
+
+void test16()
+{
+ {
+ mylong ld = 5;
+ ld = testl(ld);
+ assert(ld == 5 + mylong.sizeof);
+ }
+ {
+ myulong ld = 5;
+ ld = testul(ld);
+ assert(ld == 5 + myulong.sizeof);
+ }
+
+ static if (__c_long.sizeof == long.sizeof)
+ {
+ static assert(__c_long.max == long.max);
+ static assert(__c_long.min == long.min);
+ static assert(__c_long.init == long.init);
+ static assert(__c_ulong.max == ulong.max);
+ static assert(__c_ulong.min == ulong.min);
+ static assert(__c_ulong.init == ulong.init);
+ __c_long cl = 0;
+ cl = cl + 1;
+ long l = cl;
+ cl = l;
+ __c_ulong cul = 0;
+ cul = cul + 1;
+ ulong ul = cul;
+ cul = ul;
+ }
+ else static if (__c_long.sizeof == int.sizeof)
+ {
+ static assert(__c_long.max == int.max);
+ static assert(__c_long.min == int.min);
+ static assert(__c_long.init == int.init);
+ static assert(__c_ulong.max == uint.max);
+ static assert(__c_ulong.min == uint.min);
+ static assert(__c_ulong.init == uint.init);
+ __c_long cl = 0;
+ cl = cl + 1;
+ int i = cl;
+ cl = i;
+ __c_ulong cul = 0;
+ cul = cul + 1;
+ uint u = cul;
+ cul = u;
+ }
+ else
+ static assert(0);
+}
+
+/****************************************/
+
+struct S13707
+{
+ void* a;
+ void* b;
+ this(void* a, void* b)
+ {
+ this.a = a;
+ this.b = b;
+ }
+}
+
+extern(C++) S13707 func13707();
+
+void test13707()
+{
+ auto p = func13707();
+ assert(p.a == null);
+ assert(p.b == null);
+}
+
+/****************************************/
+
+struct S13932(int x)
+{
+ int member;
+}
+
+extern(C++) void func13932(S13932!(-1) s);
+
+/****************************************/
+
+extern(C++, N13337.M13337)
+{
+ struct S13337{}
+ void foo13337(S13337 s);
+}
+
+/****************************************/
+// 14195
+
+struct Delegate1(T) {}
+struct Delegate2(T1, T2) {}
+
+template Signature(T)
+{
+ alias Signature = typeof(*(T.init));
+}
+
+extern(C++)
+{
+ alias del1_t = Delegate1!(Signature!(void function()));
+ alias del2_t = Delegate2!(Signature!(int function(float, double)), Signature!(int function(float, double)));
+ void test14195a(del1_t);
+ void test14195b(del2_t);
+}
+
+void test14195()
+{
+ test14195a(del1_t());
+ test14195b(del2_t());
+}
+
+
+/****************************************/
+// 14200
+
+template Tuple14200(T...)
+{
+ alias Tuple14200 = T;
+}
+
+extern(C++) void test14200a(Tuple14200!(int));
+extern(C++) void test14200b(float, Tuple14200!(int, double));
+
+void test14200()
+{
+ test14200a(1);
+ test14200b(1.0f, 1, 1.0);
+}
+
+/****************************************/
+// 14956
+
+extern(C++) void test14956(S14956 s);
+
+/****************************************/
+// check order of overloads in vtable
+
+extern (C++) class Statement {}
+extern (C++) class ErrorStatement {}
+extern (C++) class PeelStatement {}
+extern (C++) class ExpStatement {}
+extern (C++) class DtorExpStatement {}
+
+extern (C++) class Visitor
+{
+public:
+ int visit(Statement) { return 1; }
+ int visit(ErrorStatement) { return 2; }
+ int visit(PeelStatement) { return 3; }
+}
+
+extern (C++) class Visitor2 : Visitor
+{
+ int visit2(ExpStatement) { return 4; }
+ int visit2(DtorExpStatement) { return 5; }
+}
+
+extern(C++) bool testVtableCpp(Visitor2 sv);
+extern(C++) Visitor2 getVisitor2();
+
+bool testVtableD(Visitor2 sv)
+{
+ Statement s1;
+ ErrorStatement s2;
+ PeelStatement s3;
+ ExpStatement s4;
+ DtorExpStatement s5;
+
+ if (sv.visit(s1) != 1) return false;
+ if (sv.visit(s2) != 2) return false;
+ if (sv.visit(s3) != 3) return false;
+ if (sv.visit2(s4) != 4) return false;
+ if (sv.visit2(s5) != 5) return false;
+ return true;
+}
+
+void testVtable()
+{
+ Visitor2 dinst = new Visitor2;
+ if (!testVtableCpp(dinst))
+ assert(0);
+
+ Visitor2 cppinst = getVisitor2();
+ if (!testVtableD(cppinst))
+ assert(0);
+}
+
+/****************************************/
+/* problems detected by fuzzer */
+extern(C++) void fuzz1_cppvararg(long arg10, long arg11, bool arg12);
+extern(C++) void fuzz1_dvararg(long arg10, long arg11, bool arg12)
+{
+ fuzz1_checkValues(arg10, arg11, arg12);
+}
+
+extern(C++) void fuzz1_checkValues(long arg10, long arg11, bool arg12)
+{
+ assert(arg10 == 103);
+ assert(arg11 == 104);
+ assert(arg12 == false);
+}
+
+void fuzz1()
+{
+ long arg10 = 103;
+ long arg11 = 104;
+ bool arg12 = false;
+ fuzz1_dvararg(arg10, arg11, arg12);
+ fuzz1_cppvararg(arg10, arg11, arg12);
+}
+
+////////
+extern(C++) void fuzz2_cppvararg(ulong arg10, ulong arg11, bool arg12);
+extern(C++) void fuzz2_dvararg(ulong arg10, ulong arg11, bool arg12)
+{
+ fuzz2_checkValues(arg10, arg11, arg12);
+}
+
+extern(C++) void fuzz2_checkValues(ulong arg10, ulong arg11, bool arg12)
+{
+ assert(arg10 == 103);
+ assert(arg11 == 104);
+ assert(arg12 == false);
+}
+
+void fuzz2()
+{
+ ulong arg10 = 103;
+ ulong arg11 = 104;
+ bool arg12 = false;
+ fuzz2_dvararg(arg10, arg11, arg12);
+ fuzz2_cppvararg(arg10, arg11, arg12);
+}
+
+////////
+extern(C++) void fuzz3_cppvararg(wchar arg10, wchar arg11, bool arg12);
+extern(C++) void fuzz3_dvararg(wchar arg10, wchar arg11, bool arg12)
+{
+ fuzz2_checkValues(arg10, arg11, arg12);
+}
+
+extern(C++) void fuzz3_checkValues(wchar arg10, wchar arg11, bool arg12)
+{
+ assert(arg10 == 103);
+ assert(arg11 == 104);
+ assert(arg12 == false);
+}
+
+void fuzz3()
+{
+ wchar arg10 = 103;
+ wchar arg11 = 104;
+ bool arg12 = false;
+ fuzz3_dvararg(arg10, arg11, arg12);
+ fuzz3_cppvararg(arg10, arg11, arg12);
+}
+
+void fuzz()
+{
+ fuzz1();
+ fuzz2();
+ fuzz3();
+}
+
+/****************************************/
+
+extern (C++)
+{
+ void throwit();
+}
+
+void testeh()
+{
+ printf("testeh()\n");
+ version (linux)
+ {
+ version (X86_64)
+ {
+ bool caught;
+ try
+ {
+ throwit();
+ }
+ catch (std.exception e)
+ {
+ caught = true;
+ }
+ assert(caught);
+ }
+ }
+}
+
+/****************************************/
+
+version (linux)
+{
+ version (X86_64)
+ {
+ bool raii_works = false;
+ struct RAIITest
+ {
+ ~this()
+ {
+ raii_works = true;
+ }
+ }
+
+ void dFunction()
+ {
+ RAIITest rt;
+ throwit();
+ }
+
+ void testeh2()
+ {
+ printf("testeh2()\n");
+ try
+ {
+ dFunction();
+ }
+ catch(std.exception e)
+ {
+ assert(raii_works);
+ }
+ }
+ }
+ else
+ void testeh2() { }
+}
+else
+ void testeh2() { }
+
+/****************************************/
+
+extern (C++) { void throwle(); void throwpe(); }
+
+void testeh3()
+{
+ printf("testeh3()\n");
+ version (linux)
+ {
+ version (X86_64)
+ {
+ bool caught = false;
+ try
+ {
+ throwle();
+ }
+ catch (std.exception e) //polymorphism test.
+ {
+ caught = true;
+ }
+ assert(caught);
+ }
+ }
+}
+
+/****************************************/
+// 15576
+
+extern (C++, ns15576)
+{
+ extern __gshared int global15576;
+
+ extern (C++, ns)
+ {
+ extern __gshared int n_global15576;
+ }
+}
+
+void test15576()
+{
+ global15576 = n_global15576 = 123;
+}
+
+/****************************************/
+// 15579
+
+extern (C++)
+{
+ class Base
+ {
+ //~this() {}
+ void based() { }
+ ubyte x = 4;
+ }
+
+ interface Interface
+ {
+ int MethodCPP();
+ int MethodD();
+ }
+
+ class Derived : Base, Interface
+ {
+ short y = 5;
+ int MethodCPP();
+ int MethodD() {
+ printf("Derived.MethodD(): this = %p, x = %d, y = %d\n", this, x, y);
+ Derived p = this;
+ //p = cast(Derived)(cast(void*)p - 16);
+ assert(p.x == 4 || p.x == 7);
+ assert(p.y == 5 || p.y == 8);
+ return 3;
+ }
+ int Method() { return 6; }
+ }
+
+ Derived cppfoo(Derived);
+ Interface cppfooi(Interface);
+}
+
+void test15579()
+{
+ Derived d = new Derived();
+ printf("d = %p\n", d);
+ assert(d.x == 4);
+ assert(d.y == 5);
+ assert((cast(Interface)d).MethodCPP() == 30);
+ assert((cast(Interface)d).MethodD() == 3);
+ assert(d.MethodCPP() == 30);
+ assert(d.MethodD() == 3);
+ assert(d.Method() == 6);
+
+ d = cppfoo(d);
+ assert(d.x == 7);
+ assert(d.y == 8);
+
+ printf("d2 = %p\n", d);
+
+ /* Casting to an interface involves thunks in the vtbl[].
+ * g++ puts the thunks for MethodD in the same COMDAT as MethodD.
+ * But D doesn't, so when the linker "picks one" of the D generated MethodD
+ * or the g++ generated MethodD, it may wind up with a messed up thunk,
+ * resulting in a seg fault. The solution is to not expect objects of the same
+ * type to be constructed on both sides of the D/C++ divide if the same member
+ * function (in this case, MethodD) is also defined on both sides.
+ */
+ version (Windows)
+ {
+ assert((cast(Interface)d).MethodD() == 3);
+ }
+ assert((cast(Interface)d).MethodCPP() == 30);
+
+ assert(d.Method() == 6);
+
+ printf("d = %p, i = %p\n", d, cast(Interface)d);
+ version (Windows)
+ {
+ Interface i = cppfooi(d);
+ printf("i2: %p\n", i);
+ assert(i.MethodD() == 3);
+ assert(i.MethodCPP() == 30);
+ }
+ printf("test15579() done\n");
+}
+
+/****************************************/
+// 15610
+
+extern(C++) class Base2
+{
+ int i;
+ void baser() { }
+}
+
+extern(C++) interface Interface2 { abstract void f(); }
+
+extern(C++) class Derived2 : Base2, Interface2
+{
+ final
+ override void f();
+}
+
+
+void test15610()
+{
+ auto c = new Derived2();
+ printf("test15610(): c = %p\n", c);
+ c.i = 3;
+ c.f();
+}
+
+/******************************************/
+// 15455
+
+struct X6
+{
+ ushort a;
+ ushort b;
+ ubyte c;
+ ubyte d;
+}
+
+static assert(X6.sizeof == 6);
+
+struct X8
+{
+ ushort a;
+ X6 b;
+}
+
+static assert(X8.sizeof == 8);
+
+void test15455a(X8 s)
+{
+ assert(s.a == 1);
+ assert(s.b.a == 2);
+ assert(s.b.b == 3);
+ assert(s.b.c == 4);
+ assert(s.b.d == 5);
+}
+
+extern (C++) void test15455b(X8 s);
+
+void test15455()
+{
+ X8 s;
+
+ s.a = 1;
+ s.b.a = 2;
+ s.b.b = 3;
+ s.b.c = 4;
+ s.b.d = 5;
+ test15455a(s);
+ test15455b(s);
+}
+
+/****************************************/
+// 15372
+
+extern(C++) int foo15372(T)(T v);
+
+void test15372()
+{
+ version(Windows){}
+ else
+ assert(foo15372!int(1) == 1);
+}
+
+/****************************************/
+// 15802
+
+extern(C++) {
+ template Foo15802(T) {
+ static int boo(T v);
+ }
+}
+
+void test15802()
+{
+ version(Windows){}
+ else
+ assert(Foo15802!(int).boo(1) == 1);
+}
+
+/****************************************/
+// 16536 - mangling mismatch on OSX
+
+version(OSX) extern(C++) ulong pass16536(ulong);
+
+void test16536()
+{
+ version(OSX) assert(pass16536(123) == 123);
+}
+
+/****************************************/
+
+void main()
+{
+ test1();
+ test2();
+ test3();
+ test4();
+ test13956();
+ test5();
+ test6();
+ test10071();
+ test7();
+ test8();
+ test11802();
+ test9();
+ test10();
+ test13955();
+ test11();
+ testvalist();
+ test12825();
+ test13161();
+ test14();
+ test13289();
+ test15();
+ test16();
+ func13707();
+ func13932(S13932!(-1)(0));
+ foo13337(S13337());
+ test14195();
+ test14200();
+ test14956(S14956());
+ testVtable();
+ fuzz();
+ testeh();
+ testeh2();
+ testeh3();
+ test15576();
+ test15579();
+ test15610();
+ test15455();
+ test15372();
+ test15802();
+ test16536();
+
+ printf("Success\n");
+}
--- /dev/null
+// EXTRA_CPP_SOURCES: externmangle.cpp
+
+extern(C++):
+
+struct Foo(X)
+{
+ X* v;
+}
+
+
+struct Boo(X)
+{
+ X* v;
+}
+
+
+void test1(Foo!int arg1);
+void test2(int* arg2, Boo!(int*) arg1);
+
+
+struct Test3(int X, int Y)
+{
+}
+
+void test3(Test3!(3,3) arg1);
+
+void test4(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3, int*, Foo!(double));
+
+void test5(Foo!(int*) arg1, Boo!(int*) arg2, Boo!(int*) arg3);
+
+
+struct Goo
+{
+ struct Foo(X)
+ {
+ X* v;
+ }
+
+ struct Boo(X)
+ {
+ struct Xoo(Y)
+ {
+ Y* v;
+ };
+ X* v;
+ }
+
+
+ void test6(Foo!(Boo!(Foo!(void))) arg1);
+ void test7(Boo!(void).Xoo!(int) arg1);
+}
+
+struct P1
+{
+ struct Mem(T)
+ {
+ }
+}
+
+struct P2
+{
+ struct Mem(T)
+ {
+ }
+}
+
+void test8(P1.Mem!int, P2.Mem!int);
+void test9(Foo!(int**), Foo!(int*), int**, int*);
+
+
+interface Test10
+{
+ private final void test10();
+ public final void test11();
+ protected final void test12();
+ public final void test13() const;
+
+ private void test14();
+ public void test15();
+ protected void test16();
+
+ private static void test17();
+ public static void test18();
+ protected static void test19();
+};
+
+Test10 Test10Ctor();
+void Test10Dtor(ref Test10 ptr);
+
+struct Test20
+{
+ __gshared:
+ private extern int test20;
+ protected extern int test21;
+ public extern int test22;
+};
+
+
+int test23(Test10*, Test10, Test10**, const(Test10));
+int test23b(const Test10*, const Test10, Test10);
+
+void test24(int function(int,int));
+
+void test25(int[291][6][5]* arr);
+int test26(int[291][6]* arr);
+
+void test27(int, ...);
+void test28(int);
+
+void test29(float);
+void test30(const float);
+
+struct Array(T)
+{
+ int dim;
+}
+
+
+interface Module
+{
+ public static void imports(Module);
+ public static int dim(Array!Module*);
+};
+
+ulong testlongmangle(int a, uint b, long c, ulong d);
+
+__gshared extern int[2][2][2] test31;
+__gshared extern int* test32;
+
+
+alias int function(Expression , void* ) apply_fp_t;
+
+interface Expression
+{
+ public final int apply(apply_fp_t fp, apply_fp_t fp2, void* param);
+ public final int getType();
+ public static Expression create(int);
+ public static void dispose(ref Expression);
+}
+
+//int test34(int[0][0]*);
+version(CRuntime_Microsoft){}
+else
+{
+ int test35(real arg);
+}
+
+const(char)* test36(const(char)*);
+
+final class Test37
+{
+ static Test37 create()
+ {
+ return new Test37;
+ }
+
+ bool test()
+ {
+ return true;
+ }
+}
+
+bool test37();
+
+interface Test38
+{
+ final int test(int, ...);
+ public static Test38 create();
+ public static void dispose(ref Test38);
+}
+
+extern(C++) int test39cpp(C2!char, S2!(int)*);
+
+extern(C++, class)
+struct S1
+{
+ private int val;
+ static S1* init(int);
+ int value();
+}
+
+extern(C++, class)
+struct S2(T)
+{
+ private T val;
+ static S2!T* init(int);
+ T value();
+}
+
+extern(C++, struct)
+class C1
+{
+ const(char)* data;
+
+ static C1 init(const(char)* p);
+ const(char)* getDataCPP();
+ extern(C++) const(char)* getDataD()
+ {
+ return data;
+ }
+}
+
+extern(C++, struct)
+class C2(T)
+{
+ const(T)* data;
+
+ static C2!T init(const(T)* p);
+ const(T)* getData();
+}
+
+void test39()
+{
+ S1* s1 = S1.init(42);
+ assert(s1.value == 42);
+ assert(S2!int.init(43).value == 43);
+ const(char)* ptr = "test".ptr;
+ C1 c1 = C1.init(ptr);
+ assert(c1.getDataCPP() == ptr);
+ assert(c1.getDataD() == ptr);
+ C2!char c2 = C2!char.init(ptr);
+ assert(c2.getData() == ptr);
+ auto result = test39cpp(c2, S2!int.init(43));
+ assert(result == 0);
+}
+
+
+void main()
+{
+ test1(Foo!int());
+ test2(null, Boo!(int*)());
+ test3(Test3!(3,3)());
+ test4(Foo!(int*)(), Boo!(int*)(), Boo!(int*)(), null, Foo!(double)());
+ test5(Foo!(int*)(), Boo!(int*)(), Boo!(int*)());
+ Goo goo;
+ goo.test6(Goo.Foo!(Goo.Boo!(Goo.Foo!(void)))());
+ goo.test7(Goo.Boo!(void).Xoo!(int)());
+
+ test8(P1.Mem!int(), P2.Mem!int());
+ test9(Foo!(int**)(), Foo!(int*)(), null, null);
+
+ auto t10 = Test10Ctor();
+ scope(exit) Test10Dtor(t10);
+
+ t10.test10();
+ t10.test11();
+ t10.test12();
+ t10.test13();
+ t10.test14();
+ t10.test15();
+ t10.test16();
+ t10.test17();
+ t10.test18();
+ t10.test19();
+
+ assert(Test20.test20 == 20);
+ assert(Test20.test21 == 21);
+ assert(Test20.test22 == 22);
+
+ assert(test23(null, null, null, null) == 1);
+ assert(test23b(null, null, null) == 1);
+
+ extern(C++) static int cb(int a, int b){return a+b;}
+
+ test24(&cb);
+ int[291][6][5] arr;
+ arr[1][1][1] = 42;
+ test25(&arr);
+ assert(test26(&arr[0]) == 42);
+
+ test27(3,4,5);
+ test28(3);
+
+ test29(3.14f);
+ test30(3.14f);
+
+ auto t32 = &Module.imports;
+ Array!Module arr2;
+ arr2.dim = 20;
+ assert(Module.dim(&arr2) == 20);
+
+ assert(testlongmangle(1, 2, 3, 4) == 10);
+ assert(test31 == [[[1, 1], [1, 1]], [[1, 1], [1, 1]]]);
+ assert(test32 == null);
+
+ auto ee = Expression.create(42);
+ extern(C++) static int efun(Expression e, void* p)
+ {
+ return cast(int)(cast(size_t)p ^ e.getType());
+ }
+
+ extern(C++) static int efun2(Expression e, void* p)
+ {
+ return cast(int)(cast(size_t)p * e.getType());
+ }
+
+ auto test33 = ee.apply(&efun, &efun2, cast(void*)&Expression.create);
+ assert(test33 == cast(int)(cast(size_t)cast(void*)&Expression.create ^ 42) * cast(int)(cast(size_t)cast(void*)&Expression.create * 42));
+ Expression.dispose(ee);
+ assert(ee is null);
+ //assert(test34(null) == 0);
+ version(CRuntime_Microsoft){}
+ else
+ {
+ assert(test35(3.14L) == 3);
+ }
+ const char* hello = "hello";
+ assert(test36(hello) == hello);
+ assert(test37());
+ auto t38 = Test38.create();
+ assert(t38.test(1, 2, 3) == 1);
+ Test38.dispose(t38);
+ test39();
+}
--- /dev/null
+// EXTRA_CPP_SOURCES: externmangle2.cpp
+
+version(Windows)
+{
+ void main()
+ {
+ }
+}
+else
+{
+ extern(C++):
+
+ struct Test32NS1
+ {
+ struct Foo(X)
+ {
+ X *v;
+ }
+
+
+ struct Bar(X)
+ {
+ X *v;
+ }
+
+ };
+
+ struct Test32NS2
+ {
+ struct Foo(X)
+ {
+ X *v;
+ }
+ };
+
+ struct Test32(alias Y, alias Z)
+ {
+ Y!(int)* field;
+ };
+
+
+ void test32a(Test32!(Test32NS1.Foo, Test32NS1.Foo) arg);
+ void test32b(Test32!(Test32NS1.Foo, Test32NS1.Bar) arg);
+ void test32c(Test32!(Test32NS1.Foo, Test32NS2.Foo) arg);
+ void test32d(Test32!(Test32NS1.Foo, Test32NS2.Foo) arg1, Test32!(Test32NS2.Foo, Test32NS1.Foo) arg2);
+
+ interface XXX
+ {
+ }
+
+ void test33a(XXX, XXX*);
+
+
+ struct Test33(alias A, alias B)
+ {
+ }
+
+ /*
+ void test33(XXX, Test33!(test33a, test33a) arg, XXX);
+
+
+ struct Test34(alias A)
+ {
+ };
+
+ struct Test34A
+ {
+ static void foo(int);
+ };
+
+
+ void test34(Test34!(Test34A.foo) arg);
+ */
+
+ __gshared extern int test36;
+
+ /*
+ struct Test37(alias A)
+ {
+ };
+
+ struct Test37A
+ {
+ __gshared extern int t38;
+ };
+
+ void test37(Test37!(test36) arg);
+ void test38(Test37!(Test37A.t38) arg);
+ */
+
+ struct Test39
+ {
+ struct T39A(X)
+ {
+ }
+ }
+
+ struct T39A
+ {
+ }
+
+ void test39(Test39.T39A!(.T39A));
+
+ version(none)
+ {
+ version(Posix) //Only for g++ with -std=c++0x and Visual Studio 2013+
+ {
+
+ struct Test40(T, V...)
+ {
+
+ }
+
+ void test40(Test40!(int, double, void))
+ {
+ }
+ }
+ else version(Win64) //Only for g++ with -std=c++0x and Visual Studio 2013+
+ {
+
+ struct Test40(T, V...)
+ {
+
+ }
+
+ void test40(Test40!(int, double, void))
+ {
+ }
+ }
+ }
+
+
+ __gshared extern const XXX test41;
+ struct Test42
+ {
+ __gshared extern const XXX test42;
+ }
+ __gshared extern int[4] test43;
+ const(XXX) test44();
+
+ void main()
+ {
+ test32a(Test32!(Test32NS1.Foo, Test32NS1.Foo)());
+ test32b(Test32!(Test32NS1.Foo, Test32NS1.Bar)());
+ test32c(Test32!(Test32NS1.Foo, Test32NS2.Foo)());
+ test32d(Test32!(Test32NS1.Foo, Test32NS2.Foo)(), Test32!(Test32NS2.Foo, Test32NS1.Foo)());
+
+ //test33a(null, null);
+ //test33(null, Test33!(test33a, test33a)(), null);
+
+ //test34(Test34!(Test34A.foo)());
+
+ assert(test36 == 36);
+
+ //test37(Test37!(test36)());
+ //test38(Test37!(Test37A.t38)());
+ test39(Test39.T39A!(.T39A)());
+
+ assert(test41 is null);
+ assert(Test42.test42 is null);
+ assert(test43 == [1, 2, 3, 4]);
+ auto ptr = &test44;
+ }
+}
--- /dev/null
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdint.h>
+
+#if __cplusplus
+extern "C" {
+#endif
+
+struct Foo1 { char c; };
+
+struct Foo1 ctest1()
+{
+ struct Foo1 f;
+
+ f.c = 3;
+ return f;
+}
+
+struct Foo2 { short s; };
+
+struct Foo2 ctest2()
+{
+ struct Foo2 f;
+
+ f.s = 0x1234;
+ return f;
+}
+
+struct Foo3 { char c; short s; };
+
+struct Foo3 ctest3()
+{
+ struct Foo3 f;
+
+ f.s = 0x5678;
+ return f;
+}
+
+
+struct Foo4 { int i; };
+
+struct Foo4 ctest4()
+{
+ struct Foo4 f;
+
+ f.i = 0x12345678;
+ return f;
+}
+
+struct Foo5 { int i, j; };
+
+struct Foo5 ctest5()
+{
+ struct Foo5 f;
+
+ f.i = 0x12345678;
+ f.j = 0x21436587;
+ return f;
+}
+
+
+struct Foo6 { int i, j, k; };
+
+struct Foo6 ctest6()
+{
+ struct Foo6 f;
+
+ f.i = 0x12345678;
+ f.j = 0x21463587;
+ f.k = 0x24163857;
+ return f;
+}
+
+struct S7 { float a,b; };
+
+struct S7 ctest10()
+{
+ struct S7 f;
+
+ f.a = 2.5;
+ f.b = 1.5;
+ return f;
+}
+
+// =================================
+
+char ctest7(char c)
+{
+ return c + 1;
+}
+
+unsigned char ctest8(unsigned char c)
+{
+ return c + 1;
+}
+
+signed char ctest9(signed char c)
+{
+ return c + 1;
+}
+
+/***********************************************/
+
+void ctestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c)
+{
+ assert(a == 100.0);
+ assert(b == 67);
+ assert(c == 200.0);
+}
+
+/***********************************************/
+
+extern void dtestrir(int x1, int x2, int x3, int x4, int x5, int x6, long double a, int b, long double c);
+
+void test4()
+{
+ dtestrir(1,2,3,4,5,6, 300.0, 68, 401.0);
+}
+
+/**********************************************/
+
+typedef struct S11 {
+ char a;
+ char b;
+ char c;
+} S11;
+
+S11 ctest11(char x, S11 s, char y) {
+ printf("C sz = %d\n", (int)sizeof(S11));
+ assert(sizeof(S11) == 3);
+ printf("x = %d\n", (int)x);
+ printf("s.a = %d\n", (int)s.a);
+ printf("s.b = %d\n", (int)s.b);
+ printf("s.c = %d\n", (int)s.c);
+ printf("y = %d\n", (int)y);
+ return s;
+}
+
+/**********************************************/
+
+typedef struct S12 {
+ char a,d;
+ char b,e;
+ char c;
+} S12;
+
+S12 ctest12(char x, S12 s, char y) {
+ printf("C sz = %d\n", (int)sizeof(S12));
+ assert(sizeof(S12) == 5);
+ printf("x = %d\n", (int)x);
+ printf("s.a = %d\n", (int)s.a);
+ printf("s.b = %d\n", (int)s.b);
+ printf("s.c = %d\n", (int)s.c);
+ printf("y = %d\n", (int)y);
+ return s;
+}
+
+
+/**********************************************/
+
+typedef struct S13 {
+ short a;
+ short b;
+ short c;
+} S13;
+
+S13 ctest13(char x, S13 s, char y) {
+ printf("C sz = %d\n", (int)sizeof(S13));
+ assert(sizeof(S13) == 6);
+ printf("x = %d\n", (int)x);
+ printf("s.a = %d\n", (int)s.a);
+ printf("s.b = %d\n", (int)s.b);
+ printf("s.c = %d\n", (int)s.c);
+ printf("y = %d\n", (int)y);
+ return s;
+}
+
+
+/**********************************************/
+
+typedef struct S14 {
+ char a,d,e,f;
+ char b,g;
+ char c;
+} S14;
+
+S14 ctest14(char x, S14 s, char y) {
+ printf("C sz = %d\n", (int)sizeof(S14));
+ assert(sizeof(S14) == 7);
+ printf("x = %d\n", (int)x);
+ printf("s.a = %d\n", (int)s.a);
+ printf("s.b = %d\n", (int)s.b);
+ printf("s.c = %d\n", (int)s.c);
+ printf("y = %d\n", (int)y);
+ return s;
+}
+
+
+/**********************************************/
+
+typedef struct S15 {
+ char a,d,e,f;
+ char b,g,h,i;
+ char c;
+} S15;
+
+S15 ctest15(char x, S15 s, char y) {
+ printf("C sz = %d\n", (int)sizeof(S15));
+ assert(sizeof(S15) == 9);
+ printf("x = %d\n", (int)x);
+ printf("s.a = %d\n", (int)s.a);
+ printf("s.b = %d\n", (int)s.b);
+ printf("s.c = %d\n", (int)s.c);
+ printf("y = %d\n", (int)y);
+ return s;
+}
+
+
+/**********************************************/
+
+typedef struct S16 {
+ char a[5];
+#ifdef __GNUC__
+ struct __attribute__((packed))
+#else
+ #pragma pack(push, 1)
+ struct
+#endif
+ {
+ char b;
+ int c;
+ };
+#ifndef __GNUC__
+ #pragma pack(pop)
+#endif
+} S16;
+
+S16 ctest16(char x, S16 s, char y) {
+ printf("C sz = %d\n", (int)sizeof(S16));
+ assert(sizeof(S16) == 10);
+ printf("x = %d\n", (int)x);
+ printf("s.a = %.*s\n", 5, s.a);
+ printf("s.b = %d\n", (int)s.b);
+ printf("s.c = %d\n", s.c);
+ printf("y = %d\n", (int)y);
+ return s;
+}
+
+
+
+#if __cplusplus
+}
+#endif
+
--- /dev/null
+struct S{
+ float a;
+};
+
+bool passthrough(bool value) { return value; }
+signed char passthrough(signed char value) { return value; }
+unsigned char passthrough(unsigned char value) { return value; }
+char passthrough(char value) { return value; }
+wchar_t passthrough(wchar_t value) { return value; }
+short passthrough(short value) { return value; }
+unsigned short passthrough(unsigned short value) { return value; }
+int passthrough(int value) { return value; }
+unsigned int passthrough(unsigned int value) { return value; }
+long passthrough(long value) { return value; }
+unsigned long passthrough(unsigned long value) { return value; }
+long long passthrough(long long value) { return value; }
+unsigned long long passthrough(unsigned long long value) { return value; }
+float passthrough(float value) { return value; }
+double passthrough(double value) { return value; }
+S passthrough(S value) { return value; }
+
+bool passthrough_ptr(bool *value) { return *value; }
+signed char passthrough_ptr(signed char *value) { return *value; }
+unsigned char passthrough_ptr(unsigned char *value) { return *value; }
+char passthrough_ptr(char *value) { return *value; }
+wchar_t passthrough_ptr(wchar_t *value) { return *value; }
+short passthrough_ptr(short *value) { return *value; }
+unsigned short passthrough_ptr(unsigned short *value) { return *value; }
+int passthrough_ptr(int *value) { return *value; }
+unsigned int passthrough_ptr(unsigned int *value) { return *value; }
+long passthrough_ptr(long *value) { return *value; }
+unsigned long passthrough_ptr(unsigned long *value) { return *value; }
+long long passthrough_ptr(long long *value) { return *value; }
+unsigned long long passthrough_ptr(unsigned long long *value) { return *value; }
+float passthrough_ptr(float *value) { return *value; }
+double passthrough_ptr(double *value) { return *value; }
+S passthrough_ptr(S *value) { return *value; }
+
+bool passthrough_ref(bool &value) { return value; }
+signed char passthrough_ref(signed char &value) { return value; }
+unsigned char passthrough_ref(unsigned char &value) { return value; }
+char passthrough_ref(char &value) { return value; }
+wchar_t passthrough_ref(wchar_t &value) { return value; }
+short passthrough_ref(short &value) { return value; }
+unsigned short passthrough_ref(unsigned short &value) { return value; }
+int passthrough_ref(int &value) { return value; }
+unsigned int passthrough_ref(unsigned int &value) { return value; }
+long passthrough_ref(long &value) { return value; }
+unsigned long passthrough_ref(unsigned long &value) { return value; }
+long long passthrough_ref(long long &value) { return value; }
+unsigned long long passthrough_ref(unsigned long long &value) { return value; }
+float passthrough_ref(float &value) { return value; }
+double passthrough_ref(double &value) { return value; }
+S passthrough_ref(S &value) { return value; }
+
+// Uncomment when mangling is fixed
+// typedef void(*fn0)();
+// fn0 passthrough_fn0 (fn0 value) { return value; }
+// typedef int (*fn1)(int);
+// fn1 passthrough_fn1 (fn1 value) { return value; }
--- /dev/null
+/*
+GCC 5.1 introduced new implementations of std::string and std::list:
+
+https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
+
+This causes e.g. std::string to be actually defined as
+std::__cxx11::string.
+
+On machines with GCC 5.1, this manifests as a linker error when
+running the cppa.d / cppb.cpp test:
+
+cppa.o: In function `_D4cppa6test14FZv':
+cppa.d:(.text._D4cppa6test14FZv+0x11): undefined reference to `foo14a(std::string*)'
+cppa.d:(.text._D4cppa6test14FZv+0x18): undefined reference to `foo14b(std::basic_string<int, std::char_traits<int>, std::allocator<int> >*)'
+cppa.d:(.text._D4cppa6test14FZv+0x3a): undefined reference to `foo14f(std::char_traits<char>*, std::string*, std::string*)'
+cppa.o: In function `_D4cppa7testeh3FZv':
+cppa.d:(.text._D4cppa7testeh3FZv+0x19): undefined reference to `throwle()'
+collect2: error: ld returned 1 exit status
+--- errorlevel 1
+
+When the .cpp file is compiled with g++ 5.3.0, the actual function
+signatures in the cppb.o object file are:
+
+foo14a(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
+foo14b(std::__cxx11::basic_string<int, std::char_traits<int>, std::allocator<int> >*)
+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> >*)
+
+Fortunately, it is easily possible to disable the new feature
+by defining _GLIBCXX_USE_CXX11_ABI as 0 before including any standard
+headers.
+*/
+#define _GLIBCXX_USE_CXX11_ABI 0
+
+#include <stdio.h>
+#include <assert.h>
+#include <exception>
+#include <cstdarg>
+
+/**************************************/
+
+int foo(int i, int j, int k);
+
+int foob(int i, int j, int k)
+{
+ printf("i = %d\n", i);
+ printf("j = %d\n", j);
+ printf("k = %d\n", k);
+ assert(i == 1);
+ assert(j == 2);
+ assert(k == 3);
+
+ foo(i, j, k);
+
+ return 7;
+}
+
+/**************************************/
+
+class D *dthis;
+
+class D
+{
+ public:
+ virtual int bar(int i, int j, int k)
+ {
+ printf("this = %p\n", this);
+ assert(this == dthis);
+ printf("D.bar: i = %d\n", i);
+ printf("D.bar: j = %d\n", j);
+ printf("D.bar: k = %d\n", k);
+ assert(i == 9);
+ assert(j == 10);
+ assert(k == 11);
+ return 8;
+ }
+};
+
+
+D* getD()
+{
+ D *d = new D();
+ dthis = d;
+ return d;
+}
+
+/**************************************/
+
+class E
+{
+ public:
+ virtual int bar(int i, int j, int k);
+};
+
+
+int callE(E *e)
+{
+ return e->bar(11,12,13);
+}
+
+/**************************************/
+
+void foo4(char *p)
+{
+}
+
+/**************************************/
+
+struct foo5 { int i; int j; void *p; };
+
+class bar5
+{
+public:
+ virtual foo5 getFoo(int i){
+ printf("This = %p\n", this);
+ foo5 f;
+ f.i = 1;
+ f.j = 2 + i;
+ f.p = (void*)this;
+ return f;
+ }
+};
+
+bar5* newBar()
+{
+ bar5* b = new bar5();
+ printf("bar = %p\n", b);
+ return b;
+}
+
+
+/**************************************/
+
+struct A11802;
+struct B11802;
+
+class C11802
+{
+public:
+ virtual void fun(A11802 *);
+ virtual void fun(B11802 *);
+};
+
+class D11802 : public C11802
+{
+public:
+ void fun(A11802 *);
+ void fun(B11802 *);
+};
+
+void test11802x(D11802 *c)
+{
+ c->fun((A11802 *)0);
+ c->fun((B11802 *)0);
+}
+
+/**************************************/
+
+typedef struct
+{
+ int i;
+ double d;
+} S6;
+
+union S6_2
+{
+ int i;
+ double d;
+};
+
+enum S6_3
+{
+ A, B
+};
+
+
+S6 foo6(void)
+{
+ S6 s;
+ s.i = 42;
+ s.d = 2.5;
+ return s;
+}
+
+S6_2 foo6_2(void)
+{
+ S6_2 s;
+ s.i = 42;
+ return s;
+}
+
+S6_3 foo6_3(void)
+{
+ S6_3 s = A;
+ return s;
+}
+
+extern "C" { int foosize6()
+{
+ return sizeof(S6);
+}
+}
+
+/**************************************/
+
+typedef struct
+{
+ int i;
+ long long d;
+} S7;
+
+extern "C" { int foo7()
+{
+ return sizeof(S7);
+}
+}
+
+/**************************************/
+
+struct S13955a
+{
+ float a;
+ double b;
+};
+
+struct S13955b
+{
+ double a;
+ float b;
+};
+
+struct S13955c
+{
+ float a;
+ float b;
+};
+
+struct S13955d
+{
+ double a;
+ double b;
+};
+
+void check13955(S13955a a, S13955b b, S13955c c, S13955d d);
+
+void func13955(S13955a a, S13955b b, S13955c c, S13955d d)
+{
+ check13955(a, b, c, d);
+}
+
+/**************************************/
+
+struct Struct10071
+{
+ void *p;
+ long double r;
+};
+
+size_t offset10071()
+{
+ Struct10071 s;
+ return (char *)&s.r - (char *)&s;
+}
+
+/**************************************/
+
+void foo8(const char *p)
+{
+}
+
+/**************************************/
+// 4059
+
+struct elem9 { };
+void foobar9(elem9*, elem9*) { }
+
+/**************************************/
+// 5148
+
+void foo10(const char*, const char*) { }
+void foo10(const int, const int) { }
+void foo10(const char, const char) { }
+void foo10(bool, bool) { }
+
+struct MyStructType { };
+void foo10(const MyStructType s, const MyStructType t) { }
+
+enum MyEnumType { onemember };
+void foo10(const MyEnumType s, const MyEnumType t) { }
+
+/**************************************/
+
+namespace N11 { namespace M { void bar11() { } } }
+
+namespace A11 { namespace B { namespace C { void bar() { } } } }
+
+/**************************************/
+
+void myvprintfx(const char* format, va_list);
+
+void myvprintf(const char* format, va_list va)
+{
+ myvprintfx(format, va);
+}
+
+/**************************************/
+
+class C13161
+{
+public:
+ virtual void dummyfunc() {}
+ long long val_5;
+ unsigned val_9;
+};
+
+class Test : public C13161
+{
+public:
+ unsigned val_0;
+ long long val_1;
+};
+
+size_t getoffset13161()
+{
+ Test s;
+ return (char *)&s.val_0 - (char *)&s;
+}
+
+class C13161a
+{
+public:
+ virtual void dummyfunc() {}
+ long double val_5;
+ unsigned val_9;
+};
+
+class Testa : public C13161a
+{
+public:
+ bool val_0;
+};
+
+size_t getoffset13161a()
+{
+ Testa s;
+ return (char *)&s.val_0 - (char *)&s;
+}
+
+/****************************************************/
+
+#if __linux__ || __APPLE__ || __FreeBSD__
+#include <memory>
+#include <vector>
+#include <string>
+
+#if __linux__
+template struct std::allocator<int>;
+template struct std::vector<int>;
+
+void foo15()
+{
+ std::allocator<int>* p;
+ p->deallocate(0, 0);
+}
+
+#endif
+
+// _Z5foo14PSt6vectorIiSaIiEE
+void foo14(std::vector<int, std::allocator<int> > *p) { }
+
+void foo14a(std::basic_string<char> *p) { }
+void foo14b(std::basic_string<int> *p) { }
+void foo14c(std::basic_istream<char> *p) { }
+void foo14d(std::basic_ostream<char> *p) { }
+void foo14e(std::basic_iostream<char> *p) { }
+
+void foo14f(std::char_traits<char>* x, std::basic_string<char> *p, std::basic_string<char> *q) { }
+
+#endif
+
+/**************************************/
+
+struct S13956
+{
+};
+
+void check13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
+
+void func13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
+{
+ check13956(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+/**************************************/
+
+wchar_t f13289_cpp_wchar_t(wchar_t ch)
+{
+ if (ch <= L'z' && ch >= L'a')
+ {
+ return ch - (L'a' - L'A');
+ }
+ else
+ {
+ return ch;
+ }
+}
+
+#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun || __NetBSD__
+unsigned short f13289_d_wchar(unsigned short ch);
+wchar_t f13289_d_dchar(wchar_t ch);
+#elif _WIN32
+wchar_t f13289_d_wchar(wchar_t ch);
+unsigned int f13289_d_dchar(unsigned int ch);
+#endif
+
+bool f13289_cpp_test()
+{
+#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun || __NetBSD__
+ if (!(f13289_d_wchar((unsigned short)'c') == (unsigned short)'C')) return false;
+ if (!(f13289_d_wchar((unsigned short)'D') == (unsigned short)'D')) return false;
+ if (!(f13289_d_dchar(L'e') == L'E')) return false;
+ if (!(f13289_d_dchar(L'F') == L'F')) return false;
+ return true;
+#elif _WIN32
+ if (!(f13289_d_wchar(L'c') == L'C')) return false;
+ if (!(f13289_d_wchar(L'D') == L'D')) return false;
+ if (!(f13289_d_dchar((unsigned int)'e') == (unsigned int)'E')) return false;
+ if (!(f13289_d_dchar((unsigned int)'F') == (unsigned int)'F')) return false;
+ return true;
+#else
+ return false;
+#endif
+}
+
+/******************************************/
+
+long double testld(long double ld)
+{
+ assert(ld == 5);
+ return ld + 1;
+}
+
+long double testldld(long double ld1, long double ld2)
+{
+ assert(ld1 == 5);
+ return ld2 + 1;
+}
+
+long testl(long lng)
+{
+ assert(lng == 5);
+ return lng + sizeof(long);
+}
+
+unsigned long testul(unsigned long ul)
+{
+ assert(ul == 5);
+ return ul + sizeof(unsigned long);
+}
+
+/******************************************/
+
+struct S13707
+{
+ void* a;
+ void* b;
+ S13707(void *a, void* b)
+ {
+ this->a = a;
+ this->b = b;
+ }
+};
+
+S13707 func13707()
+{
+ S13707 pt(NULL, NULL);
+ return pt;
+}
+
+/******************************************/
+
+template <int x> struct S13932
+{
+ int member;
+};
+
+void func13932(S13932<-1> s) {}
+
+/******************************************/
+
+namespace N13337 {
+ namespace M13337 {
+ struct S13337 { };
+ void foo13337(S13337 s) { }
+ }
+}
+
+/****************************************/
+// 14195
+
+template <typename T>
+struct Delegate1 {};
+
+template <typename R1>
+struct Delegate1 < R1() > {};
+
+template <typename T1, typename T2>
+struct Delegate2 {};
+
+template < typename R1, typename T1, typename T2, typename R2, typename T3, typename T4 >
+struct Delegate2<R1(T1, T2), R2(T3, T4)> {};
+
+void test14195a(Delegate1<void()> func) {}
+
+void test14195b(Delegate2<int(float, double), int(float, double)> func) {}
+
+/******************************************/
+// 14200
+
+void test14200a(int a) {};
+void test14200b(float a, int b, double c) {};
+
+/******************************************/
+// 14956
+
+namespace std {
+ namespace N14956 {
+ struct S14956 { };
+ }
+}
+
+void test14956(std::N14956::S14956 s) { }
+
+/******************************************/
+// check order of overloads in vtable
+
+class Statement;
+class ErrorStatement;
+class PeelStatement;
+class ExpStatement;
+class DtorExpStatement;
+
+class Visitor
+{
+public:
+ virtual int visit(Statement*) { return 1; }
+ virtual int visit(ErrorStatement*) { return 2; }
+ virtual int visit(PeelStatement*) { return 3; }
+};
+
+class Visitor2 : public Visitor
+{
+public:
+ virtual int visit2(ExpStatement*) { return 4; }
+ virtual int visit2(DtorExpStatement*) { return 5; }
+};
+
+bool testVtableCpp(Visitor2* sv)
+{
+ if (sv->visit((Statement*)0) != 1) return false;
+ if (sv->visit((ErrorStatement*)0) != 2) return false;
+ if (sv->visit((PeelStatement*)0) != 3) return false;
+ if (sv->visit2((ExpStatement*)0) != 4) return false;
+ if (sv->visit2((DtorExpStatement*)0) != 5) return false;
+ return true;
+}
+
+Visitor2 inst;
+
+Visitor2* getVisitor2()
+{
+ return &inst;
+}
+
+/******************************************/
+// issues detected by fuzzer
+#if _LP64
+#define longlong long
+#else
+#define longlong long long
+#endif
+
+void fuzz1_checkValues(longlong arg10, longlong arg11, bool arg12);
+void fuzz1_cppvararg(longlong arg10, longlong arg11, bool arg12)
+{
+ fuzz1_checkValues(arg10, arg11, arg12);
+}
+
+void fuzz2_checkValues(unsigned longlong arg10, unsigned longlong arg11, bool arg12);
+void fuzz2_cppvararg(unsigned longlong arg10, unsigned longlong arg11, bool arg12)
+{
+ fuzz2_checkValues(arg10, arg11, arg12);
+}
+
+#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun || __NetBSD__
+#define wchar unsigned short
+#elif _WIN32
+#define wchar wchar_t
+#endif
+
+void fuzz3_checkValues(wchar arg10, wchar arg11, bool arg12);
+void fuzz3_cppvararg(wchar arg10, wchar arg11, bool arg12)
+{
+ fuzz3_checkValues(arg10, arg11, arg12);
+}
+
+/******************************************/
+
+void throwit()
+{
+#if _WIN32
+#else
+ std::exception se;
+ throw se;
+#endif
+}
+
+/******************************************/
+
+#if linux
+#include <stdexcept>
+
+void throwle()
+{
+ std::logic_error le("test");
+ throw le;
+}
+
+#endif
+
+/******************************************/
+// 15579
+
+/******************************************/
+// 15579
+
+class Base
+{
+public:
+ //virtual ~Base() {}
+ virtual void base();
+ unsigned char x;
+};
+
+class Interface
+{
+public:
+ virtual int MethodCPP() = 0;
+ virtual int MethodD() = 0;
+};
+
+class Derived : public Base, public Interface
+{
+public:
+ Derived();
+ short y;
+ int MethodCPP();
+#if _WIN32 || _WIN64
+ int MethodD();
+ virtual int Method();
+#else
+ int MethodD() { return 3; } // need def or vtbl[] is not generated
+ virtual int Method() { return 6; } // need def or vtbl[] is not generated
+#endif
+};
+
+void Base::base() { }
+int Derived::MethodCPP() {
+ printf("Derived::MethodCPP() this = %p, x = %d, y = %d\n", this, x, y);
+ assert(x == 4 || x == 7);
+ assert(y == 5 || y == 8);
+ return 30;
+}
+Derived::Derived() { }
+
+
+Derived *cppfoo(Derived *d)
+{
+ printf("cppfoo(): d = %p\n", d);
+ assert(d->x == 4);
+ assert(d->y == 5);
+ assert(d->MethodD() == 3);
+ assert(d->MethodCPP() == 30);
+ assert(d->Method() == 6);
+
+ d = new Derived();
+ d->x = 7;
+ d->y = 8;
+ assert(d->MethodD() == 3);
+ assert(d->MethodCPP() == 30);
+ assert(d->Method() == 6);
+ printf("d1 = %p\n", d);
+ return d;
+}
+
+Interface *cppfooi(Interface *i)
+{
+ printf("cppfooi(): i = %p\n", i);
+ assert(i->MethodD() == 3);
+ assert(i->MethodCPP() == 30);
+
+ Derived *d = new Derived();
+ d->x = 7;
+ d->y = 8;
+ printf("d = %p, i = %p\n", d, (Interface *)d);
+ return d;
+}
+
+/******************************************/
+// 15610
+
+class Base2
+{
+ public:
+ int i;
+ virtual void baser() { }
+};
+
+class Interface2
+{
+ public:
+ virtual void f() = 0;
+};
+
+class Derived2 : public Base2, public Interface2
+{
+ public:
+ void f();
+};
+
+void Derived2::f()
+{
+ printf("Derived2::f() this = %p i = %d\n", this, i);
+ assert(i == 3);
+}
+
+/******************************************/
+// 15455
+
+struct X6
+{
+ unsigned short a;
+ unsigned short b;
+ unsigned char c;
+ unsigned char d;
+};
+
+struct X8
+{
+ unsigned short a;
+ X6 b;
+};
+
+void test15455b(X8 s)
+{
+ assert(sizeof(X6) == 6);
+ assert(sizeof(X8) == 8);
+ assert(s.a == 1);
+ assert(s.b.a == 2);
+ assert(s.b.b == 3);
+ assert(s.b.c == 4);
+ assert(s.b.d == 5);
+}
+
+/******************************************/
+// 15372
+
+template <typename T>
+int foo15372(int value)
+{
+ return value;
+}
+
+void test15372b()
+{
+ int t = foo15372<int>(1);
+}
+
+/****************************************/
+// 15576
+
+namespace ns15576
+{
+ int global15576;
+
+ namespace ns
+ {
+ int n_global15576;
+ }
+}
+
+/****************************************/
+// 15802
+
+template <typename T>
+class Foo15802
+{
+public:
+ static int boo(int value)
+ {
+ return value;
+ }
+};
+
+void test15802b()
+{
+ int t = Foo15802<int>::boo(1);
+}
+
+
+/****************************************/
+// 16536 - mangling mismatch on OSX
+
+#if defined(__APPLE__)
+__UINTMAX_TYPE__ pass16536(__UINTMAX_TYPE__ a)
+{
+ return a;
+}
+#endif
--- /dev/null
+#include <stdint.h>
+
+template<class X>
+struct Foo
+{
+ X *v;
+};
+
+template<class X>
+struct Boo
+{
+ X *v;
+};
+
+void test1(Foo<int> arg1)
+{
+}
+
+
+void test2(int* arg2, Boo<int*> arg1)
+{
+}
+
+template<int X, int Y>
+struct Test3
+{
+
+};
+
+void test3(Test3<3,3> arg1)
+{
+}
+
+void test4(Foo<int*> arg1, Boo<int*> arg2, Boo<int*> arg3, int*, Foo<double>)
+{
+}
+
+void test5(Foo<int*> arg1, Boo<int*> arg2, Boo<int*> arg3)
+{
+}
+
+struct Goo
+{
+
+ template<class X>
+ struct Foo
+ {
+ X* v;
+ };
+
+ template<class X>
+ struct Boo
+ {
+ template<class Y>
+ struct Xoo
+ {
+ Y* v;
+ };
+ X* v;
+ };
+
+
+ void test6(Foo<Boo<Foo<void> > > arg1);
+ void test7(Boo<void>::Xoo<int> arg1);
+};
+
+void Goo::test6(Goo::Foo<Goo::Boo<Goo::Foo<void> > > arg1)
+{
+}
+
+void Goo::test7(Goo::Boo<void>::Xoo<int> arg1)
+{
+}
+
+struct P1
+{
+ template<class T>
+ struct Mem
+ {
+ };
+};
+
+struct P2
+{
+ template<class T>
+ struct Mem
+ {
+ };
+};
+
+void test8(P1::Mem<int>, P2::Mem<int>){}
+void test9(Foo<int**>, Foo<int*>, int**, int*){}
+
+
+
+class Test10
+{
+ private: void test10();
+ public: void test11();
+ protected: void test12();
+ public: void test13() const;
+
+ private: void test14(); // Private methods in D are always non-virtual
+ public: virtual void test15();
+ protected: virtual void test16();
+
+ private: static void test17();
+ public: static void test18();
+ protected: static void test19();
+};
+
+Test10* Test10Ctor()
+{
+ return new Test10();
+}
+
+void Test10Dtor(Test10*& ptr)
+{
+ delete ptr;
+ ptr = 0;
+}
+
+void Test10::test10(){}
+void Test10::test11(){}
+void Test10::test12(){}
+void Test10::test13() const{}
+void Test10::test14(){}
+void Test10::test15(){}
+void Test10::test16(){}
+void Test10::test17(){}
+void Test10::test18(){}
+void Test10::test19(){}
+
+struct Test20
+{
+ private: static int test20;
+ protected: static int test21;
+ public: static int test22;
+};
+
+int Test20::test20 = 20;
+int Test20::test21 = 21;
+int Test20::test22 = 22;
+
+int test23(Test10**, Test10*, Test10***, Test10 const *const)
+{
+ return 1;
+}
+
+int test23b(Test10 const *const *const, Test10 const* const, Test10*)
+{
+ return 1;
+}
+
+void test24(int(*)(int,int))
+{
+}
+
+void test25(int arr[2][5][6][291])
+{
+}
+
+int test26(int arr[5][6][291])
+{
+ return arr[1][1][1];
+}
+
+void test27(int, ...){}
+void test28(int){}
+
+void test29(float){}
+void test30(const float){}
+
+template<class T>
+struct Array
+{
+ int dim;
+};
+
+class Module
+{
+public:
+ static void imports(Module*);
+ static int dim(Array<Module*>*);
+};
+
+
+void Module::imports(Module*)
+{
+}
+
+int Module::dim(Array<Module*>* arr)
+{
+ return arr->dim;
+}
+
+#if _LP64
+unsigned long testlongmangle(int32_t a, uint32_t b, long c, unsigned long d)
+{
+ return a + b + c + d;
+}
+#else
+unsigned long long testlongmangle(int a, unsigned int b, long long c, unsigned long long d)
+{
+ return a + b + c + d;
+}
+#endif
+
+int test31[2][2][2] = {1, 1, 1, 1, 1, 1, 1, 1};
+int *test32 = 0;
+
+
+
+class Expression;
+
+typedef int (*apply_fp_t)(Expression*, void*);
+
+class Expression
+{
+ int type;
+public:
+ int apply(apply_fp_t fp, apply_fp_t fp2, void *param);
+ int getType();
+ static Expression* create(int v);
+ static void dispose(Expression*&);
+};
+
+int Expression::apply(apply_fp_t fp, apply_fp_t fp2, void *param)
+{
+ return fp(this, param) * fp2(this, param);
+}
+
+int Expression::getType()
+{
+ return type;
+}
+
+Expression* Expression::create(int v)
+{
+ Expression *e = new Expression();
+ e->type = v;
+ return e;
+}
+
+void Expression::dispose(Expression *&e)
+{
+ if (e)
+ delete e;
+ e = 0;
+}
+
+/*int test34(int v[0][0][0])
+{
+ return 0;
+}*/
+
+#ifndef _MSC_VER
+ int test35(long double arg)
+ {
+ return (int)arg;
+ }
+#endif
+
+const char *test36(const char *arg)
+{
+ return arg;
+}
+
+class Test37
+{
+public:
+ static Test37 *create();
+ bool test();
+};
+
+bool test37()
+{
+ Test37 *o = Test37::create();
+ return o->test();
+}
+
+class Test38
+{
+public:
+ int test(int, ...);
+ static Test38* create();
+ static void dispose(Test38*&);
+};
+
+int Test38::test(int a, ...)
+{
+ return a;
+}
+
+Test38* Test38::create()
+{
+ Test38 *t = new Test38();
+ return t;
+}
+
+void Test38::dispose(Test38 *&t)
+{
+ if (t)
+ delete t;
+ t = 0;
+}
+
+class S1
+{
+ int val;
+public:
+ static S1* init(int);
+ S1(int v) : val(v) {}
+ int value();
+};
+
+S1* S1::init(int x)
+{
+ return new S1(x);
+}
+
+int S1::value()
+{
+ return val;
+}
+
+template<class T>
+class S2
+{
+ T val;
+public:
+ static S2<T>* init(T);
+ S2(T v) : val(v) {}
+ T value();
+};
+
+template<>
+S2<int>* S2<int>::init(int x)
+{
+ return new S2<int>(x);
+}
+
+template<>
+int S2<int>::value()
+{
+ return val;
+}
+
+struct C1
+{
+ const char *data;
+
+ static C1* init(const char *p);
+
+ C1(const char* p) : data(p) { }
+
+ virtual const char* getDataCPP();
+ virtual const char* getDataD();
+};
+
+C1* C1::init(const char *p)
+{
+ return new C1(p);
+}
+
+const char* C1::getDataCPP()
+{
+ return data;
+}
+
+template<class T>
+struct C2
+{
+ const T *data;
+
+ static C2* init(const T *p);
+
+ C2(const T* p) : data(p) { }
+
+ virtual const T* getData();
+};
+
+template<>
+C2<char>* C2<char>::init(const char *p)
+{
+ return new C2<char>(p);
+}
+
+template<>
+const char* C2<char>::getData()
+{
+ return data;
+}
+
+int test39cpp(C2<char>* c2, S2<int>* s2)
+{
+ C2<char>* otherC2 = C2<char>::init(c2->getData());
+ if (c2->getData() != otherC2->getData())
+ return 1;
+ S2<int>* otherS2 = S2<int>::init(s2->value());
+ if (s2->value() != otherS2->value())
+ return 2;
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+
+struct Test32NS1
+{
+ template<class X>
+ struct Foo
+ {
+ X *v;
+ };
+
+ template<class X>
+ struct Bar
+ {
+ X *v;
+ };
+
+};
+
+struct Test32NS2
+{
+ template<class X>
+ struct Foo
+ {
+ X *v;
+ };
+};
+
+template <template <class X> class Y, template <class X> class Z>
+struct Test32
+{
+ Y<int>* field;
+};
+
+
+void test32a(Test32<Test32NS1::Foo, Test32NS1::Foo> arg)
+{
+}
+
+void test32b(Test32<Test32NS1::Foo, Test32NS1::Bar> arg)
+{
+}
+
+void test32c(Test32<Test32NS1::Foo, Test32NS2::Foo> arg)
+{
+}
+
+void test32d(Test32<Test32NS1::Foo, Test32NS2::Foo> arg1, Test32<Test32NS2::Foo, Test32NS1::Foo> arg2)
+{
+}
+
+
+class XXX
+{
+};
+template <void (&Goo)(XXX*, XXX**), void (&Xoo)(XXX*, XXX**)>
+struct Test33
+{
+};
+
+void test33a(XXX*, XXX**){}
+
+void test33(XXX*, Test33<test33a, test33a> arg, XXX*)
+{
+}
+
+template <void (&Goo)(int)>
+struct Test34
+{
+};
+
+struct Test34A
+{
+ static void foo(int);
+};
+
+void Test34A::foo(int) {}
+void test34(Test34<Test34A::foo> arg)
+{
+}
+
+int test36= 36;
+
+template <int& XREF>
+struct Test37
+{
+};
+
+struct Test37A
+{
+ static int t38;
+};
+
+int Test37A::t38 = 42;
+
+void test37(Test37<test36> arg)
+{
+}
+
+void test38(Test37<Test37A::t38> arg)
+{
+}
+
+struct Test39
+{
+ template <class X>
+ struct T39A
+ {
+ };
+};
+
+struct T39A
+{
+};
+
+void test39(Test39::T39A< ::T39A >)
+{
+}
+
+#if 0 //only for g++ with -std=c++0x and Visual C++ >= 2013
+ #if defined(__GNUG__) || (defined(_MSC_VER) && _MSC_VER >= 1200)
+ template<class... VarArg> struct Test40
+ {
+ };
+
+ void test40(Test40<int, double, void> arg)
+ {
+ }
+ #endif
+
+
+#endif
+
+
+extern XXX const * const test41 = 0;
+
+namespace Test42
+{
+ extern XXX const * const test42 = 0;
+}
+
+int test43[4] = {1, 2, 3, 4};
+
+XXX const* const test44()
+{
+ return new XXX;
+}
--- /dev/null
+# Copyright (C) 2012-2020 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# Runnable C++ tests for the D2 testsuite.
+
+# Load support procs.
+load_lib gdc-dg.exp
+load_lib gdc-utils.exp
+
+# If the D runtime library is missing, bail.
+if { ![check_effective_target_d_runtime] } {
+ return
+}
+
+# We are mixing D and C++ code, need to pull in libstdc++
+global GDC_INCLUDE_CXX_FLAGS
+set GDC_INCLUDE_CXX_FLAGS 1
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+if [check_no_compiler_messages extern_c++_tests assembly {
+ // C++
+ int main() { return 0; }
+}] {
+ gdc-do-test [glob -nocomplain $srcdir/$subdir/*.d]
+}
+
+set GDC_INCLUDE_CXX_FLAGS 0
+
+# All done.
+dg-finish
set options [gdc-permute-options [lsort -unique $PERMUTE_ARGS]]
switch $dir {
+ runnable_cxx -
runnable {
for { set i 0 } { $i<[llength $options] } { incr i } {
set flags [lindex $options $i]
proc gdc_include_flags { paths } {
global srcdir
+ global GDC_INCLUDE_CXX_FLAGS
global TESTING_IN_BUILD_TREE
set flags ""
return "${flags}"
}
+ if [info exists GDC_INCLUDE_CXX_FLAGS] {
+ set include_cxx_flags $GDC_INCLUDE_CXX_FLAGS
+ } else {
+ set include_cxx_flags 0
+ }
+
set gccpath ${paths}
if { $gccpath != "" } {
append flags "-I${srcdir}/../../libphobos/src "
# For the tests that mix C++ and D, need to know where headers are located.
- set odir [lookfor_file ${gccpath} libstdc++-v3]
- if { ${odir} != "" } {
- set cxxflags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
- set idx [lsearch $cxxflags "-nostdinc++"]
- append flags [lreplace $cxxflags $idx $idx]
+ if $include_cxx_flags {
+ set odir [lookfor_file ${gccpath} libstdc++-v3]
+ if { ${odir} != "" && [file exists ${odir}/scripts/testsuite_flags] } {
+ set cxxflags [exec sh ${odir}/scripts/testsuite_flags --build-includes]
+ set idx [lsearch $cxxflags "-nostdinc++"]
+ append flags [lreplace $cxxflags $idx $idx]
+ }
}
return "$flags"
global srcdir
global ld_library_path
global GDC_UNDER_TEST
+ global GDC_INCLUDE_CXX_FLAGS
global shlib_ext
global SHARED_OPTION
set SHARED_OPTION ""
verbose "shared lib extension: $shlib_ext"
+ if [info exists GDC_INCLUDE_CXX_FLAGS] {
+ set include_cxx_flags $GDC_INCLUDE_CXX_FLAGS
+ } else {
+ set include_cxx_flags 0
+ }
+
if { $gccpath != "" } {
# Path to libgphobos.spec.
append flags "-B${gccpath}/libphobos/src "
if [file exists "${gccpath}/libiberty/libiberty.a"] {
append flags "-L${gccpath}/libiberty "
}
- # For the tests that mix C++ and D, we should try and handle this better.
- if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \
- || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
- append flags "-L${gccpath}/libstdc++-v3/src/.libs "
- append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
+ # For the tests that mix C++ and D, need to know where library is located.
+ if $include_cxx_flags {
+ if { [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.a"] \
+ || [file exists "${gccpath}/libstdc++-v3/src/.libs/libstdc++.${shlib_ext}"] } {
+ append flags "-L${gccpath}/libstdc++-v3/src/.libs "
+ append ld_library_path ":${gccpath}/libstdc++-v3/src/.libs"
+ }
}
append ld_library_path [gcc-set-multilib-library-path $GDC_UNDER_TEST]
} else {
if { $libiberty != "" } {
append flags "-L${libiberty} "
}
+ if $include_cxx_flags {
+ set libstdcpp [lookfor_file ${tool_root_dir} libstdc++]
+ if { $libstdcpp != "" } {
+ append flags "-L${libstdcpp} "
+ append ld_library_path ":${libstdcpp}"
+ }
+ }
}
set_ld_library_path_env_vars
#
proc gdc_init { args } {
- global subdir
global gdc_initialized
global base_dir
global tmpdir
global libdir
global gluefile wrap_flags
- global objdir srcdir
- global ALWAYS_DFLAGS
- global TOOL_EXECUTABLE TOOL_OPTIONS
+ global TOOL_EXECUTABLE
global GDC_UNDER_TEST
global TESTING_IN_BUILD_TREE
- global TEST_ALWAYS_FLAGS
global gcc_warning_prefix
global gcc_error_prefix
gdc_maybe_build_wrapper "${tmpdir}/d-testglue.o"
- set ALWAYS_DFLAGS ""
-
- # TEST_ALWAYS_FLAGS are flags that should be passed to every
- # compilation. They are passed first to allow individual
- # tests to override them.
- if [info exists TEST_ALWAYS_FLAGS] {
- lappend ALWAYS_DFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
- }
-
- if ![is_remote host] {
- if [info exists TOOL_OPTIONS] {
- lappend ALWAYS_DFLAGS "additional_flags=[gdc_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
- lappend ALWAYS_DFLAGS "ldflags=[gdc_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
- } else {
- lappend ALWAYS_DFLAGS "additional_flags=[gdc_include_flags [get_multilibs] ]"
- lappend ALWAYS_DFLAGS "ldflags=[gdc_link_flags [get_multilibs] ]"
- }
- }
-
- if [info exists TOOL_OPTIONS] {
- lappend ALWAYS_DFLAGS "additional_flags=$TOOL_OPTIONS"
- }
-
- verbose -log "ALWAYS_DFLAGS set to $ALWAYS_DFLAGS"
-
set gcc_warning_prefix "warning:"
set gcc_error_prefix "(fatal )?error:"
proc gdc_target_compile { source dest type options } {
global tmpdir
global gluefile wrap_flags
- global ALWAYS_DFLAGS
global GDC_UNDER_TEST
+ global TOOL_OPTIONS
+ global TEST_ALWAYS_FLAGS
if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
lappend options "libs=${gluefile}"
lappend options "ldflags=${wrap_flags}"
}
+ set always_dflags ""
+
+ # TEST_ALWAYS_FLAGS are flags that should be passed to every
+ # compilation. They are passed first to allow individual
+ # tests to override them.
+ if [info exists TEST_ALWAYS_FLAGS] {
+ lappend always_dflags "additional_flags=$TEST_ALWAYS_FLAGS"
+ }
+
+ if ![is_remote host] {
+ if [info exists TOOL_OPTIONS] {
+ lappend always_dflags "additional_flags=[gdc_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
+ lappend always_dflags "ldflags=[gdc_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
+ } else {
+ lappend always_dflags "additional_flags=[gdc_include_flags [get_multilibs] ]"
+ lappend always_dflags "ldflags=[gdc_link_flags [get_multilibs] ]"
+ }
+ }
+
+ if [info exists TOOL_OPTIONS] {
+ lappend always_dflags "additional_flags=$TOOL_OPTIONS"
+ }
+
+ verbose "always_dflags set to: $always_dflags"
+
lappend options "timeout=[timeout_value]"
lappend options "compiler=$GDC_UNDER_TEST"
- set options [concat "$ALWAYS_DFLAGS" $options]
+ set options [concat "$always_dflags" $options]
set options [dg-additional-files-options $options $source]
return [target_compile $source $dest $type $options]
}