| 1 |
module test34; |
| 2 |
|
| 3 |
import core.exception; |
| 4 |
import core.stdc.stdio; |
| 5 |
import core.vararg; |
| 6 |
|
| 7 |
/************************************************/ |
| 8 |
|
| 9 |
class Foo {} |
| 10 |
class Bar {} |
| 11 |
|
| 12 |
void test1() |
| 13 |
{ |
| 14 |
TypeInfo ti_foo = typeid(Foo); |
| 15 |
TypeInfo ti_bar = typeid(Bar); |
| 16 |
|
| 17 |
auto hfoo = ti_foo.toHash(); |
| 18 |
auto hbar = ti_bar.toHash(); |
| 19 |
assert(hfoo != hbar); |
| 20 |
|
| 21 |
auto e = (ti_foo == ti_bar); |
| 22 |
assert(!e); |
| 23 |
|
| 24 |
auto c = (ti_foo.opCmp(ti_bar) == 0); |
| 25 |
assert(!c); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
/************************************************/ |
| 30 |
|
| 31 |
void test2() |
| 32 |
{ |
| 33 |
assert( [2,3]!=[2,4] ); |
| 34 |
assert( [3,2]!=[4,2] ); |
| 35 |
assert( !([2,3]==[2,4]) ); |
| 36 |
assert( ([2,3]==[2,3]) ); |
| 37 |
} |
| 38 |
|
| 39 |
/************************************************/ |
| 40 |
|
| 41 |
struct Struct |
| 42 |
{ |
| 43 |
int langID; |
| 44 |
long _force_nrvo; |
| 45 |
} |
| 46 |
|
| 47 |
Struct[1] table; |
| 48 |
|
| 49 |
Struct getfirst() |
| 50 |
{ |
| 51 |
foreach(v; table) { |
| 52 |
assert(v.langID == 1); |
| 53 |
return v; |
| 54 |
} |
| 55 |
assert(0); |
| 56 |
} |
| 57 |
|
| 58 |
Struct getsecond() |
| 59 |
{ |
| 60 |
foreach(ref v; table) { |
| 61 |
assert(v.langID == 1); |
| 62 |
return v; |
| 63 |
} |
| 64 |
assert(0); |
| 65 |
} |
| 66 |
|
| 67 |
void test3() |
| 68 |
{ |
| 69 |
table[0].langID = 1; |
| 70 |
|
| 71 |
auto v = getfirst(); |
| 72 |
assert(v.langID == 1); |
| 73 |
|
| 74 |
v = getsecond(); |
| 75 |
assert(v.langID == 1); |
| 76 |
} |
| 77 |
|
| 78 |
/************************************************/ |
| 79 |
|
| 80 |
class ExOuter |
| 81 |
{ |
| 82 |
class ExInner |
| 83 |
{ |
| 84 |
this() |
| 85 |
{ |
| 86 |
typeof(this.outer) X; |
| 87 |
static assert(is(typeof(X) == ExOuter)); |
| 88 |
} |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
void test4() |
| 93 |
{ |
| 94 |
} |
| 95 |
|
| 96 |
/************************************************/ |
| 97 |
|
| 98 |
int status5; |
| 99 |
|
| 100 |
struct MyStruct5 |
| 101 |
{ |
| 102 |
} |
| 103 |
|
| 104 |
void rec5(int i, MyStruct5 s) |
| 105 |
{ |
| 106 |
if( i > 0 ) |
| 107 |
{ |
| 108 |
status5++; |
| 109 |
rec5(i-1, s); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
void test5() |
| 114 |
{ |
| 115 |
assert(status5==0); |
| 116 |
MyStruct5 st; |
| 117 |
rec5(1030, st); |
| 118 |
assert(status5==1030); |
| 119 |
} |
| 120 |
|
| 121 |
/************************************************/ |
| 122 |
|
| 123 |
class C6 |
| 124 |
{ |
| 125 |
const int a; |
| 126 |
|
| 127 |
this() |
| 128 |
{ |
| 129 |
a = 3; |
| 130 |
} |
| 131 |
|
| 132 |
this(int x) |
| 133 |
{ |
| 134 |
this(); |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
void test6() |
| 139 |
{ |
| 140 |
} |
| 141 |
|
| 142 |
/************************************************/ |
| 143 |
|
| 144 |
template parseUinteger(string s) |
| 145 |
{ |
| 146 |
static if (s.length == 0) |
| 147 |
{ const char[] value = ""; |
| 148 |
const char[] rest = ""; |
| 149 |
} |
| 150 |
else static if (s[0] >= '0' && s[0] <= '9') |
| 151 |
{ const char[] value = s[0] ~ parseUinteger!(s[1..$]).value; |
| 152 |
const char[] rest = parseUinteger!(s[1..$]).rest; |
| 153 |
} |
| 154 |
else |
| 155 |
{ const char[] value = ""; |
| 156 |
const char[] rest = s; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
template parseInteger(string s) |
| 161 |
{ |
| 162 |
static if (s.length == 0) |
| 163 |
{ const char[] value = ""; |
| 164 |
const char[] rest = ""; |
| 165 |
} |
| 166 |
else static if (s[0] >= '0' && s[0] <= '9') |
| 167 |
{ const char[] value = s[0] ~ parseUinteger!(s[1..$]).value; |
| 168 |
const char[] rest = parseUinteger!(s[1..$]).rest; |
| 169 |
} |
| 170 |
else static if (s.length >= 2 && |
| 171 |
s[0] == '-' && s[1] >= '0' && s[1] <= '9') |
| 172 |
{ const char[] value = s[0..2] ~ parseUinteger!(s[2..$]).value; |
| 173 |
const char[] rest = parseUinteger!(s[2..$]).rest; |
| 174 |
} |
| 175 |
else |
| 176 |
{ const char[] value = ""; |
| 177 |
const char[] rest = s; |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
void test7() |
| 182 |
{ |
| 183 |
assert(parseUinteger!("1234abc").value == "1234"); |
| 184 |
assert(parseUinteger!("1234abc").rest == "abc"); |
| 185 |
assert(parseInteger!("-1234abc").value == "-1234"); |
| 186 |
assert(parseInteger!("-1234abc").rest == "abc"); |
| 187 |
} |
| 188 |
|
| 189 |
/************************************************/ |
| 190 |
|
| 191 |
struct Foo8 { } |
| 192 |
|
| 193 |
enum Enum { RED } |
| 194 |
|
| 195 |
//typedef int myint; |
| 196 |
|
| 197 |
alias int myalias; |
| 198 |
|
| 199 |
void test8() |
| 200 |
{ |
| 201 |
/+ |
| 202 |
assert((1+2).stringof == "1 + 2"); |
| 203 |
assert(Foo8.stringof == "Foo8"); |
| 204 |
assert(test.Foo8.stringof == "test.Foo8"); |
| 205 |
assert(int.stringof == "int"); |
| 206 |
assert((int*[5][]).stringof == "int*[5][]"); |
| 207 |
assert(Enum.RED.stringof == "Enum.RED"); |
| 208 |
assert(test.myint.stringof == "test.myint"); |
| 209 |
assert(myalias.stringof == "myalias"); |
| 210 |
assert((5).stringof == "5"); |
| 211 |
assert(typeof(5).stringof == "typeof(5)"); |
| 212 |
+/ |
| 213 |
} |
| 214 |
|
| 215 |
/************************************************/ |
| 216 |
|
| 217 |
/+ |
| 218 |
class Base9 { |
| 219 |
public void fnc(){ |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
class Foo9 : Base9 { |
| 224 |
alias Base9.fnc fnc; |
| 225 |
public void fnc(){ |
| 226 |
} |
| 227 |
static this(){ |
| 228 |
alias void function() T; |
| 229 |
T ptr = & fnc; |
| 230 |
} |
| 231 |
} |
| 232 |
+/ |
| 233 |
|
| 234 |
void test9() |
| 235 |
{ |
| 236 |
} |
| 237 |
|
| 238 |
/************************************************/ |
| 239 |
|
| 240 |
bool isalnum(dchar c) { return c>='0' && c >= '9'; } |
| 241 |
|
| 242 |
char[] toHtmlFilename(char[] fname) |
| 243 |
{ |
| 244 |
foreach (ref c; fname) |
| 245 |
{ |
| 246 |
if (!isalnum(c) && c != '.' && c != '-') |
| 247 |
c = '_'; |
| 248 |
} |
| 249 |
return fname; |
| 250 |
} |
| 251 |
|
| 252 |
void test10() |
| 253 |
{ |
| 254 |
} |
| 255 |
|
| 256 |
/************************************************/ |
| 257 |
|
| 258 |
class A34 { } |
| 259 |
class B34 : A34 { } |
| 260 |
|
| 261 |
void test11() |
| 262 |
{ |
| 263 |
A34 test=new B34; |
| 264 |
assert(test.toString == "test34.B34"); |
| 265 |
A34 test_2=cast(A34)(new B34); |
| 266 |
assert(test_2.toString == "test34.B34"); |
| 267 |
} |
| 268 |
|
| 269 |
/************************************************/ |
| 270 |
|
| 271 |
template Foo12(T: T[U], U) |
| 272 |
{ |
| 273 |
alias int Foo12; |
| 274 |
} |
| 275 |
|
| 276 |
void test12() |
| 277 |
{ |
| 278 |
Foo12!(int[long]) x; |
| 279 |
assert(is(typeof(x) == int)); |
| 280 |
} |
| 281 |
|
| 282 |
/************************************************/ |
| 283 |
|
| 284 |
class C13 |
| 285 |
{ |
| 286 |
int a = 4; |
| 287 |
this() |
| 288 |
{ |
| 289 |
printf("C13.this()\n"); |
| 290 |
assert(a == 4); |
| 291 |
a = 5; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
void test13() |
| 296 |
{ |
| 297 |
C13 c = cast(C13)Object.factory("test34.C13"); |
| 298 |
assert(c.a == 5); |
| 299 |
Object o = Object.factory("test35.C13"); |
| 300 |
assert(o is null); |
| 301 |
} |
| 302 |
|
| 303 |
/************************************************/ |
| 304 |
|
| 305 |
class Base15 { |
| 306 |
int func(int a) { return 1; } |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
class Foo15 : Base15 { |
| 311 |
alias Base15.func func; |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
class Bar15 : Foo15 { |
| 316 |
alias Foo15.func func; |
| 317 |
int func(string a) { return 2; } |
| 318 |
} |
| 319 |
|
| 320 |
void test15() |
| 321 |
{ |
| 322 |
Bar15 b = new Bar15(); |
| 323 |
assert(b.func("hello") == 2); |
| 324 |
assert(b.func(5) == 1); |
| 325 |
} |
| 326 |
|
| 327 |
/************************************************/ |
| 328 |
|
| 329 |
struct Basic16(T, U) {} |
| 330 |
|
| 331 |
struct Iterator16(T : Basic16!(T, U), U) |
| 332 |
{ |
| 333 |
static void Foo() |
| 334 |
{ |
| 335 |
assert(is(T == int)); |
| 336 |
assert(is(U == float)); |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
void test16() |
| 341 |
{ |
| 342 |
Iterator16!(Basic16!(int, float)).Foo(); |
| 343 |
} |
| 344 |
|
| 345 |
/************************************************/ |
| 346 |
|
| 347 |
struct S17(T) |
| 348 |
{ |
| 349 |
struct iterator {} |
| 350 |
} |
| 351 |
|
| 352 |
int insert17(T) (S17!(T) lst, S17!(T).iterator i) |
| 353 |
{ |
| 354 |
return 3; |
| 355 |
} |
| 356 |
|
| 357 |
void test17() |
| 358 |
{ |
| 359 |
S17!(int) a; |
| 360 |
S17!(int).iterator i; |
| 361 |
auto x = insert17(a, i); |
| 362 |
assert(x == 3); |
| 363 |
} |
| 364 |
|
| 365 |
/************************************************/ |
| 366 |
|
| 367 |
void test18() |
| 368 |
{ |
| 369 |
real t = 0.; |
| 370 |
for(int i=0; i<10; i++) |
| 371 |
{ |
| 372 |
t += 1.; |
| 373 |
real r = (2*t); |
| 374 |
printf("%Lg %Lg %Lg\n", t, r, 2*t); |
| 375 |
assert(2*t == (i+1)*2); |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
/************************************************/ |
| 380 |
|
| 381 |
void test19() |
| 382 |
{ |
| 383 |
char c = '3'; |
| 384 |
void[] ca = cast(void[])[c]; |
| 385 |
char[] x = cast(char[])ca; |
| 386 |
assert(x[0] == '3'); |
| 387 |
} |
| 388 |
|
| 389 |
/************************************************/ |
| 390 |
|
| 391 |
enum type20 |
| 392 |
{ |
| 393 |
a, |
| 394 |
b, |
| 395 |
} |
| 396 |
|
| 397 |
class myclass20 |
| 398 |
{ |
| 399 |
template XX(uint a, uint c) |
| 400 |
{ |
| 401 |
static uint XX(){ return (a*256+c);} |
| 402 |
} |
| 403 |
void testcase() |
| 404 |
{ |
| 405 |
switch (cast(uint)type20.a) |
| 406 |
{ |
| 407 |
case XX!(cast(uint)type20.a,cast(uint)type20.b)(): |
| 408 |
break; |
| 409 |
default: assert(0); |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
void test20() |
| 415 |
{ |
| 416 |
} |
| 417 |
|
| 418 |
/************************************************/ |
| 419 |
|
| 420 |
struct S21 |
| 421 |
{ |
| 422 |
alias int Foo; |
| 423 |
int x; |
| 424 |
} |
| 425 |
|
| 426 |
void test21() |
| 427 |
{ |
| 428 |
S21 s; |
| 429 |
typeof(s).Foo j; |
| 430 |
assert(is(typeof(j) == int)); |
| 431 |
} |
| 432 |
|
| 433 |
/************************************************/ |
| 434 |
|
| 435 |
void test22() |
| 436 |
{ |
| 437 |
auto i = 3, j = 4; |
| 438 |
assert(is(typeof(i) == int)); |
| 439 |
assert(is(typeof(j) == int)); |
| 440 |
} |
| 441 |
|
| 442 |
/************************************************/ |
| 443 |
|
| 444 |
static m23 = 5, n23 = 6; |
| 445 |
|
| 446 |
void test23() |
| 447 |
{ |
| 448 |
auto i = 3, j = 4; |
| 449 |
assert(is(typeof(i) == int)); |
| 450 |
assert(is(typeof(j) == int)); |
| 451 |
assert(is(typeof(m23) == int)); |
| 452 |
assert(is(typeof(n23) == int)); |
| 453 |
} |
| 454 |
|
| 455 |
/************************************************/ |
| 456 |
|
| 457 |
const int a24 = 0; |
| 458 |
const int foo24 = 4; |
| 459 |
const int[1] bar24 = [foo24 * 2]; |
| 460 |
const int zap24 = (1 << bar24[a24]); |
| 461 |
|
| 462 |
void test24() |
| 463 |
{ |
| 464 |
assert(zap24 == 256); |
| 465 |
} |
| 466 |
|
| 467 |
/************************************************/ |
| 468 |
|
| 469 |
struct List25(T) { } |
| 470 |
struct CircularQueue25(T) { } |
| 471 |
|
| 472 |
void front25(T)(ref List25!(T) list) { } |
| 473 |
void front25(T)(ref CircularQueue25!(T) queue) { } |
| 474 |
|
| 475 |
void test25() |
| 476 |
{ |
| 477 |
List25!(int) x; |
| 478 |
front25(x); |
| 479 |
} |
| 480 |
|
| 481 |
/************************************************/ |
| 482 |
|
| 483 |
struct Foo26 |
| 484 |
{ |
| 485 |
const string x; |
| 486 |
} |
| 487 |
|
| 488 |
static Foo26 foo26 = {"something"}; |
| 489 |
|
| 490 |
void test26() |
| 491 |
{ |
| 492 |
assert(foo26.x == "something"); |
| 493 |
} |
| 494 |
|
| 495 |
/************************************************/ |
| 496 |
|
| 497 |
template Mang(alias F) |
| 498 |
{ |
| 499 |
class G { } |
| 500 |
alias void function (G ) H; |
| 501 |
const string mangledname = H.mangleof; |
| 502 |
} |
| 503 |
|
| 504 |
template moo(alias A) |
| 505 |
{ |
| 506 |
const string a = Mang!(A).mangledname; |
| 507 |
static assert(Mang!(A).mangledname == a); // FAILS !!! |
| 508 |
} |
| 509 |
|
| 510 |
void test27() |
| 511 |
{ |
| 512 |
int q; |
| 513 |
string b = moo!(q).a; |
| 514 |
} |
| 515 |
|
| 516 |
/************************************************/ |
| 517 |
|
| 518 |
struct Color |
| 519 |
{ |
| 520 |
static void fromRgb(uint rgb) |
| 521 |
{ |
| 522 |
} |
| 523 |
|
| 524 |
static void fromRgb(ubyte alpha, uint rgb) |
| 525 |
{ |
| 526 |
} |
| 527 |
} |
| 528 |
|
| 529 |
void test28() |
| 530 |
{ |
| 531 |
Color.fromRgb(0); |
| 532 |
Color.fromRgb(cast(uint)0); |
| 533 |
} |
| 534 |
|
| 535 |
/************************************************/ |
| 536 |
|
| 537 |
void test29() |
| 538 |
{ |
| 539 |
const char[] t="abcd"; |
| 540 |
const ubyte[] t2=cast(ubyte[])t; |
| 541 |
const char[] t3=['a','b','c','d']; |
| 542 |
const ubyte[] t4=cast(ubyte[])t3; |
| 543 |
assert(t4[1] == 'b'); |
| 544 |
} |
| 545 |
|
| 546 |
/************************************************/ |
| 547 |
|
| 548 |
void test30() |
| 549 |
{ |
| 550 |
const char[] test = "" ~ 'a' ~ 'b' ~ 'c'; |
| 551 |
char[] test2 = (cast(char[])null)~'a'~'b'~'c'; |
| 552 |
const char[] test3 = (cast(char[])null)~'a'~'b'~'c'; |
| 553 |
char[] test4 = (cast(char[])[])~'a'~'b'~'c'; |
| 554 |
const char[] test5 = (cast(char[])[])~'a'~'b'~'c'; |
| 555 |
const char[] test6 = null; |
| 556 |
const char[] test7 = test6~'a'~'b'~'c'; |
| 557 |
} |
| 558 |
|
| 559 |
/************************************************/ |
| 560 |
|
| 561 |
class C31 |
| 562 |
{ |
| 563 |
synchronized invariant() { int x; } |
| 564 |
} |
| 565 |
|
| 566 |
void test31() |
| 567 |
{ |
| 568 |
} |
| 569 |
|
| 570 |
/************************************************/ |
| 571 |
|
| 572 |
ulong foo32() |
| 573 |
{ |
| 574 |
return cast(ulong) (cast(ulong) 1176576512 + cast(float) -2); |
| 575 |
} |
| 576 |
|
| 577 |
void test32() |
| 578 |
{ |
| 579 |
assert(foo32()==1176576510); |
| 580 |
} |
| 581 |
|
| 582 |
/************************************************/ |
| 583 |
|
| 584 |
class RangeCoder |
| 585 |
{ |
| 586 |
uint[258] cumCount; // 256 + end + total |
| 587 |
uint lower; |
| 588 |
uint upper; |
| 589 |
ulong range; |
| 590 |
|
| 591 |
this() { |
| 592 |
for (int i=0; i<cumCount.length; i++) |
| 593 |
cumCount[i] = i; |
| 594 |
lower = 0; |
| 595 |
upper = 0xffffffff; |
| 596 |
range = 0x100000000; |
| 597 |
} |
| 598 |
|
| 599 |
void encode(uint symbol) { |
| 600 |
uint total = cumCount[$ - 1]; |
| 601 |
// "Error: Access Violation" in following line |
| 602 |
upper = lower + cast(uint)((cumCount[symbol+1] * range) / total) - 1; |
| 603 |
lower = lower + cast(uint)((cumCount[symbol] * range) / total); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
void test33() |
| 608 |
{ |
| 609 |
RangeCoder rc = new RangeCoder(); |
| 610 |
rc.encode(77); |
| 611 |
} |
| 612 |
|
| 613 |
/************************************************/ |
| 614 |
|
| 615 |
struct Vector34 |
| 616 |
{ |
| 617 |
float x, y, z; |
| 618 |
|
| 619 |
public static Vector34 opCall(float x = 0, float y = 0, float z = 0) |
| 620 |
{ |
| 621 |
Vector34 v; |
| 622 |
|
| 623 |
v.x = x; |
| 624 |
v.y = y; |
| 625 |
v.z = z; |
| 626 |
|
| 627 |
return v; |
| 628 |
} |
| 629 |
|
| 630 |
public string toString() |
| 631 |
{ |
| 632 |
return formatImpl("<%f, %f, %f>", x, y, z); |
| 633 |
} |
| 634 |
|
| 635 |
private static string formatImpl(string fmt, ...) |
| 636 |
{ |
| 637 |
string ret = "<"; |
| 638 |
bool comma; |
| 639 |
foreach (arg; _arguments) |
| 640 |
{ |
| 641 |
assert(arg is typeid(float)); |
| 642 |
if (comma) |
| 643 |
ret ~= ", "; |
| 644 |
auto f = va_arg!float(_argptr); |
| 645 |
if (f == 1) |
| 646 |
ret ~= "1.000000"; |
| 647 |
else if (f == 0) |
| 648 |
ret ~= "0.000000"; |
| 649 |
else |
| 650 |
assert(0); |
| 651 |
comma = true; |
| 652 |
} |
| 653 |
ret ~= ">"; |
| 654 |
return ret; |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
string format34(string fmt, ...) |
| 659 |
{ |
| 660 |
assert(_arguments[0] is typeid(Vector34)); |
| 661 |
auto arg = va_arg!Vector34(_argptr); |
| 662 |
return arg.toString(); |
| 663 |
} |
| 664 |
|
| 665 |
class Foo34 |
| 666 |
{ |
| 667 |
private Vector34 v; |
| 668 |
|
| 669 |
public this() |
| 670 |
{ |
| 671 |
v = Vector34(1, 0, 0); |
| 672 |
} |
| 673 |
|
| 674 |
public void foo() |
| 675 |
{ |
| 676 |
bar(); |
| 677 |
} |
| 678 |
|
| 679 |
private void bar() |
| 680 |
{ |
| 681 |
auto s = foobar(); |
| 682 |
assert(format34("%s", s) == "<1.000000, 0.000000, 0.000000>"); |
| 683 |
} |
| 684 |
|
| 685 |
public Vector34 foobar() |
| 686 |
{ |
| 687 |
return v; |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
void test34() |
| 692 |
{ |
| 693 |
Foo34 f = new Foo34(); |
| 694 |
f.foo(); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
/************************************************/ |
| 699 |
|
| 700 |
void foo35() |
| 701 |
{ |
| 702 |
uint a; |
| 703 |
uint b; |
| 704 |
uint c; |
| 705 |
extern (Windows) int function(int i, int j, int k) xxx; |
| 706 |
|
| 707 |
a = 1; |
| 708 |
b = 2; |
| 709 |
c = 3; |
| 710 |
|
| 711 |
xxx = cast(typeof(xxx))(a + b); |
| 712 |
throw new Exception("xxx"); |
| 713 |
xxx( 4, 5, 6 ); |
| 714 |
} |
| 715 |
|
| 716 |
void test35() |
| 717 |
{ |
| 718 |
} |
| 719 |
|
| 720 |
/************************************************/ |
| 721 |
|
| 722 |
void test36() |
| 723 |
{ |
| 724 |
int* p = void, c = void; |
| 725 |
} |
| 726 |
|
| 727 |
/************************************************/ |
| 728 |
|
| 729 |
void test37() |
| 730 |
{ |
| 731 |
synchronized |
| 732 |
{ |
| 733 |
synchronized |
| 734 |
{ |
| 735 |
printf("Hello world!\n"); |
| 736 |
} |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
/************************************************/ |
| 741 |
|
| 742 |
struct Rect { |
| 743 |
int left, top, right, bottom; |
| 744 |
} |
| 745 |
|
| 746 |
void test38() |
| 747 |
{ |
| 748 |
print38(sizeTest(false)); |
| 749 |
print38(sizeTest(true)); |
| 750 |
print38(defaultRect); |
| 751 |
} |
| 752 |
|
| 753 |
static Rect sizeTest(bool empty) { |
| 754 |
if (empty) { |
| 755 |
Rect result; |
| 756 |
return result; |
| 757 |
//return Rect.init; |
| 758 |
} else { |
| 759 |
return defaultRect; |
| 760 |
/+Rect result = defaultRect; |
| 761 |
return result;+/ |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
void print38(Rect r) { |
| 766 |
printf("(%d, %d)-(%d, %d)\n", r.left, r.top, r.right, r.bottom); |
| 767 |
assert(r.left == 0); |
| 768 |
assert(r.right == 0); |
| 769 |
assert(r.top == 0); |
| 770 |
assert(r.bottom == 0); |
| 771 |
} |
| 772 |
|
| 773 |
Rect defaultRect() { |
| 774 |
return Rect.init; |
| 775 |
} |
| 776 |
|
| 777 |
/************************************************/ |
| 778 |
|
| 779 |
void varargs39(...) |
| 780 |
{ |
| 781 |
if (_arguments[0] is typeid(double[])) |
| 782 |
{ |
| 783 |
auto arg = va_arg!(double[])(_argptr); |
| 784 |
assert(arg.length == 1 && arg[0] == 1 || arg[0] == 2); |
| 785 |
} |
| 786 |
else if (_arguments[0] is typeid(double[][])) |
| 787 |
{ |
| 788 |
auto arg = va_arg!(double[][])(_argptr); |
| 789 |
assert(arg == [[1],[2]]); |
| 790 |
} |
| 791 |
else if (_arguments[0] is typeid(double[1][])) |
| 792 |
{ |
| 793 |
auto arg = va_arg!(double[1][])(_argptr); |
| 794 |
assert(arg == [[1], [2]]); |
| 795 |
} |
| 796 |
else |
| 797 |
assert(0); |
| 798 |
} |
| 799 |
|
| 800 |
void test39() |
| 801 |
{ |
| 802 |
double[][] foo = [[1.0],[2.0]]; |
| 803 |
|
| 804 |
varargs39(foo[0]); // --> [1] , ok |
| 805 |
varargs39(foo[1]); // --> [2] , ok |
| 806 |
varargs39(foo); // --> [[1],4.63919e-306] ack! |
| 807 |
|
| 808 |
double[1][2] bar; |
| 809 |
bar[0][0] = 1.0; |
| 810 |
bar[1][0] = 2.0; |
| 811 |
|
| 812 |
varargs39(bar); // Error: Access violation |
| 813 |
} |
| 814 |
|
| 815 |
/************************************************/ |
| 816 |
|
| 817 |
void varargs40(...) |
| 818 |
{ |
| 819 |
if (_arguments[0] is typeid(int[char])) |
| 820 |
{ |
| 821 |
auto x = va_arg!(int[char])(_argptr); |
| 822 |
assert(x == ['b':123]); |
| 823 |
} |
| 824 |
else if (_arguments[0] is typeid(int)) |
| 825 |
{ |
| 826 |
auto x = va_arg!int(_argptr); |
| 827 |
assert(x == 123); |
| 828 |
} |
| 829 |
else |
| 830 |
assert(0); |
| 831 |
} |
| 832 |
|
| 833 |
void test40() |
| 834 |
{ |
| 835 |
int[char] x; |
| 836 |
x['b'] = 123; |
| 837 |
varargs40(x); |
| 838 |
varargs40(x['b']); |
| 839 |
} |
| 840 |
|
| 841 |
/************************************************/ |
| 842 |
|
| 843 |
void test41() |
| 844 |
{ |
| 845 |
} |
| 846 |
|
| 847 |
/************************************************/ |
| 848 |
|
| 849 |
enum Enum42 { |
| 850 |
A = 1 |
| 851 |
} |
| 852 |
|
| 853 |
void test42() { |
| 854 |
Enum42[] enums = new Enum42[1]; |
| 855 |
assert(enums[0] == Enum42.A); |
| 856 |
} |
| 857 |
|
| 858 |
|
| 859 |
/************************************************/ |
| 860 |
|
| 861 |
struct A43 {} |
| 862 |
|
| 863 |
struct B43(L) { |
| 864 |
A43 l; |
| 865 |
} |
| 866 |
|
| 867 |
void test43() |
| 868 |
{ |
| 869 |
A43 a; |
| 870 |
auto b = B43!(A43)(a); |
| 871 |
} |
| 872 |
|
| 873 |
/************************************************/ |
| 874 |
|
| 875 |
void test44() |
| 876 |
{ |
| 877 |
int[ const char[] ] a = ["abc":3, "def":4]; |
| 878 |
} |
| 879 |
|
| 880 |
/************************************************/ |
| 881 |
|
| 882 |
void varargs45(...) |
| 883 |
{ |
| 884 |
if (_arguments[0] is typeid(const(char[3])[])) |
| 885 |
{ |
| 886 |
auto a = va_arg!(const(char[3])[])(_argptr); |
| 887 |
assert(a == ["abc", "def"]); |
| 888 |
} |
| 889 |
else if (_arguments[0] is typeid(const(char)[][])) |
| 890 |
{ |
| 891 |
auto b = va_arg!(const(char)[][])(_argptr); |
| 892 |
assert(b == ["abc", "def"]); |
| 893 |
} |
| 894 |
else |
| 895 |
assert(0); |
| 896 |
} |
| 897 |
|
| 898 |
void test45() |
| 899 |
{ |
| 900 |
const(char)[3][] a = ["abc", "def"]; |
| 901 |
varargs45(a); |
| 902 |
const(char)[][2] b = ["abc", "def"]; |
| 903 |
varargs45(b); |
| 904 |
} |
| 905 |
|
| 906 |
/************************************************/ |
| 907 |
|
| 908 |
struct bignum |
| 909 |
{ |
| 910 |
bool smaller() |
| 911 |
{ |
| 912 |
if (true) return false; |
| 913 |
else return false; |
| 914 |
assert(0); |
| 915 |
} |
| 916 |
|
| 917 |
void equal() |
| 918 |
{ |
| 919 |
if (!smaller) |
| 920 |
return; |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
void test46() |
| 925 |
{ |
| 926 |
} |
| 927 |
|
| 928 |
/************************************************/ |
| 929 |
|
| 930 |
static size_t myfind(string haystack, char needle) { |
| 931 |
foreach (i, c ; haystack) { |
| 932 |
if (c == needle) return i; |
| 933 |
} |
| 934 |
return size_t.max; |
| 935 |
} |
| 936 |
|
| 937 |
static size_t skip_digits(string s) { |
| 938 |
foreach (i, c ; s) { |
| 939 |
if (c < '0' || c > '9') return i; |
| 940 |
} |
| 941 |
return s.length; |
| 942 |
} |
| 943 |
|
| 944 |
static uint matoi(string s) { |
| 945 |
uint result = 0; |
| 946 |
foreach (c ; s) { |
| 947 |
if (c < '0' || c > '9') break; |
| 948 |
result = result * 10 + (c - '0'); |
| 949 |
} |
| 950 |
return result; |
| 951 |
} |
| 952 |
|
| 953 |
enum { leading, skip, width, modifier, format, fmt_length, extra }; |
| 954 |
|
| 955 |
static string GetFormat(string s) { |
| 956 |
uint pos = 0; |
| 957 |
string result; |
| 958 |
// find the percent sign |
| 959 |
while (pos < s.length && s[pos] != '%') { |
| 960 |
++pos; |
| 961 |
} |
| 962 |
const leading_chars = pos; |
| 963 |
result ~= cast(char) pos; |
| 964 |
if (pos < s.length) ++pos; // go right after the '%' |
| 965 |
// skip? |
| 966 |
if (pos < s.length && s[pos] == '*') { |
| 967 |
result ~= 1; |
| 968 |
++pos; |
| 969 |
} else { |
| 970 |
result ~= 0; |
| 971 |
} |
| 972 |
// width? |
| 973 |
result ~= cast(char) matoi(s); |
| 974 |
pos += skip_digits(s[pos .. $]); |
| 975 |
// modifier? |
| 976 |
if (pos < s.length && myfind("hjlLqtz", s[pos]) != size_t.max) { |
| 977 |
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 978 |
static if (true) { |
| 979 |
result ~= s[pos++]; |
| 980 |
} else { |
| 981 |
result ~= s[pos]; |
| 982 |
++pos; |
| 983 |
} |
| 984 |
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
| 985 |
} else { |
| 986 |
result ~= '\0'; |
| 987 |
} |
| 988 |
return result; |
| 989 |
} |
| 990 |
|
| 991 |
void test47() |
| 992 |
{ |
| 993 |
static string test = GetFormat(" %*Lf"); |
| 994 |
assert(test[modifier] == 'L', "`" ~ test[modifier] ~ "'"); |
| 995 |
} |
| 996 |
|
| 997 |
/************************************************/ |
| 998 |
|
| 999 |
class B48() {} |
| 1000 |
class C48 {} |
| 1001 |
|
| 1002 |
int foo48()(B48!()) { return 1; } |
| 1003 |
int foo48()(C48 c) { return 2; } |
| 1004 |
|
| 1005 |
void test48() |
| 1006 |
{ |
| 1007 |
auto i = foo48(new B48!()); |
| 1008 |
assert(i == 1); |
| 1009 |
|
| 1010 |
i = foo48(new C48); |
| 1011 |
assert(i == 2); |
| 1012 |
} |
| 1013 |
|
| 1014 |
/************************************************/ |
| 1015 |
|
| 1016 |
void test49() |
| 1017 |
{ |
| 1018 |
struct A { int v; } |
| 1019 |
|
| 1020 |
A a = A(10); |
| 1021 |
|
| 1022 |
version (all) |
| 1023 |
{ |
| 1024 |
if (a == a.init) { assert(0); } |
| 1025 |
else { assert(a.v == 10); } |
| 1026 |
} |
| 1027 |
else |
| 1028 |
{ |
| 1029 |
if (a == a.init) { assert(a.v == 10); } |
| 1030 |
else { assert(0); } |
| 1031 |
} |
| 1032 |
|
| 1033 |
a.v = 100; |
| 1034 |
if (a == a.init) { assert(0); } |
| 1035 |
else { assert(a.v == 100); } |
| 1036 |
|
| 1037 |
a = A(1000); |
| 1038 |
if (a == a.init) { assert(0); } |
| 1039 |
else { assert(a.v == 1000); } |
| 1040 |
|
| 1041 |
version (all) |
| 1042 |
assert(a.init.v == 0); |
| 1043 |
else |
| 1044 |
assert(a.init.v == 10); |
| 1045 |
} |
| 1046 |
|
| 1047 |
/************************************************/ |
| 1048 |
|
| 1049 |
struct S51 |
| 1050 |
{ |
| 1051 |
int i = 3; |
| 1052 |
void div() { assert(i == 3); } |
| 1053 |
} |
| 1054 |
|
| 1055 |
void test51() |
| 1056 |
{ |
| 1057 |
S51().div(); |
| 1058 |
} |
| 1059 |
|
| 1060 |
/************************************************/ |
| 1061 |
|
| 1062 |
void test52() |
| 1063 |
{ |
| 1064 |
struct Foo { |
| 1065 |
alias int Y; |
| 1066 |
} |
| 1067 |
with (Foo) { |
| 1068 |
Y y; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
/************************************************/ |
| 1073 |
|
| 1074 |
struct TestStruct |
| 1075 |
{ |
| 1076 |
int dummy0 = 0; |
| 1077 |
int dummy1 = 1; |
| 1078 |
int dummy2 = 2; |
| 1079 |
} |
| 1080 |
|
| 1081 |
void func53(TestStruct[2] testarg) |
| 1082 |
{ |
| 1083 |
assert(testarg[0].dummy0 == 0); |
| 1084 |
assert(testarg[0].dummy1 == 1); |
| 1085 |
assert(testarg[0].dummy2 == 2); |
| 1086 |
|
| 1087 |
assert(testarg[1].dummy0 == 0); |
| 1088 |
assert(testarg[1].dummy1 == 1); |
| 1089 |
assert(testarg[1].dummy2 == 2); |
| 1090 |
} |
| 1091 |
|
| 1092 |
TestStruct[2] m53; |
| 1093 |
|
| 1094 |
void test53() |
| 1095 |
{ |
| 1096 |
func53(m53); |
| 1097 |
} |
| 1098 |
|
| 1099 |
/************************************************/ |
| 1100 |
|
| 1101 |
void test54() |
| 1102 |
{ |
| 1103 |
double a = 0; |
| 1104 |
double b = 1; |
| 1105 |
// Internal error: ..\ztc\cg87.c 3233 |
| 1106 |
a += ((1? b: 1+1i)*1i).re; |
| 1107 |
assert(a == 0); |
| 1108 |
// Internal error: ..\ztc\cod2.c 1680 |
| 1109 |
a += ((b?1:b-1i)*1i).re; |
| 1110 |
assert(a == 0); |
| 1111 |
} |
| 1112 |
|
| 1113 |
/************************************************/ |
| 1114 |
|
| 1115 |
class B55 {} |
| 1116 |
class D55 : B55 {} |
| 1117 |
|
| 1118 |
template foo55(S, T : S) { } // doesn't work |
| 1119 |
|
| 1120 |
alias foo55!(B55, D55) bar55; |
| 1121 |
|
| 1122 |
void test55() |
| 1123 |
{ |
| 1124 |
} |
| 1125 |
|
| 1126 |
/************************************************/ |
| 1127 |
|
| 1128 |
template t56() { alias Object t56; } |
| 1129 |
static assert(t56!().stringof == "Object"); |
| 1130 |
|
| 1131 |
void test56() |
| 1132 |
{ |
| 1133 |
} |
| 1134 |
|
| 1135 |
/************************************************/ |
| 1136 |
|
| 1137 |
void test57() |
| 1138 |
{ |
| 1139 |
alias long[char[]] AA; |
| 1140 |
|
| 1141 |
static if (is(AA T : T[U], U : const char[])) |
| 1142 |
{ |
| 1143 |
assert(is(T == long)); |
| 1144 |
assert(is(U == const(char)[])); |
| 1145 |
} |
| 1146 |
|
| 1147 |
static if (is(AA A : A[B], B : int)) |
| 1148 |
{ |
| 1149 |
assert(0); |
| 1150 |
} |
| 1151 |
|
| 1152 |
static if (is(int[10] W : W[V], int V)) |
| 1153 |
{ |
| 1154 |
assert(is(W == int)); |
| 1155 |
assert(V == 10); |
| 1156 |
} |
| 1157 |
|
| 1158 |
static if (is(int[10] X : X[Y], int Y : 5)) |
| 1159 |
{ |
| 1160 |
assert(0); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
/************************************************/ |
| 1165 |
|
| 1166 |
static this() |
| 1167 |
{ |
| 1168 |
printf("one\n"); |
| 1169 |
} |
| 1170 |
|
| 1171 |
static this() |
| 1172 |
{ |
| 1173 |
printf("two\n"); |
| 1174 |
} |
| 1175 |
|
| 1176 |
static ~this() |
| 1177 |
{ |
| 1178 |
printf("~two\n"); |
| 1179 |
} |
| 1180 |
|
| 1181 |
static ~this() |
| 1182 |
{ |
| 1183 |
printf("~one\n"); |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
void test59() |
| 1188 |
{ |
| 1189 |
} |
| 1190 |
|
| 1191 |
/************************************************/ |
| 1192 |
|
| 1193 |
class C60 |
| 1194 |
{ |
| 1195 |
extern (C++) int bar60(int i, int j, int k) |
| 1196 |
{ |
| 1197 |
printf("this = %p\n", this); |
| 1198 |
printf("i = %d\n", i); |
| 1199 |
printf("j = %d\n", j); |
| 1200 |
printf("k = %d\n", k); |
| 1201 |
assert(i == 4); |
| 1202 |
assert(j == 5); |
| 1203 |
assert(k == 6); |
| 1204 |
return 1; |
| 1205 |
} |
| 1206 |
} |
| 1207 |
|
| 1208 |
|
| 1209 |
extern (C++) |
| 1210 |
int foo60(int i, int j, int k) |
| 1211 |
{ |
| 1212 |
printf("i = %d\n", i); |
| 1213 |
printf("j = %d\n", j); |
| 1214 |
printf("k = %d\n", k); |
| 1215 |
assert(i == 1); |
| 1216 |
assert(j == 2); |
| 1217 |
assert(k == 3); |
| 1218 |
return 1; |
| 1219 |
} |
| 1220 |
|
| 1221 |
void test60() |
| 1222 |
{ |
| 1223 |
foo60(1, 2, 3); |
| 1224 |
|
| 1225 |
C60 c = new C60(); |
| 1226 |
c.bar60(4, 5, 6); |
| 1227 |
} |
| 1228 |
|
| 1229 |
/***************************************************/ |
| 1230 |
|
| 1231 |
template Foo61(alias a) {} |
| 1232 |
|
| 1233 |
struct Bar61 {} |
| 1234 |
const Bar61 bar61 = {}; |
| 1235 |
|
| 1236 |
alias Foo61!(bar61) baz61; |
| 1237 |
|
| 1238 |
void test61() |
| 1239 |
{ |
| 1240 |
} |
| 1241 |
|
| 1242 |
/************************************************/ |
| 1243 |
|
| 1244 |
T foo62(T)(lazy T value) |
| 1245 |
{ |
| 1246 |
return value; |
| 1247 |
} |
| 1248 |
|
| 1249 |
void test62() |
| 1250 |
{ |
| 1251 |
foo62(new float[1]); |
| 1252 |
} |
| 1253 |
|
| 1254 |
/************************************************/ |
| 1255 |
|
| 1256 |
void main() |
| 1257 |
{ |
| 1258 |
test1(); |
| 1259 |
test2(); |
| 1260 |
test3(); |
| 1261 |
test4(); |
| 1262 |
test5(); |
| 1263 |
test6(); |
| 1264 |
test7(); |
| 1265 |
test8(); |
| 1266 |
test9(); |
| 1267 |
test10(); |
| 1268 |
test11(); |
| 1269 |
test12(); |
| 1270 |
test13(); |
| 1271 |
test15(); |
| 1272 |
test16(); |
| 1273 |
test17(); |
| 1274 |
test18(); |
| 1275 |
test19(); |
| 1276 |
test20(); |
| 1277 |
test21(); |
| 1278 |
test22(); |
| 1279 |
test23(); |
| 1280 |
test24(); |
| 1281 |
test25(); |
| 1282 |
test26(); |
| 1283 |
test27(); |
| 1284 |
test28(); |
| 1285 |
test29(); |
| 1286 |
test30(); |
| 1287 |
test31(); |
| 1288 |
test32(); |
| 1289 |
test33(); |
| 1290 |
test34(); |
| 1291 |
test35(); |
| 1292 |
test36(); |
| 1293 |
test37(); |
| 1294 |
test38(); |
| 1295 |
test39(); |
| 1296 |
test40(); |
| 1297 |
test41(); |
| 1298 |
test42(); |
| 1299 |
test43(); |
| 1300 |
test44(); |
| 1301 |
test45(); |
| 1302 |
test46(); |
| 1303 |
test47(); |
| 1304 |
test48(); |
| 1305 |
test49(); |
| 1306 |
test51(); |
| 1307 |
test52(); |
| 1308 |
test53(); |
| 1309 |
test54(); |
| 1310 |
test55(); |
| 1311 |
test56(); |
| 1312 |
test57(); |
| 1313 |
test59(); |
| 1314 |
test60(); |
| 1315 |
test61(); |
| 1316 |
test62(); |
| 1317 |
|
| 1318 |
printf("Success\n"); |
| 1319 |
} |