Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/gdc.test/runnable_cxx/cpp_abi_tests.d @ 152:2b5abeee2509
update gcc11
author | anatofuz |
---|---|
date | Mon, 25 May 2020 07:50:57 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
145:1830386684a0 | 152:2b5abeee2509 |
---|---|
1 // EXTRA_CPP_SOURCES: cpp_abi_tests.cpp | |
2 | |
3 extern(C++) { | |
4 | |
5 struct S | |
6 { | |
7 float a = 1; | |
8 } | |
9 | |
10 bool passthrough(bool value); | |
11 byte passthrough(byte value); | |
12 ubyte passthrough(ubyte value); | |
13 char passthrough(char value); | |
14 dchar passthrough(dchar value); | |
15 short passthrough(short value); | |
16 ushort passthrough(ushort value); | |
17 int passthrough(int value); | |
18 uint passthrough(uint value); | |
19 long passthrough(long value); | |
20 ulong passthrough(ulong value); | |
21 float passthrough(float value); | |
22 double passthrough(double value); | |
23 S passthrough(S value); | |
24 | |
25 bool passthrough_ptr(bool *value); | |
26 byte passthrough_ptr(byte *value); | |
27 ubyte passthrough_ptr(ubyte *value); | |
28 char passthrough_ptr(char *value); | |
29 dchar passthrough_ptr(dchar *value); | |
30 short passthrough_ptr(short *value); | |
31 ushort passthrough_ptr(ushort *value); | |
32 int passthrough_ptr(int *value); | |
33 uint passthrough_ptr(uint *value); | |
34 long passthrough_ptr(long *value); | |
35 ulong passthrough_ptr(ulong *value); | |
36 float passthrough_ptr(float *value); | |
37 double passthrough_ptr(double *value); | |
38 S passthrough_ptr(S *value); | |
39 | |
40 bool passthrough_ref(ref bool value); | |
41 byte passthrough_ref(ref byte value); | |
42 ubyte passthrough_ref(ref ubyte value); | |
43 char passthrough_ref(ref char value); | |
44 dchar passthrough_ref(ref dchar value); | |
45 short passthrough_ref(ref short value); | |
46 ushort passthrough_ref(ref ushort value); | |
47 int passthrough_ref(ref int value); | |
48 uint passthrough_ref(ref uint value); | |
49 long passthrough_ref(ref long value); | |
50 ulong passthrough_ref(ref ulong value); | |
51 float passthrough_ref(ref float value); | |
52 double passthrough_ref(ref double value); | |
53 S passthrough_ref(ref S value); | |
54 } | |
55 | |
56 template IsSigned(T) | |
57 { | |
58 enum IsSigned = is(T==byte) || | |
59 is(T==short) || | |
60 is(T==int) || | |
61 is(T==long); | |
62 } | |
63 | |
64 template IsUnsigned(T) | |
65 { | |
66 enum IsUnsigned = is(T==ubyte) || | |
67 is(T==ushort) || | |
68 is(T==uint) || | |
69 is(T==ulong); | |
70 } | |
71 | |
72 template IsIntegral(T) | |
73 { | |
74 enum IsIntegral = IsSigned!T || IsUnsigned!T; | |
75 } | |
76 | |
77 template IsFloatingPoint(T) | |
78 { | |
79 enum IsFloatingPoint = is(T==float) || is(T==double) || is(T==real); | |
80 } | |
81 | |
82 template IsBoolean(T) | |
83 { | |
84 enum IsBoolean = is(T==bool); | |
85 } | |
86 | |
87 template IsSomeChar(T) | |
88 { | |
89 enum IsSomeChar = is(T==char) || is(T==dchar); | |
90 } | |
91 | |
92 void check(T)(T actual, T expected) | |
93 { | |
94 assert(actual is expected); | |
95 } | |
96 | |
97 void check(T)(T value) | |
98 { | |
99 check(passthrough(value), value); | |
100 check(passthrough_ptr(&value), value); | |
101 check(passthrough_ref(value), value); | |
102 } | |
103 | |
104 T[] values(T)() | |
105 { | |
106 T[] values; | |
107 static if(IsBoolean!T) | |
108 { | |
109 values ~= true; | |
110 values ~= false; | |
111 } | |
112 else static if(IsSomeChar!T) | |
113 { | |
114 values ~= T.init; | |
115 values ~= T('a'); | |
116 values ~= T('z'); | |
117 } | |
118 else | |
119 { | |
120 values ~= T(0); | |
121 values ~= T(1); | |
122 static if(IsIntegral!T) | |
123 { | |
124 static if(IsSigned!T) values ~= T.min; | |
125 values ~= T.max; | |
126 } | |
127 else static if(IsFloatingPoint!T) | |
128 { | |
129 values ~= T.nan; | |
130 values ~= T.min_normal; | |
131 values ~= T.max; | |
132 } | |
133 else | |
134 { | |
135 assert(0); | |
136 } | |
137 } | |
138 return values; | |
139 } | |
140 | |
141 void main() | |
142 { | |
143 foreach(bool val; values!bool()) check(val); | |
144 foreach(byte val; values!byte()) check(val); | |
145 foreach(ubyte val; values!ubyte()) check(val); | |
146 foreach(char val; values!char()) check(val); | |
147 foreach(dchar val; values!dchar()) check(val); | |
148 foreach(short val; values!short()) check(val); | |
149 foreach(ushort val; values!ushort()) check(val); | |
150 foreach(int val; values!int()) check(val); | |
151 foreach(uint val; values!uint()) check(val); | |
152 foreach(long val; values!long()) check(val); | |
153 foreach(ulong val; values!ulong()) check(val); | |
154 foreach(float val; values!float()) check(val); | |
155 foreach(double val; values!double()) check(val); | |
156 check(S()); | |
157 } |