8 extern(C
) int printf(const char*, ...);
26 int dotype(char x
) { return T_char
; }
27 int dotype(bool x
) { return T_bit
; }
28 int dotype(byte x
) { return T_byte
; }
29 int dotype(ubyte x
) { return T_ubyte
; }
30 int dotype(wchar x
) { return T_wchar
; }
31 int dotype(short x
) { return T_short
; }
32 int dotype(ushort x
) { return T_ushort
; }
33 int dotype(int x
) { return T_int
; }
34 int dotype(uint x
) { return T_uint
; }
35 int dotype(long x
) { return T_long
; }
36 int dotype(ulong x
) { return T_ulong
; }
42 * 0x8000 0100000 32768
43 * 0xFFFF 0177777 65535
44 * 0x10000 0200000 65536
45 * 0x7FFFFFFF 017777777777 2147483647
46 * 0x80000000 020000000000 2147483648
47 * 0xFFFFFFFF 037777777777 4294967295
48 * 0x100000000 040000000000 4294967296
49 * 0x7FFFFFFFFFFFFFFF 0777777777777777777777 9223372036854775807
50 * 0x8000000000000000 01000000000000000000000 9223372036854775808
51 * 0xFFFFFFFFFFFFFFFF 01777777777777777777777 18446744073709551615
54 assert(dotype(1) == T_int
);
56 /***************** Hexadecimal ***********************/
58 assert(dotype(0) == T_int
);
59 assert(dotype(0x7FFF) == T_int
);
60 assert(dotype(0x8000) == T_int
);
61 assert(dotype(0xFFFF) == T_int
);
62 assert(dotype(0x10000) == T_int
);
63 assert(dotype(0x7FFFFFFF) == T_int
);
64 assert(dotype(0x80000000) == T_uint
);
65 assert(dotype(0xFFFFFFFF) == T_uint
);
66 assert(dotype(0x100000000) == T_long
);
67 assert(dotype(0x7FFFFFFFFFFFFFFF) == T_long
);
68 assert(dotype(0x8000000000000000) == T_ulong
);
69 assert(dotype(0xFFFFFFFFFFFFFFFF) == T_ulong
);
71 assert(dotype(0u) == T_uint
);
72 assert(dotype(0x7FFFu
) == T_uint
);
73 assert(dotype(0x8000u
) == T_uint
);
74 assert(dotype(0xFFFFu
) == T_uint
);
75 assert(dotype(0x10000u
) == T_uint
);
76 assert(dotype(0x7FFFFFFFu
) == T_uint
);
77 assert(dotype(0x80000000u
) == T_uint
);
78 assert(dotype(0xFFFFFFFFu
) == T_uint
);
79 assert(dotype(0x100000000u
) == T_ulong
);
80 assert(dotype(0x7FFFFFFFFFFFFFFFu
) == T_ulong
);
81 assert(dotype(0x8000000000000000u
) == T_ulong
);
82 assert(dotype(0xFFFFFFFFFFFFFFFFu
) == T_ulong
);
84 assert(dotype(0L) == T_long
);
85 assert(dotype(0x7FFFL
) == T_long
);
86 assert(dotype(0x8000L
) == T_long
);
87 assert(dotype(0xFFFFL
) == T_long
);
88 assert(dotype(0x10000L
) == T_long
);
89 assert(dotype(0x7FFFFFFFL
) == T_long
);
90 assert(dotype(0x80000000L
) == T_long
);
91 assert(dotype(0xFFFFFFFFL
) == T_long
);
92 assert(dotype(0x100000000L
) == T_long
);
93 assert(dotype(0x7FFFFFFFFFFFFFFFL
) == T_long
);
94 assert(dotype(0x8000000000000000L
) == T_ulong
);
95 assert(dotype(0xFFFFFFFFFFFFFFFFL
) == T_ulong
);
97 assert(dotype(0uL) == T_ulong
);
98 assert(dotype(0x7FFFuL
) == T_ulong
);
99 assert(dotype(0x8000uL
) == T_ulong
);
100 assert(dotype(0xFFFFuL
) == T_ulong
);
101 assert(dotype(0x10000uL
) == T_ulong
);
102 assert(dotype(0x7FFFFFFFuL
) == T_ulong
);
103 assert(dotype(0x80000000uL
) == T_ulong
);
104 assert(dotype(0xFFFFFFFFuL
) == T_ulong
);
105 assert(dotype(0x100000000uL
) == T_ulong
);
106 assert(dotype(0x7FFFFFFFFFFFFFFFuL
) == T_ulong
);
107 assert(dotype(0x8000000000000000uL
) == T_ulong
);
108 assert(dotype(0xFFFFFFFFFFFFFFFFuL
) == T_ulong
);
110 /***************** Decimal ***********************/
112 assert(dotype(0) == T_int
);
113 assert(dotype(32767) == T_int
);
114 assert(dotype(32768) == T_int
);
115 assert(dotype(65535) == T_int
);
116 assert(dotype(65536) == T_int
);
117 assert(dotype(2147483647) == T_int
);
118 assert(dotype(2147483648) == T_long
);
119 assert(dotype(4294967295) == T_long
);
120 assert(dotype(4294967296) == T_long
);
121 assert(dotype(9223372036854775807) == T_long
);
122 //assert(dotype(9223372036854775808) == T_long);
123 //assert(dotype(18446744073709551615) == T_ulong);
125 assert(dotype(0u) == T_uint
);
126 assert(dotype(32767u) == T_uint
);
127 assert(dotype(32768u) == T_uint
);
128 assert(dotype(65535u) == T_uint
);
129 assert(dotype(65536u) == T_uint
);
130 assert(dotype(2147483647u) == T_uint
);
131 assert(dotype(2147483648u) == T_uint
);
132 assert(dotype(4294967295u) == T_uint
);
133 assert(dotype(4294967296u) == T_ulong
);
134 assert(dotype(9223372036854775807u) == T_ulong
);
135 assert(dotype(9223372036854775808u) == T_ulong
);
136 assert(dotype(18446744073709551615u) == T_ulong
);
138 assert(dotype(0L) == T_long
);
139 assert(dotype(32767L) == T_long
);
140 assert(dotype(32768L) == T_long
);
141 assert(dotype(65535L) == T_long
);
142 assert(dotype(65536L) == T_long
);
143 assert(dotype(2147483647L) == T_long
);
144 assert(dotype(2147483648L) == T_long
);
145 assert(dotype(4294967295L) == T_long
);
146 assert(dotype(4294967296L) == T_long
);
147 assert(dotype(9223372036854775807L) == T_long
);
148 //assert(dotype(9223372036854775808L) == T_ulong);
149 //assert(dotype(18446744073709551615L) == T_ulong);
151 assert(dotype(0uL) == T_ulong
);
152 assert(dotype(32767uL) == T_ulong
);
153 assert(dotype(32768uL) == T_ulong
);
154 assert(dotype(65535uL) == T_ulong
);
155 assert(dotype(65536uL) == T_ulong
);
156 assert(dotype(2147483647uL) == T_ulong
);
157 assert(dotype(2147483648uL) == T_ulong
);
158 assert(dotype(4294967295uL) == T_ulong
);
159 assert(dotype(4294967296uL) == T_ulong
);
160 assert(dotype(9223372036854775807uL) == T_ulong
);
161 assert(dotype(9223372036854775808uL) == T_ulong
);
162 assert(dotype(18446744073709551615uL) == T_ulong
);
167 ulong[] a
= [ 2_463_534_242UL ];
170 assert(e
== 2_463_534_242UL);
173 /***************************************************/
174 // https://issues.dlang.org/show_bug.cgi?id=13907
176 void f13907_1(wchar[1] a
) {}
177 void f13907_2(wchar[2] a
) {}
178 void f13907_3(wchar[3] a
) {}
180 auto f13907_12(char[1]) { return 1; }
181 auto f13907_12(char[2]) { return 2; }
183 auto f13907_123(char[1]) { return 1; }
184 auto f13907_123(char[2]) { return 2; }
185 auto f13907_123(char[3]) { return 3; }
186 auto f13907_123(const(char)[]) { return 0; }
190 static assert(!__traits(compiles
, { f13907_1("\U00010000"w
); }));
191 static assert(!__traits(compiles
, { f13907_1("\U00010000" ); }));
192 f13907_2("\U00010000"w
);
193 f13907_2("\U00010000");
194 f13907_3("\U00010000"w
); // Re-enable implicit length extension, from https://issues.dlang.org/show_bug.cgi?id=13999
195 f13907_3("\U00010000" ); // Re-enable implicit length extension, from https://issues.dlang.org/show_bug.cgi?id=13999
197 assert(f13907_12("a") == 1);
198 assert(f13907_12("ab") == 2);
199 static assert(!__traits(compiles
, { f13907_12("abc"); }));
201 assert(f13907_123("a") == 1);
202 assert(f13907_123("ab") == 2);
203 assert(f13907_123("abc") == 3);
204 assert(f13907_123("abcd") == 0);
206 // regression tests for the lengthen behavior in initializer
207 enum const(char*) p
= "hello world";
208 static assert(!__traits(compiles
, { static char[5] a
= "hello world"; })); // truncation is not allowed
209 static assert(!__traits(compiles
, { static void[20] a
= "hello world"; }));
210 static assert(!__traits(compiles
, { static int[20] a
= "hello world"; }));
211 static assert(!__traits(compiles
, { static char[20] a
= "hello world"w
; }));
212 static assert(!__traits(compiles
, { static wchar[20] a
= "hello world"d
; }));
213 static assert(!__traits(compiles
, { static dchar[20] a
= "hello world"c
; }));
214 static assert(!__traits(compiles
, { static char[20] a
= p
; }));
215 static char[20] csa
= "hello world"; // extending is allowed
216 static wchar[20] wsa
= "hello world"; // ok
217 static dchar[20] dsa
= "hello world"; // ok
219 // https://issues.dlang.org/show_bug.cgi?id=13966
222 enum immutable(char[5]) sarrstr
= "class";
225 // https://issues.dlang.org/show_bug.cgi?id=13999
226 string
[dchar[2]] aa13999
= ["あ": "bar"];
227 assert(aa13999
["あ"] == "bar");
228 dchar[2] key13999
= "あ";
229 assert(key13999
[0] == 'あ');
230 assert(key13999
[1] == '\0');
231 assert(aa13999
[key13999
] == "bar");
234 ulong op12950(ulong v
){return v
+ 12950;}
238 assert(0x00_00_00_01.op12950() == 12951);
239 assert(0x00_00_00_01UL.op12950() == 12951);
240 assert(0b00_00_00_01.op12950() == 12951);
241 assert(0b00_00_00_01UL.op12950() == 12951);
246 static immutable uint[] x
= cast(immutable uint[]) x
"FFAADDEE";
247 static assert(x
[0] == 0xFFAADDEE);
248 assert(x
[0] == 0xFFAADDEE);
250 static immutable ulong[] y
= cast(immutable ulong[]) x
"1122334455667788AABBCCDDEEFF0099";
251 static assert(y
[0] == 0x1122334455667788);
252 static assert(y
[1] == 0xAABBCCDDEEFF0099);
253 assert(y
[0] == 0x1122334455667788);
254 assert(y
[1] == 0xAABBCCDDEEFF0099);
256 // Test that mangling of StringExp with size 8 is the same as array literal mangling:
257 void f(immutable ulong[] a
)() {}
258 static assert(f
!y
.mangleof
== f
!([0x1122334455667788, 0xAABBCCDDEEFF0099]).mangleof
);
260 // Test printing StringExp with size 8
261 enum toStr(immutable ulong[] v
) = v
.stringof
;
262 static assert(toStr
!y
== `x"88776655443322119900FFEEDDCCBBAA"`);
265 /***************************************************/