| 1 |
// https://issues.dlang.org/show_bug.cgi?id=21515 |
| 2 |
// EXTRA_CPP_SOURCES: test21515.cpp |
| 3 |
// CXXFLAGS: -std=c++11 |
| 4 |
// DISABLED: win32 win64 |
| 5 |
|
| 6 |
// ABI layout of native complex |
| 7 |
struct _Complex(T) { T re; T im; } |
| 8 |
|
| 9 |
// Special enum definitions. |
| 10 |
version (Posix) |
| 11 |
{ |
| 12 |
align(float.alignof) enum __c_complex_float : _Complex!float; |
| 13 |
align(double.alignof) enum __c_complex_double : _Complex!double; |
| 14 |
align(real.alignof) enum __c_complex_real : _Complex!real; |
| 15 |
} |
| 16 |
else |
| 17 |
{ |
| 18 |
align(float.sizeof * 2) enum __c_complex_float : _Complex!float; |
| 19 |
align(double.sizeof * 2) enum __c_complex_double : _Complex!double; |
| 20 |
align(real.alignof) enum __c_complex_real : _Complex!real; |
| 21 |
} |
| 22 |
alias complex_float = __c_complex_float; |
| 23 |
alias complex_double = __c_complex_double; |
| 24 |
alias complex_real = __c_complex_real; |
| 25 |
|
| 26 |
extern(C) complex_float ccomplexf(); |
| 27 |
extern(C) complex_double ccomplex(); |
| 28 |
extern(C) complex_real ccomplexl(); |
| 29 |
extern(C) void ccomplexf2(complex_float c); |
| 30 |
extern(C) void ccomplex2(complex_double c); |
| 31 |
extern(C) void ccomplexl2(complex_real c); |
| 32 |
|
| 33 |
extern(C++) complex_float cpcomplexf(); |
| 34 |
extern(C++) complex_double cpcomplex(); |
| 35 |
extern(C++) complex_real cpcomplexl(); |
| 36 |
extern(C++) void cpcomplexf(complex_float c); |
| 37 |
extern(C++) void cpcomplex(complex_double c); |
| 38 |
extern(C++) void cpcomplexl(complex_real c); |
| 39 |
|
| 40 |
struct wrap_complexf { complex_float c; alias c this; }; |
| 41 |
struct wrap_complex { complex_double c; alias c this; }; |
| 42 |
struct wrap_complexl { complex_real c; alias c this; }; |
| 43 |
|
| 44 |
extern(C++) wrap_complexf wcomplexf(); |
| 45 |
extern(C++) wrap_complex wcomplex(); |
| 46 |
extern(C++) wrap_complexl wcomplexl(); |
| 47 |
extern(C++) void wcomplexf(wrap_complexf c); |
| 48 |
extern(C++) void wcomplex(wrap_complex c); |
| 49 |
extern(C++) void wcomplexl(wrap_complexl c); |
| 50 |
|
| 51 |
struct soft_complexf { float re; float im; }; |
| 52 |
struct soft_complex { double re; double im; }; |
| 53 |
struct soft_complexl { real re; real im; }; |
| 54 |
|
| 55 |
extern(C++) soft_complexf scomplexf(); |
| 56 |
extern(C++) soft_complex scomplex(); |
| 57 |
extern(C++) soft_complexl scomplexl(); |
| 58 |
extern(C++) void scomplexf(soft_complexf c); |
| 59 |
extern(C++) void scomplex(soft_complex c); |
| 60 |
extern(C++) void scomplexl(soft_complexl c); |
| 61 |
|
| 62 |
int main() |
| 63 |
{ |
| 64 |
auto a1 = ccomplexf(); |
| 65 |
auto b1 = ccomplex(); |
| 66 |
auto c1 = ccomplexl(); |
| 67 |
assert(a1.re == 2 && a1.im == 1); |
| 68 |
assert(b1.re == 2 && b1.im == 1); |
| 69 |
assert(c1.re == 2 && c1.im == 1); |
| 70 |
ccomplexf2(a1); |
| 71 |
ccomplex2(b1); |
| 72 |
ccomplexl2(c1); |
| 73 |
|
| 74 |
auto a2 = cpcomplexf(); |
| 75 |
auto b2 = cpcomplex(); |
| 76 |
auto c2 = cpcomplexl(); |
| 77 |
assert(a2.re == 2 && a2.im == 1); |
| 78 |
assert(b2.re == 2 && b2.im == 1); |
| 79 |
assert(c2.re == 2 && c2.im == 1); |
| 80 |
cpcomplexf(a2); |
| 81 |
cpcomplex(b2); |
| 82 |
cpcomplexl(c2); |
| 83 |
|
| 84 |
auto a3 = wcomplexf(); |
| 85 |
auto b3 = wcomplex(); |
| 86 |
auto c3 = wcomplexl(); |
| 87 |
assert(a3.re == 2 && a3.im == 1); |
| 88 |
assert(b3.re == 2 && b3.im == 1); |
| 89 |
assert(c3.re == 2 && c3.im == 1); |
| 90 |
wcomplexf(a3); |
| 91 |
wcomplex(b3); |
| 92 |
wcomplexl(c3); |
| 93 |
|
| 94 |
auto a4 = scomplexf(); |
| 95 |
auto b4 = scomplex(); |
| 96 |
auto c4 = scomplexl(); |
| 97 |
assert(a4.re == 2 && a4.im == 1); |
| 98 |
assert(b4.re == 2 && b4.im == 1); |
| 99 |
assert(c4.re == 2 && c4.im == 1); |
| 100 |
scomplexf(a4); |
| 101 |
scomplex(b4); |
| 102 |
scomplexl(c4); |
| 103 |
|
| 104 |
return 0; |
| 105 |
} |