| 1 |
// REQUIRED_ARGS: |
| 2 |
// EXTRA_SOURCES: imports/std11file.d |
| 3 |
|
| 4 |
extern(C) int printf(const char*, ...); |
| 5 |
extern(C) size_t strlen(const char*); |
| 6 |
|
| 7 |
/**************************************/ |
| 8 |
|
| 9 |
alias strlen foo1; |
| 10 |
|
| 11 |
void test1() |
| 12 |
{ |
| 13 |
const(char) *p = "bar"; |
| 14 |
size_t i = foo1(p); |
| 15 |
assert(i == 3); |
| 16 |
} |
| 17 |
|
| 18 |
/**************************************/ |
| 19 |
|
| 20 |
template Foo2(T) |
| 21 |
{ |
| 22 |
alias T t; |
| 23 |
} |
| 24 |
|
| 25 |
alias Foo2!(int) t1; |
| 26 |
alias Foo2!(int).t t2; |
| 27 |
alias t1.t t3; |
| 28 |
alias t2 t4; |
| 29 |
alias Foo2!(int) t5; |
| 30 |
|
| 31 |
void test2() |
| 32 |
{ |
| 33 |
t1.t v1; |
| 34 |
t2 v2; |
| 35 |
t3 v3; |
| 36 |
t4 v4; |
| 37 |
t5.t v5; |
| 38 |
int *p; |
| 39 |
|
| 40 |
p = &v1; |
| 41 |
p = &v2; |
| 42 |
p = &v3; |
| 43 |
p = &v4; |
| 44 |
p = &v5; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
/**************************************/ |
| 49 |
|
| 50 |
debug = stdchar; |
| 51 |
|
| 52 |
debug(mychar) |
| 53 |
{ |
| 54 |
alias byte mychar; |
| 55 |
} |
| 56 |
|
| 57 |
void test3() |
| 58 |
{ |
| 59 |
debug(mychar) |
| 60 |
{ |
| 61 |
mychar[] line=cast(mychar[])cast(char[])"It is a long line."; |
| 62 |
mychar[] delimiter=cast(mychar[])cast(string)"is"; |
| 63 |
} |
| 64 |
|
| 65 |
debug(stdchar) |
| 66 |
{ |
| 67 |
string line="It is a long line."; |
| 68 |
string delimiter="is"; |
| 69 |
} |
| 70 |
|
| 71 |
debug(stdbyte) |
| 72 |
{ |
| 73 |
byte[] line=cast(byte[])cast(string)"It is a long line."; |
| 74 |
byte[] delimiter=cast(byte[])cast(string)"is"; |
| 75 |
} |
| 76 |
|
| 77 |
debug(stdwchar) |
| 78 |
{ |
| 79 |
wstring line="It is a long line."; |
| 80 |
wstring delimiter="is"; |
| 81 |
} |
| 82 |
int ptr=3; |
| 83 |
|
| 84 |
size_t dl=delimiter.length; |
| 85 |
size_t pl=ptr+dl; |
| 86 |
|
| 87 |
assert(line[ptr..pl]==delimiter[]); |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
/**************************************/ |
| 92 |
|
| 93 |
void test4() |
| 94 |
{ |
| 95 |
byte* p; |
| 96 |
|
| 97 |
version(D_LP64) |
| 98 |
assert(p.sizeof == 8); |
| 99 |
else |
| 100 |
assert(p.sizeof == 4); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
/**************************************/ |
| 105 |
|
| 106 |
|
| 107 |
class Foo6 |
| 108 |
{ |
| 109 |
} |
| 110 |
|
| 111 |
void test6() |
| 112 |
{ |
| 113 |
Foo6 foo = new Foo6(); |
| 114 |
|
| 115 |
with (foo) |
| 116 |
{ |
| 117 |
int x; |
| 118 |
|
| 119 |
x = 4; |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
/**************************************/ |
| 124 |
|
| 125 |
int i7 = 3; |
| 126 |
|
| 127 |
void test7() |
| 128 |
{ |
| 129 |
switch (i7) |
| 130 |
{ |
| 131 |
default: assert(0); |
| 132 |
case 3: |
| 133 |
int x; |
| 134 |
|
| 135 |
x = 4; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
/**************************************/ |
| 140 |
|
| 141 |
void test8() |
| 142 |
{ |
| 143 |
string a = "a |
| 144 |
b |
| 145 |
c"; |
| 146 |
assert(a.length == 5); |
| 147 |
assert(a[1] == '\n'); |
| 148 |
} |
| 149 |
|
| 150 |
/**************************************/ |
| 151 |
|
| 152 |
|
| 153 |
struct Foo9 { char c; char bar() { return c; } } |
| 154 |
|
| 155 |
Foo9 makeFoo() { Foo9 f; return f; } |
| 156 |
|
| 157 |
void callFoo (Foo9 a) |
| 158 |
{ |
| 159 |
a.bar(); |
| 160 |
} |
| 161 |
|
| 162 |
void test9() |
| 163 |
{ |
| 164 |
callFoo(makeFoo ()); |
| 165 |
} |
| 166 |
|
| 167 |
/**************************************/ |
| 168 |
|
| 169 |
|
| 170 |
struct Foo10 { } |
| 171 |
|
| 172 |
Foo10 makeFoo10() { Foo10 f; return f; } |
| 173 |
|
| 174 |
void callFoo (Foo10 a) |
| 175 |
{ |
| 176 |
} |
| 177 |
|
| 178 |
void test10() |
| 179 |
{ |
| 180 |
callFoo(makeFoo10()); |
| 181 |
} |
| 182 |
|
| 183 |
/**************************************/ |
| 184 |
|
| 185 |
struct Color |
| 186 |
{ int x; } |
| 187 |
|
| 188 |
Color[3] colors; |
| 189 |
|
| 190 |
Color eval(float x, float y) |
| 191 |
{ |
| 192 |
colors[1].x = 7; |
| 193 |
return colors[1]; |
| 194 |
} |
| 195 |
|
| 196 |
void test11() |
| 197 |
{ |
| 198 |
Color c; |
| 199 |
|
| 200 |
c = eval(1.0, 2.0); |
| 201 |
assert(c.x == 7); |
| 202 |
} |
| 203 |
|
| 204 |
/**************************************/ |
| 205 |
|
| 206 |
struct Size12 |
| 207 |
{ |
| 208 |
int width; |
| 209 |
int height; |
| 210 |
} |
| 211 |
|
| 212 |
int x12; |
| 213 |
|
| 214 |
void foo12(out Size12 sz) |
| 215 |
{ |
| 216 |
sz.width = 2; |
| 217 |
|
| 218 |
if(sz.width == 2) |
| 219 |
x12 = 1; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
void test12() |
| 224 |
{ |
| 225 |
Size12 sz; |
| 226 |
|
| 227 |
foo12(sz); |
| 228 |
assert(x12 == 1); |
| 229 |
assert(sz.width == 2); |
| 230 |
} |
| 231 |
|
| 232 |
/**************************************/ |
| 233 |
|
| 234 |
|
| 235 |
interface D13 |
| 236 |
{ |
| 237 |
void setHostFrame(); |
| 238 |
} |
| 239 |
|
| 240 |
class A13 : D13 |
| 241 |
{ |
| 242 |
void setHostFrame() |
| 243 |
{ |
| 244 |
} |
| 245 |
|
| 246 |
char group; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
void setLayout(D13 lo) |
| 251 |
{ |
| 252 |
printf("lo = %p\n", lo); |
| 253 |
lo.setHostFrame(); |
| 254 |
printf("ok\n"); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
void test13() |
| 259 |
{ |
| 260 |
A13 a = new A13(); |
| 261 |
printf("a = %p\n", a); |
| 262 |
setLayout(a); |
| 263 |
} |
| 264 |
|
| 265 |
/**************************************/ |
| 266 |
|
| 267 |
void test14() |
| 268 |
{ |
| 269 |
while(false) |
| 270 |
{ |
| 271 |
static int a; |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
|
| 276 |
/**************************************/ |
| 277 |
|
| 278 |
alias void delegate(int) t_func; |
| 279 |
|
| 280 |
class Foo15 |
| 281 |
{ |
| 282 |
t_func func1; |
| 283 |
int x; |
| 284 |
|
| 285 |
void dothis() |
| 286 |
{ |
| 287 |
if (func1) |
| 288 |
func1(4); |
| 289 |
else |
| 290 |
x = 3; |
| 291 |
} |
| 292 |
|
| 293 |
void func(int num) { x = num; } |
| 294 |
} |
| 295 |
|
| 296 |
void test15() |
| 297 |
{ |
| 298 |
Foo15 a = new Foo15; |
| 299 |
a.dothis(); |
| 300 |
assert(a.x == 3); |
| 301 |
a.func1 = &a.func; |
| 302 |
a.dothis(); |
| 303 |
assert(a.x == 4); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
/**************************************/ |
| 308 |
|
| 309 |
int[] foo16(byte[] a) |
| 310 |
{ |
| 311 |
return cast(int[])a; |
| 312 |
} |
| 313 |
|
| 314 |
void test16() |
| 315 |
{ |
| 316 |
byte[12] b; |
| 317 |
int[] i; |
| 318 |
|
| 319 |
i = foo16(b); |
| 320 |
assert(i.length == 3); |
| 321 |
} |
| 322 |
|
| 323 |
/**************************************/ |
| 324 |
|
| 325 |
void test17() |
| 326 |
{ |
| 327 |
{ |
| 328 |
float x = 10; |
| 329 |
x %= 4; |
| 330 |
printf("x = %g\n", x); |
| 331 |
assert(x == 2); |
| 332 |
x = 10; |
| 333 |
x = x % 4; |
| 334 |
printf("x = %g\n", x); |
| 335 |
assert(x == 2); |
| 336 |
x = 4; |
| 337 |
x = 10 % x; |
| 338 |
printf("x = %g\n", x); |
| 339 |
assert(x == 2); |
| 340 |
} |
| 341 |
{ |
| 342 |
double y = 10; |
| 343 |
y %= 4; |
| 344 |
printf("y = %g\n", y); |
| 345 |
assert(y == 2); |
| 346 |
y = 10; |
| 347 |
y = y % 4; |
| 348 |
printf("y = %g\n", y); |
| 349 |
assert(y == 2); |
| 350 |
y = 4; |
| 351 |
y = 10 % y; |
| 352 |
printf("y = %g\n", y); |
| 353 |
assert(y == 2); |
| 354 |
} |
| 355 |
{ |
| 356 |
real z = 10; |
| 357 |
z %= 4; |
| 358 |
printf("z = %Lg\n", z); |
| 359 |
assert(z == 2); |
| 360 |
z = 10; |
| 361 |
z = z % 4; |
| 362 |
printf("z = %Lg\n", z); |
| 363 |
assert(z == 2); |
| 364 |
z = 4; |
| 365 |
z = 10 % z; |
| 366 |
printf("z = %Lg\n", z); |
| 367 |
assert(z == 2); |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
/**************************************/ |
| 373 |
|
| 374 |
struct Bar18 { } |
| 375 |
|
| 376 |
struct Foo18 |
| 377 |
{ |
| 378 |
static Bar18 x = { }; |
| 379 |
} |
| 380 |
|
| 381 |
void test18() |
| 382 |
{ |
| 383 |
const Bar18 b = Foo18.x; |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
/**************************************/ |
| 388 |
|
| 389 |
int x19 = 10; |
| 390 |
|
| 391 |
void test19() |
| 392 |
{ bool b; |
| 393 |
|
| 394 |
b = cast(bool)x19; |
| 395 |
assert(b == true); |
| 396 |
} |
| 397 |
|
| 398 |
/**************************************/ |
| 399 |
|
| 400 |
class A20 |
| 401 |
{ |
| 402 |
int abc() { return 3; } |
| 403 |
|
| 404 |
alias abc def; |
| 405 |
} |
| 406 |
|
| 407 |
void test20() |
| 408 |
{ |
| 409 |
int i; |
| 410 |
A20 a = new A20(); |
| 411 |
|
| 412 |
i = a.def(); |
| 413 |
assert(i == 3); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
/**************************************/ |
| 418 |
|
| 419 |
void test21() |
| 420 |
{ |
| 421 |
string s; |
| 422 |
s = 1 ? "a" : "b"; |
| 423 |
assert(s == "a"); |
| 424 |
} |
| 425 |
|
| 426 |
/**************************************/ |
| 427 |
|
| 428 |
class Foo22 |
| 429 |
{ |
| 430 |
} |
| 431 |
|
| 432 |
class Bar22 : Foo22 |
| 433 |
{ |
| 434 |
} |
| 435 |
|
| 436 |
class Abc22 |
| 437 |
{ |
| 438 |
Foo22 test() { return null; } |
| 439 |
} |
| 440 |
|
| 441 |
class Def22 : Abc22 |
| 442 |
{ |
| 443 |
override Bar22 test() { return new Bar22; } |
| 444 |
} |
| 445 |
|
| 446 |
void testx22(Abc22 a) |
| 447 |
{ |
| 448 |
assert(a.test() !is null); |
| 449 |
} |
| 450 |
|
| 451 |
void test22() |
| 452 |
{ |
| 453 |
Def22 d = new Def22(); |
| 454 |
|
| 455 |
testx22(d); |
| 456 |
} |
| 457 |
|
| 458 |
/**************************************/ |
| 459 |
|
| 460 |
struct foo23 |
| 461 |
{ |
| 462 |
static struct bar |
| 463 |
{ |
| 464 |
int x; |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
void test23() |
| 469 |
{ |
| 470 |
//printf ("%d\n", foo23.bar.sizeof); |
| 471 |
assert(foo23.bar.sizeof == int.sizeof); |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
/**************************************/ |
| 476 |
|
| 477 |
void test24() |
| 478 |
{ |
| 479 |
struct Test |
| 480 |
{ |
| 481 |
int i; |
| 482 |
|
| 483 |
bool bar(int a) |
| 484 |
{ |
| 485 |
i = a; |
| 486 |
return true; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
Test t; |
| 491 |
assert(t.bar(3)); |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
/**************************************/ |
| 496 |
|
| 497 |
void test25() |
| 498 |
{ |
| 499 |
{ const int [] list = [ 1, 2 ]; |
| 500 |
assert(list[0] == 1); |
| 501 |
assert(list[1] == 2); |
| 502 |
} |
| 503 |
|
| 504 |
{ const int [] list = [ 3, 4 ]; |
| 505 |
assert(list[0] == 3); |
| 506 |
assert(list[1] == 4); |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
/**************************************/ |
| 512 |
|
| 513 |
void test26() |
| 514 |
{ |
| 515 |
while (0) |
| 516 |
{ |
| 517 |
int x; |
| 518 |
} |
| 519 |
|
| 520 |
while (0) |
| 521 |
{ |
| 522 |
int x; |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
/**************************************/ |
| 528 |
|
| 529 |
struct NODE27 { |
| 530 |
int data; |
| 531 |
shared(NODE27) *next; |
| 532 |
} |
| 533 |
|
| 534 |
static shared NODE27[3] nodetbl = |
| 535 |
[ |
| 536 |
{ 0,cast(shared(NODE27)*)nodetbl + 1}, |
| 537 |
{ 0,cast(shared(NODE27)*)nodetbl + 2}, |
| 538 |
{ 0,null} |
| 539 |
]; |
| 540 |
|
| 541 |
static shared NODE27[3] nodetbl2 = [ |
| 542 |
{ 0,&nodetbl2[1]}, |
| 543 |
{ 0,&nodetbl2[2]}, |
| 544 |
{ 0,null} |
| 545 |
]; |
| 546 |
|
| 547 |
void test27() |
| 548 |
{ |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
/**************************************/ |
| 553 |
|
| 554 |
class Foo28 |
| 555 |
{ |
| 556 |
protected int x; |
| 557 |
|
| 558 |
static class Bar |
| 559 |
{ |
| 560 |
Foo28 f; |
| 561 |
|
| 562 |
int method () { return f.x; } |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
void test28() |
| 567 |
{ |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
/**************************************/ |
| 572 |
|
| 573 |
void test29() |
| 574 |
{ |
| 575 |
int[immutable(byte)[]] foo; |
| 576 |
|
| 577 |
static immutable(byte)[] bar = [ 65, 66, 67 ]; |
| 578 |
|
| 579 |
foo[bar] = 1; |
| 580 |
assert(foo[bar] == 1); |
| 581 |
} |
| 582 |
|
| 583 |
/**************************************/ |
| 584 |
|
| 585 |
class A30 |
| 586 |
{ |
| 587 |
static class Child |
| 588 |
{ |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
|
| 593 |
class B30 |
| 594 |
{ |
| 595 |
static class Child |
| 596 |
{ |
| 597 |
static int value = 6; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
void test30() |
| 602 |
{ |
| 603 |
printf ("%d\n", B30.Child.value); |
| 604 |
assert(B30.Child.value == 6); |
| 605 |
} |
| 606 |
|
| 607 |
|
| 608 |
/**************************************/ |
| 609 |
|
| 610 |
void test31() |
| 611 |
{ |
| 612 |
float b; |
| 613 |
b -= 1.0; |
| 614 |
b += 1.0; |
| 615 |
} |
| 616 |
|
| 617 |
/**************************************/ |
| 618 |
|
| 619 |
class Foo32 |
| 620 |
{ |
| 621 |
struct Bar |
| 622 |
{ |
| 623 |
int x; |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
void test32() |
| 628 |
{ |
| 629 |
with (new Foo32) |
| 630 |
{ |
| 631 |
Bar z; |
| 632 |
z.x = 5; |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
/**************************************/ |
| 638 |
|
| 639 |
string[2][] foo33; |
| 640 |
|
| 641 |
void test33() |
| 642 |
{ |
| 643 |
string[2] bar; |
| 644 |
|
| 645 |
bar[1] = "hello"; |
| 646 |
foo33 ~= bar; |
| 647 |
assert(foo33[0][1] == "hello"); |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
/**************************************/ |
| 652 |
|
| 653 |
|
| 654 |
void test34() |
| 655 |
{ |
| 656 |
try { |
| 657 |
int i = 0; |
| 658 |
printf( "i:%d\n", i ); |
| 659 |
} finally { |
| 660 |
printf( "Done\n" ); |
| 661 |
} |
| 662 |
try { |
| 663 |
int i = 1; |
| 664 |
printf( "i:%d\n", i ); |
| 665 |
} finally { |
| 666 |
printf( "Done\n" ); |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
|
| 671 |
/**************************************/ |
| 672 |
|
| 673 |
class Bar35 {} |
| 674 |
|
| 675 |
template Foo35( T ) |
| 676 |
{ |
| 677 |
void func() { }; |
| 678 |
} |
| 679 |
|
| 680 |
void test35() |
| 681 |
{ |
| 682 |
try { |
| 683 |
alias Foo35!( Bar35 ) filter; |
| 684 |
} catch (Exception e) { |
| 685 |
printf( "Exception %.*s", cast(int)e.msg.length, e.msg.ptr ); |
| 686 |
} finally { |
| 687 |
printf( "Done0." ); |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
/**************************************/ |
| 693 |
|
| 694 |
void test36() |
| 695 |
{ |
| 696 |
enum {A=1} |
| 697 |
enum {B=A?0:1} |
| 698 |
assert(A == 1); |
| 699 |
assert(B == 0); |
| 700 |
} |
| 701 |
|
| 702 |
/**************************************/ |
| 703 |
|
| 704 |
struct A37 |
| 705 |
{ |
| 706 |
int a; |
| 707 |
} |
| 708 |
|
| 709 |
struct B37 |
| 710 |
{ |
| 711 |
int a; |
| 712 |
int b; |
| 713 |
} |
| 714 |
|
| 715 |
struct C37 |
| 716 |
{ |
| 717 |
int a; |
| 718 |
int b; |
| 719 |
int c; |
| 720 |
} |
| 721 |
|
| 722 |
struct D37 |
| 723 |
{ |
| 724 |
byte a,b,c; |
| 725 |
} |
| 726 |
|
| 727 |
void test37() |
| 728 |
{ |
| 729 |
A37 a; |
| 730 |
B37 b; |
| 731 |
C37 c; |
| 732 |
D37 d; |
| 733 |
|
| 734 |
assert(a.a == 0); |
| 735 |
assert(b.a == 0 && b.b == 0); |
| 736 |
assert(c.a == 0 && c.b == 0 && c.c == 0); |
| 737 |
assert(d.a == 0 && d.b == 0 && d.c == 0); |
| 738 |
} |
| 739 |
|
| 740 |
|
| 741 |
/**************************************/ |
| 742 |
|
| 743 |
int function() fp18; |
| 744 |
|
| 745 |
extern(Windows) int func18() |
| 746 |
{ |
| 747 |
static int otherfunc() |
| 748 |
{ return 18; } |
| 749 |
|
| 750 |
fp18 = &otherfunc; |
| 751 |
return fp18(); |
| 752 |
} |
| 753 |
|
| 754 |
void test38() |
| 755 |
{ |
| 756 |
assert(func18() == 18); |
| 757 |
} |
| 758 |
|
| 759 |
|
| 760 |
/**************************************/ |
| 761 |
|
| 762 |
class bar39 |
| 763 |
{ |
| 764 |
struct _sub |
| 765 |
{ |
| 766 |
bool a; |
| 767 |
string d; |
| 768 |
}; |
| 769 |
_sub mySub; |
| 770 |
}; |
| 771 |
|
| 772 |
class foo39 |
| 773 |
{ |
| 774 |
bar39._sub[] subArray; |
| 775 |
|
| 776 |
this(bar39[] arr) |
| 777 |
{ |
| 778 |
for(int i=0; i<arr.length; i++) |
| 779 |
subArray ~= arr[i].mySub; |
| 780 |
}; |
| 781 |
}; |
| 782 |
|
| 783 |
|
| 784 |
void test39() |
| 785 |
{ |
| 786 |
} |
| 787 |
|
| 788 |
|
| 789 |
/**************************************/ |
| 790 |
|
| 791 |
void test40() |
| 792 |
{ |
| 793 |
void* h; |
| 794 |
|
| 795 |
h = h.init; |
| 796 |
assert(h == cast(void*)0); |
| 797 |
} |
| 798 |
|
| 799 |
/**************************************/ |
| 800 |
|
| 801 |
int test41() |
| 802 |
{ |
| 803 |
label: |
| 804 |
int foo; |
| 805 |
foo = 0; |
| 806 |
return foo; |
| 807 |
} |
| 808 |
|
| 809 |
|
| 810 |
/**************************************/ |
| 811 |
|
| 812 |
struct A42 |
| 813 |
{ |
| 814 |
invariant() |
| 815 |
{ |
| 816 |
} |
| 817 |
|
| 818 |
B42 *findPool() |
| 819 |
{ |
| 820 |
return null; |
| 821 |
} |
| 822 |
|
| 823 |
} |
| 824 |
|
| 825 |
struct B42 |
| 826 |
{ |
| 827 |
int cmp(B42 *p2) |
| 828 |
{ |
| 829 |
return 0; |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
void test42() |
| 834 |
{ |
| 835 |
} |
| 836 |
|
| 837 |
|
| 838 |
/**************************************/ |
| 839 |
|
| 840 |
void test43() |
| 841 |
{ |
| 842 |
real a = 0.9; |
| 843 |
ulong b = cast(ulong) a; |
| 844 |
printf("%u", cast(uint) b); |
| 845 |
assert(cast(uint) b == 0); |
| 846 |
|
| 847 |
int c = cast(int) a; |
| 848 |
printf("%i", c); |
| 849 |
assert(c == 0); |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
/**************************************/ |
| 854 |
|
| 855 |
void test44() |
| 856 |
{ |
| 857 |
switch("asdf") |
| 858 |
{ |
| 859 |
case "asdf": |
| 860 |
printf("asdf\n"); |
| 861 |
break; |
| 862 |
|
| 863 |
|
| 864 |
case "jkl": |
| 865 |
printf("jkl\n"); |
| 866 |
assert(0); |
| 867 |
break; |
| 868 |
|
| 869 |
|
| 870 |
default: |
| 871 |
printf("default\n"); |
| 872 |
assert(0); |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
|
| 877 |
/**************************************/ |
| 878 |
|
| 879 |
void func45(string a) |
| 880 |
{ |
| 881 |
assert(a.length == 5); |
| 882 |
} |
| 883 |
|
| 884 |
void test45() |
| 885 |
{ |
| 886 |
char[5] foo; |
| 887 |
|
| 888 |
foo[] = "hello"; |
| 889 |
printf("'%.*s'\n", cast(int)foo.length, foo.ptr); |
| 890 |
func45(cast(string)foo); |
| 891 |
} |
| 892 |
|
| 893 |
/**************************************/ |
| 894 |
|
| 895 |
struct Foo46 |
| 896 |
{ |
| 897 |
int x; |
| 898 |
} |
| 899 |
|
| 900 |
void test46() |
| 901 |
{ |
| 902 |
Foo46 f; |
| 903 |
|
| 904 |
with (f) |
| 905 |
{ |
| 906 |
x = 3; |
| 907 |
} |
| 908 |
assert(f.x == 3); |
| 909 |
} |
| 910 |
|
| 911 |
/**************************************/ |
| 912 |
|
| 913 |
struct Bar48 |
| 914 |
{ |
| 915 |
uint k; |
| 916 |
ubyte m; |
| 917 |
} |
| 918 |
|
| 919 |
Bar48 makebar48() { Bar48 b; return b; } |
| 920 |
|
| 921 |
void test48() |
| 922 |
{ |
| 923 |
Bar48 b = makebar48(); |
| 924 |
} |
| 925 |
|
| 926 |
/**************************************/ |
| 927 |
|
| 928 |
void testx49() { printf("testx49()\n"); } |
| 929 |
|
| 930 |
void test49() { return testx49(); } |
| 931 |
|
| 932 |
/**************************************/ |
| 933 |
|
| 934 |
int testx50() { printf("testx50()\n"); return 3; } |
| 935 |
|
| 936 |
void test50() { return cast(void)testx50(); } |
| 937 |
|
| 938 |
/**************************************/ |
| 939 |
|
| 940 |
class A51 |
| 941 |
{ |
| 942 |
static typeof(this) foo() |
| 943 |
{ |
| 944 |
return new A51(); |
| 945 |
} |
| 946 |
|
| 947 |
this() |
| 948 |
{ |
| 949 |
bar = 3; |
| 950 |
} |
| 951 |
|
| 952 |
int bar; |
| 953 |
} |
| 954 |
|
| 955 |
class B51 : A51 |
| 956 |
{ |
| 957 |
static typeof(super) b; |
| 958 |
} |
| 959 |
|
| 960 |
struct C51 |
| 961 |
{ |
| 962 |
typeof(&this) x; |
| 963 |
} |
| 964 |
|
| 965 |
void test51() |
| 966 |
{ |
| 967 |
A51 a = A51.foo(); |
| 968 |
assert(a.bar == 3); |
| 969 |
|
| 970 |
B51.b = a; |
| 971 |
assert(B51.b.bar == 3); |
| 972 |
assert(B51.b.classinfo == A51.classinfo); |
| 973 |
|
| 974 |
C51 c; |
| 975 |
c.x = &c; |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
/**************************************/ |
| 980 |
|
| 981 |
class A52 |
| 982 |
{ |
| 983 |
char get() { return 'A'; } |
| 984 |
|
| 985 |
char foo() { return typeof(this).get(); } |
| 986 |
char bar() { return A52.get(); } |
| 987 |
} |
| 988 |
|
| 989 |
class B52 : A52 |
| 990 |
{ |
| 991 |
override char get() { return 'B'; } |
| 992 |
} |
| 993 |
|
| 994 |
void test52() |
| 995 |
{ |
| 996 |
B52 b = new B52(); |
| 997 |
|
| 998 |
assert(b.foo() == 'A'); |
| 999 |
assert(b.bar() == 'A'); |
| 1000 |
assert(b.get() == 'B'); |
| 1001 |
} |
| 1002 |
|
| 1003 |
/**************************************/ |
| 1004 |
|
| 1005 |
struct A53 |
| 1006 |
{ |
| 1007 |
int b() { return 1; } |
| 1008 |
} |
| 1009 |
|
| 1010 |
int x53() |
| 1011 |
{ |
| 1012 |
A53 a; |
| 1013 |
return a.b; |
| 1014 |
} |
| 1015 |
|
| 1016 |
void test53() |
| 1017 |
{ |
| 1018 |
assert(x53() == 1); |
| 1019 |
} |
| 1020 |
|
| 1021 |
/**************************************/ |
| 1022 |
|
| 1023 |
class A54 |
| 1024 |
{ |
| 1025 |
void a() |
| 1026 |
{ |
| 1027 |
printf("A54.a\n"); |
| 1028 |
} |
| 1029 |
|
| 1030 |
void b() |
| 1031 |
{ |
| 1032 |
typeof(this).a(); |
| 1033 |
} |
| 1034 |
} |
| 1035 |
|
| 1036 |
class B54 : A54 |
| 1037 |
{ |
| 1038 |
override void a() |
| 1039 |
{ |
| 1040 |
printf("B54.a\n"); |
| 1041 |
assert(0); |
| 1042 |
} |
| 1043 |
} |
| 1044 |
|
| 1045 |
void test54() |
| 1046 |
{ |
| 1047 |
B54 b = new B54(); |
| 1048 |
|
| 1049 |
b.b(); |
| 1050 |
} |
| 1051 |
|
| 1052 |
|
| 1053 |
/**************************************/ |
| 1054 |
|
| 1055 |
int foo55(int x = 5) |
| 1056 |
{ |
| 1057 |
printf("x = %d\n", x); |
| 1058 |
return x; |
| 1059 |
} |
| 1060 |
|
| 1061 |
void test55() |
| 1062 |
{ int i; |
| 1063 |
|
| 1064 |
i = foo55(6); |
| 1065 |
assert(i == 6); |
| 1066 |
i = foo55(); |
| 1067 |
assert(i == 5); |
| 1068 |
} |
| 1069 |
|
| 1070 |
/**************************************/ |
| 1071 |
|
| 1072 |
class A56 |
| 1073 |
{ |
| 1074 |
int foo(int x = 5) |
| 1075 |
{ |
| 1076 |
printf("A56.x = %d\n", x); |
| 1077 |
return x; |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
class B56 : A56 |
| 1082 |
{ |
| 1083 |
override int foo(int x = 7) |
| 1084 |
{ |
| 1085 |
printf("B56.x = %d\n", x); |
| 1086 |
return x; |
| 1087 |
} |
| 1088 |
} |
| 1089 |
|
| 1090 |
|
| 1091 |
void test56() |
| 1092 |
{ int i; |
| 1093 |
B56 b = new B56(); |
| 1094 |
|
| 1095 |
i = b.foo(6); |
| 1096 |
assert(i == 6); |
| 1097 |
i = b.foo(); |
| 1098 |
assert(i == 7); |
| 1099 |
} |
| 1100 |
|
| 1101 |
|
| 1102 |
/**************************************/ |
| 1103 |
|
| 1104 |
void test57() |
| 1105 |
{ |
| 1106 |
char c; |
| 1107 |
wchar w; |
| 1108 |
dchar d; |
| 1109 |
|
| 1110 |
printf("c = %x, w = %x, d = %x\n", c, w, d); |
| 1111 |
assert(c == 0xFF); |
| 1112 |
assert(w == 0xFFFF); |
| 1113 |
assert(d == 0xFFFF); |
| 1114 |
} |
| 1115 |
|
| 1116 |
/**************************************/ |
| 1117 |
|
| 1118 |
void test58() |
| 1119 |
{ |
| 1120 |
static int x; |
| 1121 |
|
| 1122 |
static class S |
| 1123 |
{ |
| 1124 |
static this() |
| 1125 |
{ |
| 1126 |
printf ("static constructor\n"); |
| 1127 |
x = 10; |
| 1128 |
} |
| 1129 |
|
| 1130 |
this() |
| 1131 |
{ |
| 1132 |
printf ("class constructor\n"); |
| 1133 |
} |
| 1134 |
} |
| 1135 |
|
| 1136 |
assert(x == 10); |
| 1137 |
new S; |
| 1138 |
} |
| 1139 |
|
| 1140 |
/**************************************/ |
| 1141 |
|
| 1142 |
struct S61 { |
| 1143 |
int a, b, c, d; |
| 1144 |
} |
| 1145 |
|
| 1146 |
void rec(int n, S61 t) |
| 1147 |
{ |
| 1148 |
if (n > 0) { |
| 1149 |
t.b++; |
| 1150 |
rec(n-1,t); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
void test61() |
| 1155 |
{ |
| 1156 |
S61 F; |
| 1157 |
|
| 1158 |
rec(100, F); |
| 1159 |
} |
| 1160 |
|
| 1161 |
/**************************************/ |
| 1162 |
|
| 1163 |
class A62 |
| 1164 |
{ |
| 1165 |
static A62 test(int q=0) { |
| 1166 |
return null; |
| 1167 |
} |
| 1168 |
} |
| 1169 |
|
| 1170 |
A62 foo62() |
| 1171 |
{ |
| 1172 |
return A62.test; |
| 1173 |
} |
| 1174 |
|
| 1175 |
void test62() |
| 1176 |
{ |
| 1177 |
foo62(); |
| 1178 |
} |
| 1179 |
|
| 1180 |
|
| 1181 |
/**************************************/ |
| 1182 |
|
| 1183 |
class A63 |
| 1184 |
{ |
| 1185 |
private import imports.std11file; |
| 1186 |
alias imports.std11file.getcwd getcwd; |
| 1187 |
} |
| 1188 |
|
| 1189 |
void test63() |
| 1190 |
{ |
| 1191 |
A63 f = new A63(); |
| 1192 |
auto s = f.getcwd(); |
| 1193 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 1194 |
} |
| 1195 |
|
| 1196 |
/**************************************/ |
| 1197 |
// https://issues.dlang.org/show_bug.cgi?id=8809 |
| 1198 |
|
| 1199 |
void test8809() |
| 1200 |
{ |
| 1201 |
static class B |
| 1202 |
{ |
| 1203 |
char foo() { return 'B'; } |
| 1204 |
} |
| 1205 |
static class C : B |
| 1206 |
{ |
| 1207 |
char test1Bx() { return B.foo(); } |
| 1208 |
char test1Cx() { return C.foo(); } |
| 1209 |
char test1Dx() { return foo(); } |
| 1210 |
char test1By() { return this.B.foo(); } |
| 1211 |
char test1Cy() { return this.C.foo(); } // cannot compile -> OK |
| 1212 |
char test1Dy() { return this. foo(); } |
| 1213 |
char test1Bz() { return typeof(super).foo(); } |
| 1214 |
char test1Cz() { return typeof(this). foo(); } |
| 1215 |
//char test1Dz(); |
| 1216 |
|
| 1217 |
char test2Bx() { return { return B.foo(); }(); } |
| 1218 |
char test2Cx() { return { return C.foo(); }(); } |
| 1219 |
char test2Dx() { return { return foo(); }(); } |
| 1220 |
char test2By() { return { return this.B.foo(); }(); } |
| 1221 |
char test2Cy() { return { return this.C.foo(); }(); } // cannot compile -> OK |
| 1222 |
char test2Dy() { return { return this. foo(); }(); } |
| 1223 |
char test2Bz() { return { return typeof(super).foo(); }(); } |
| 1224 |
char test2Cz() { return { return typeof(this). foo(); }(); } |
| 1225 |
//char test2Dz(); |
| 1226 |
|
| 1227 |
char test3Bx() { return (new class Object { char bar() { return B.foo(); } }).bar(); } |
| 1228 |
char test3Cx() { return (new class Object { char bar() { return C.foo(); } }).bar(); } |
| 1229 |
char test3Dx() { return (new class Object { char bar() { return foo(); } }).bar(); } |
| 1230 |
|
| 1231 |
override char foo() { return 'C'; } |
| 1232 |
} |
| 1233 |
static class D : C |
| 1234 |
{ |
| 1235 |
override char foo() { return 'D'; } |
| 1236 |
} |
| 1237 |
|
| 1238 |
C c = new D(); |
| 1239 |
|
| 1240 |
assert(c.test1Bx() == 'B'); |
| 1241 |
assert(c.test1Cx() == 'C'); |
| 1242 |
assert(c.test1Dx() == 'D'); |
| 1243 |
assert(c.test1By() == 'B'); |
| 1244 |
assert(c.test1Cy() == 'C'); |
| 1245 |
assert(c.test1Dy() == 'D'); |
| 1246 |
assert(c.test1Bz() == 'B'); // NG('D') -> OK |
| 1247 |
assert(c.test1Cz() == 'C'); |
| 1248 |
//assert(c.test1Dz() == 'D'); |
| 1249 |
|
| 1250 |
assert(c.test2Bx() == 'B'); // NG('D') -> OK |
| 1251 |
assert(c.test2Cx() == 'C'); // NG('D') -> OK |
| 1252 |
assert(c.test2Dx() == 'D'); |
| 1253 |
assert(c.test2By() == 'B'); |
| 1254 |
assert(c.test2Cy() == 'C'); |
| 1255 |
assert(c.test2Dy() == 'D'); |
| 1256 |
assert(c.test2Bz() == 'B'); // NG('D') -> OK |
| 1257 |
assert(c.test2Cz() == 'C'); // NG('D') -> OK |
| 1258 |
//assert(c.test2Dz() == 'D'); |
| 1259 |
|
| 1260 |
assert(c.test3Bx() == 'B'); // NG('D') -> OK |
| 1261 |
assert(c.test3Cx() == 'C'); // NG('D') -> OK |
| 1262 |
assert(c.test3Dx() == 'D'); |
| 1263 |
} |
| 1264 |
|
| 1265 |
/**************************************/ |
| 1266 |
// https://issues.dlang.org/show_bug.cgi?id=9734 |
| 1267 |
|
| 1268 |
void test9734() |
| 1269 |
{ |
| 1270 |
class C {} |
| 1271 |
class D : C |
| 1272 |
{ |
| 1273 |
static bool test(C) { return true; } |
| 1274 |
|
| 1275 |
void foo()() if (is(typeof(test(super)))) {} |
| 1276 |
void bar()() if (is(typeof(super) == C)) {} |
| 1277 |
} |
| 1278 |
void baz()() if (is(typeof(super))) {} |
| 1279 |
|
| 1280 |
auto d = new D(); |
| 1281 |
d.foo(); |
| 1282 |
d.bar(); |
| 1283 |
static assert(!__traits(compiles, baz())); |
| 1284 |
} |
| 1285 |
|
| 1286 |
/**************************************/ |
| 1287 |
|
| 1288 |
int main(string[] argv) |
| 1289 |
{ |
| 1290 |
test1(); |
| 1291 |
test2(); |
| 1292 |
test3(); |
| 1293 |
test4(); |
| 1294 |
test6(); |
| 1295 |
test7(); |
| 1296 |
test8(); |
| 1297 |
test9(); |
| 1298 |
test10(); |
| 1299 |
test11(); |
| 1300 |
test12(); |
| 1301 |
test13(); |
| 1302 |
test14(); |
| 1303 |
test15(); |
| 1304 |
test16(); |
| 1305 |
test17(); |
| 1306 |
test18(); |
| 1307 |
test19(); |
| 1308 |
test20(); |
| 1309 |
test21(); |
| 1310 |
test22(); |
| 1311 |
test23(); |
| 1312 |
test24(); |
| 1313 |
test25(); |
| 1314 |
test26(); |
| 1315 |
test27(); |
| 1316 |
test28(); |
| 1317 |
test29(); |
| 1318 |
test30(); |
| 1319 |
test31(); |
| 1320 |
test32(); |
| 1321 |
test33(); |
| 1322 |
test34(); |
| 1323 |
test35(); |
| 1324 |
test36(); |
| 1325 |
test37(); |
| 1326 |
test38(); |
| 1327 |
test39(); |
| 1328 |
test40(); |
| 1329 |
test41(); |
| 1330 |
test42(); |
| 1331 |
test43(); |
| 1332 |
test44(); |
| 1333 |
test45(); |
| 1334 |
test46(); |
| 1335 |
test48(); |
| 1336 |
test49(); |
| 1337 |
test50(); |
| 1338 |
test51(); |
| 1339 |
test52(); |
| 1340 |
test53(); |
| 1341 |
test54(); |
| 1342 |
test55(); |
| 1343 |
test56(); |
| 1344 |
test57(); |
| 1345 |
test58(); |
| 1346 |
test61(); |
| 1347 |
test62(); |
| 1348 |
test63(); |
| 1349 |
test8809(); |
| 1350 |
test9734(); |
| 1351 |
|
| 1352 |
printf("Success\n"); |
| 1353 |
return 0; |
| 1354 |
} |