| 1 |
module test; |
| 2 |
|
| 3 |
import core.stdc.stdio; |
| 4 |
import core.vararg; |
| 5 |
|
| 6 |
/*******************************************/ |
| 7 |
|
| 8 |
struct S1 |
| 9 |
{ |
| 10 |
void* function(void*) fn; |
| 11 |
} |
| 12 |
|
| 13 |
template M1() |
| 14 |
{ |
| 15 |
S1 s; |
| 16 |
} |
| 17 |
|
| 18 |
void test1() |
| 19 |
{ |
| 20 |
S1 s2; |
| 21 |
mixin M1; |
| 22 |
assert(s.fn == null); |
| 23 |
} |
| 24 |
|
| 25 |
/*******************************************/ |
| 26 |
|
| 27 |
enum Qwert { yuiop } |
| 28 |
|
| 29 |
int asdfg(Qwert hjkl) { return 1; } |
| 30 |
int asdfg(uint zxcvb) { return 2; } |
| 31 |
|
| 32 |
void test2() |
| 33 |
{ |
| 34 |
int nm = 2; |
| 35 |
|
| 36 |
assert(asdfg(nm) == 2); |
| 37 |
assert(asdfg(cast(int) nm) == 2); |
| 38 |
assert(asdfg(3) == 2); |
| 39 |
assert(asdfg(cast(int) 3) == 2); |
| 40 |
assert(asdfg(3L) == 2); |
| 41 |
assert(asdfg(cast(int) 3L) == 2); |
| 42 |
assert(asdfg(3 + 2) == 2); |
| 43 |
assert(asdfg(cast(int) (3 + 2)) == 2); |
| 44 |
assert(asdfg(nm + 2) == 2); |
| 45 |
assert(asdfg(cast(int) (nm + 2)) == 2); |
| 46 |
assert(asdfg(3 + nm) == 2); |
| 47 |
assert(asdfg(cast(int) (3 + nm)) == 2); |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
/*******************************************/ |
| 52 |
|
| 53 |
template Qwert3(string yuiop) { |
| 54 |
immutable string Qwert3 = cast(string)yuiop; |
| 55 |
} |
| 56 |
|
| 57 |
template Asdfg3(string yuiop) { |
| 58 |
immutable string Asdfg3 = cast(string)Qwert3!(cast(string)(cast(string)yuiop ~ cast(string)"hjkl")); |
| 59 |
} |
| 60 |
|
| 61 |
void test3() |
| 62 |
{ |
| 63 |
string zxcvb = Asdfg3!(null); |
| 64 |
assert(zxcvb == "hjkl"); |
| 65 |
assert(zxcvb == "hjkl" ~ null); |
| 66 |
} |
| 67 |
|
| 68 |
/*******************************************/ |
| 69 |
|
| 70 |
template Qwert4(string yuiop) |
| 71 |
{ |
| 72 |
immutable string Qwert4 = cast(string)(yuiop ~ "asdfg" ~ yuiop); |
| 73 |
} |
| 74 |
|
| 75 |
void test4() |
| 76 |
{ |
| 77 |
string hjkl = Qwert4!(null); |
| 78 |
assert(hjkl == "asdfg"); |
| 79 |
} |
| 80 |
|
| 81 |
/*******************************************/ |
| 82 |
|
| 83 |
void test6() |
| 84 |
{ |
| 85 |
struct Foo |
| 86 |
{ |
| 87 |
void foo() { } |
| 88 |
} |
| 89 |
|
| 90 |
alias Foo Bar; |
| 91 |
|
| 92 |
Bar a; |
| 93 |
a.foo(); |
| 94 |
} |
| 95 |
|
| 96 |
/*******************************************/ |
| 97 |
|
| 98 |
void test7() |
| 99 |
{ |
| 100 |
struct Foo |
| 101 |
{ |
| 102 |
alias typeof(this) ThisType; |
| 103 |
alias typeof(this) ThatType; |
| 104 |
} |
| 105 |
|
| 106 |
assert(is(Foo.ThisType == Foo)); |
| 107 |
assert(is(Foo.ThatType == Foo)); |
| 108 |
} |
| 109 |
|
| 110 |
/*******************************************/ |
| 111 |
|
| 112 |
void test8() |
| 113 |
{ |
| 114 |
int[] test; |
| 115 |
test.length = 10; |
| 116 |
assert(test.length == 10); |
| 117 |
assert(test.ptr != null); |
| 118 |
|
| 119 |
test.length = 1; |
| 120 |
assert(test.length == 1); |
| 121 |
assert(test.ptr != null); |
| 122 |
|
| 123 |
test.length = 8; |
| 124 |
assert(test.length == 8); |
| 125 |
assert(test.ptr != null); |
| 126 |
|
| 127 |
test.length = 0; |
| 128 |
assert(test.length == 0); |
| 129 |
assert(test.ptr != null); |
| 130 |
} |
| 131 |
|
| 132 |
/*******************************************/ |
| 133 |
|
| 134 |
class CBase10 |
| 135 |
{ |
| 136 |
this() { } |
| 137 |
} |
| 138 |
|
| 139 |
void foo10( CBase10 l ) |
| 140 |
{ |
| 141 |
} |
| 142 |
|
| 143 |
void test10() |
| 144 |
{ |
| 145 |
if (1) |
| 146 |
{ |
| 147 |
foo10( new class() CBase10 |
| 148 |
{ |
| 149 |
this() { super(); } |
| 150 |
} |
| 151 |
); |
| 152 |
} |
| 153 |
return; |
| 154 |
} |
| 155 |
|
| 156 |
/*******************************************/ |
| 157 |
|
| 158 |
struct Foo11 |
| 159 |
{ |
| 160 |
static |
| 161 |
int func(T)(T a) { assert(a == 1); return 0; } |
| 162 |
} |
| 163 |
|
| 164 |
void test11() |
| 165 |
{ |
| 166 |
auto a = Foo11.init.func(1); |
| 167 |
a = Foo11.init.func!(int)(1); |
| 168 |
a = Foo11.func(1); |
| 169 |
a = Foo11.func!(int)(1); |
| 170 |
} |
| 171 |
|
| 172 |
/*******************************************/ |
| 173 |
|
| 174 |
void test12() |
| 175 |
{ |
| 176 |
class ExceptioN { } |
| 177 |
|
| 178 |
class ExceptioX { } |
| 179 |
|
| 180 |
static assert(ExceptioN.mangleof[0 ..$-1] == ExceptioX.mangleof[0 .. $-1]); |
| 181 |
} |
| 182 |
|
| 183 |
/*******************************************/ |
| 184 |
|
| 185 |
template check( char ch1, char ch2) |
| 186 |
{ |
| 187 |
const bool check = ch1 == ch2; |
| 188 |
} |
| 189 |
|
| 190 |
void test13() |
| 191 |
{ |
| 192 |
const char[] s = "123+456" ; |
| 193 |
assert(check!( '+', s[3] ) == true); |
| 194 |
} |
| 195 |
|
| 196 |
/*******************************************/ |
| 197 |
|
| 198 |
void test14() |
| 199 |
{ |
| 200 |
static const char[] test=['a','b','c','d']; |
| 201 |
static assert(test==['a','b','c','d']); |
| 202 |
static assert(['a','b','c','d']== test); |
| 203 |
} |
| 204 |
|
| 205 |
/*******************************************/ |
| 206 |
|
| 207 |
void func15(...) |
| 208 |
in { |
| 209 |
printf("Arguments len = %d\n", cast(int)_arguments.length); |
| 210 |
assert(_arguments.length == 2); |
| 211 |
} |
| 212 |
do { |
| 213 |
|
| 214 |
} |
| 215 |
|
| 216 |
void test15() |
| 217 |
{ |
| 218 |
func15(1, 2); |
| 219 |
} |
| 220 |
|
| 221 |
/*******************************************/ |
| 222 |
|
| 223 |
void test17() |
| 224 |
{ |
| 225 |
void delegate() y = { }; |
| 226 |
y(); |
| 227 |
} |
| 228 |
|
| 229 |
/*******************************************/ |
| 230 |
|
| 231 |
abstract class Pen { int foo(); } |
| 232 |
|
| 233 |
class Penfold : Pen { |
| 234 |
override int foo() { return 1; } |
| 235 |
} |
| 236 |
|
| 237 |
class Pinky : Pen { |
| 238 |
override int foo() { return 2; } |
| 239 |
} |
| 240 |
|
| 241 |
class Printer { |
| 242 |
void vprint(Pen obj) { |
| 243 |
assert(obj.foo() == 1 || obj.foo() == 2); |
| 244 |
} |
| 245 |
|
| 246 |
C print(C)(C obj) { |
| 247 |
assert(obj.foo() == 1 || obj.foo() == 2); |
| 248 |
return obj; |
| 249 |
} |
| 250 |
|
| 251 |
} |
| 252 |
|
| 253 |
void test18() |
| 254 |
{ |
| 255 |
Printer p = new Printer; |
| 256 |
p.print(new Pinky); |
| 257 |
p.print(new Penfold); |
| 258 |
with (p) |
| 259 |
{ |
| 260 |
vprint(new Pinky); |
| 261 |
vprint(new Penfold); |
| 262 |
|
| 263 |
print!(Pinky)(new Pinky); |
| 264 |
print!(Penfold)(new Penfold); |
| 265 |
|
| 266 |
p.print(new Pinky); |
| 267 |
p.print(new Penfold); |
| 268 |
|
| 269 |
print(new Pinky); |
| 270 |
print(new Penfold); |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
/*******************************************/ |
| 275 |
|
| 276 |
|
| 277 |
class A19 |
| 278 |
{ |
| 279 |
void s() {} |
| 280 |
} |
| 281 |
|
| 282 |
class B19 : A19 |
| 283 |
{ |
| 284 |
alias A19.s s; |
| 285 |
static void s(int i) {} |
| 286 |
override void s() {} |
| 287 |
} |
| 288 |
|
| 289 |
class C19 |
| 290 |
{ |
| 291 |
void f() { |
| 292 |
B19.s(0); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
void test19() |
| 297 |
{ |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
/*******************************************/ |
| 302 |
|
| 303 |
class U {} |
| 304 |
class T : U {} |
| 305 |
|
| 306 |
void test20() |
| 307 |
{ |
| 308 |
T* ptr; |
| 309 |
T[2] sar; |
| 310 |
T[] dar; |
| 311 |
|
| 312 |
// all of the following should work according to the "Implicit |
| 313 |
// Conversions" section of the spec |
| 314 |
|
| 315 |
tPtr(ptr); |
| 316 |
tPtr(sar.ptr); |
| 317 |
tPtr(dar.ptr); |
| 318 |
tDar(sar); |
| 319 |
|
| 320 |
// uPtr(ptr); // T* => U* |
| 321 |
// uPtr(sar); // T[2] => U* |
| 322 |
// uPtr(dar); // T[] => U* |
| 323 |
// uSar(sar); // T[2] => U[2] |
| 324 |
// uDar(sar); // T[2] => U[] |
| 325 |
|
| 326 |
uDar(dar); // T[] => const(U)[] |
| 327 |
vPtr(ptr); // T* => void* |
| 328 |
vPtr(sar.ptr); |
| 329 |
vPtr(dar.ptr); |
| 330 |
|
| 331 |
vDar(sar); |
| 332 |
vDar(dar); // works, but T[] => void[] isn't mentioned in the spec |
| 333 |
} |
| 334 |
|
| 335 |
void tPtr(T*t){} |
| 336 |
void tDar(T[]t){} |
| 337 |
void uPtr(U*u){} |
| 338 |
void uSar(U[2]u){} |
| 339 |
void uDar(const(U)[]u){} |
| 340 |
void vPtr(void*v){} |
| 341 |
void vDar(void[]v){} |
| 342 |
|
| 343 |
|
| 344 |
/*******************************************/ |
| 345 |
|
| 346 |
struct Foo21 |
| 347 |
{ |
| 348 |
int i; |
| 349 |
} |
| 350 |
|
| 351 |
template some_struct_instance(T) |
| 352 |
{ |
| 353 |
static Foo21 some_struct_instance = |
| 354 |
{ |
| 355 |
5, |
| 356 |
}; |
| 357 |
} |
| 358 |
|
| 359 |
void test21() |
| 360 |
{ |
| 361 |
alias some_struct_instance!(int) inst; |
| 362 |
assert(inst.i == 5); |
| 363 |
} |
| 364 |
|
| 365 |
/*******************************************/ |
| 366 |
|
| 367 |
struct Foo22(T) {} |
| 368 |
|
| 369 |
void test22() |
| 370 |
{ |
| 371 |
int i; |
| 372 |
|
| 373 |
if ((Foo22!(char)).init == (Foo22!(char)).init) |
| 374 |
i = 1; |
| 375 |
assert(i == 1); |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
/*******************************************/ |
| 380 |
|
| 381 |
void test23() |
| 382 |
{ |
| 383 |
auto t=['a','b','c','d']; |
| 384 |
assert(is(typeof(t) == char[])); |
| 385 |
|
| 386 |
const t2=['a','b','c','d','e']; |
| 387 |
assert(is(typeof(t2) == const(const(char)[]))); |
| 388 |
} |
| 389 |
|
| 390 |
/*******************************************/ |
| 391 |
|
| 392 |
int foo24(int i ...) |
| 393 |
{ |
| 394 |
return i; |
| 395 |
} |
| 396 |
|
| 397 |
void test24() |
| 398 |
{ |
| 399 |
assert(foo24(3) == 3); |
| 400 |
} |
| 401 |
|
| 402 |
/*******************************************/ |
| 403 |
|
| 404 |
struct Foo26 |
| 405 |
{ |
| 406 |
int a; |
| 407 |
|
| 408 |
static Foo26 opCall(int i) |
| 409 |
{ Foo26 f; |
| 410 |
f.a += i; |
| 411 |
return f; |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
void test26() |
| 416 |
{ Foo26 f; |
| 417 |
|
| 418 |
f = cast(Foo26)3; |
| 419 |
assert(f.a == 3); |
| 420 |
|
| 421 |
Foo26 g = 3; |
| 422 |
assert(g.a == 3); |
| 423 |
} |
| 424 |
|
| 425 |
/*******************************************/ |
| 426 |
|
| 427 |
struct S27 |
| 428 |
{ |
| 429 |
int x; |
| 430 |
|
| 431 |
void opAssign(int i) |
| 432 |
{ |
| 433 |
x = i + 1; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
void test27() |
| 438 |
{ |
| 439 |
S27 s; |
| 440 |
s = 1; |
| 441 |
assert(s.x == 2); |
| 442 |
} |
| 443 |
|
| 444 |
/*******************************************/ |
| 445 |
|
| 446 |
class C28 |
| 447 |
{ |
| 448 |
int x; |
| 449 |
|
| 450 |
void opAssign(int i) |
| 451 |
{ |
| 452 |
x = i + 1; |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
void test28() |
| 457 |
{ |
| 458 |
// No longer supported for 2.0 |
| 459 |
// C28 s = new C28; |
| 460 |
// s = 1; |
| 461 |
// assert(s.x == 2); |
| 462 |
} |
| 463 |
|
| 464 |
/*******************************************/ |
| 465 |
|
| 466 |
struct S29 |
| 467 |
{ |
| 468 |
static S29 opCall(int v) |
| 469 |
{ |
| 470 |
S29 result; |
| 471 |
result.v = v; |
| 472 |
return result; |
| 473 |
} |
| 474 |
int a; |
| 475 |
int v; |
| 476 |
int x,y,z; |
| 477 |
} |
| 478 |
|
| 479 |
int foo29() |
| 480 |
{ |
| 481 |
auto s = S29(5); |
| 482 |
return s.v; |
| 483 |
} |
| 484 |
|
| 485 |
void test29() |
| 486 |
{ |
| 487 |
int i = foo29(); |
| 488 |
printf("%d\n", i); |
| 489 |
assert(i == 5); |
| 490 |
} |
| 491 |
|
| 492 |
/*******************************************/ |
| 493 |
|
| 494 |
struct S30 |
| 495 |
{ |
| 496 |
static S30 opCall(int v) |
| 497 |
{ |
| 498 |
S30 result; |
| 499 |
|
| 500 |
void bar() |
| 501 |
{ |
| 502 |
result.v += 1; |
| 503 |
} |
| 504 |
|
| 505 |
result.v = v; |
| 506 |
bar(); |
| 507 |
return result; |
| 508 |
} |
| 509 |
int a; |
| 510 |
int v; |
| 511 |
int x,y,z; |
| 512 |
} |
| 513 |
|
| 514 |
int foo30() |
| 515 |
{ |
| 516 |
auto s = S30(5); |
| 517 |
return s.v; |
| 518 |
} |
| 519 |
|
| 520 |
void test30() |
| 521 |
{ |
| 522 |
int i = foo30(); |
| 523 |
printf("%d\n", i); |
| 524 |
assert(i == 6); |
| 525 |
} |
| 526 |
|
| 527 |
/*******************************************/ |
| 528 |
|
| 529 |
struct S31 |
| 530 |
{ |
| 531 |
static void abc(S31 *r) |
| 532 |
{ |
| 533 |
r.v += 1; |
| 534 |
} |
| 535 |
|
| 536 |
static S31 opCall(int v) |
| 537 |
{ |
| 538 |
S31 result; |
| 539 |
|
| 540 |
void bar() |
| 541 |
{ |
| 542 |
abc(&result); |
| 543 |
} |
| 544 |
|
| 545 |
result.v = v; |
| 546 |
bar(); |
| 547 |
return result; |
| 548 |
} |
| 549 |
int a; |
| 550 |
int v; |
| 551 |
int x,y,z; |
| 552 |
} |
| 553 |
|
| 554 |
int foo31() |
| 555 |
{ |
| 556 |
auto s = S31(5); |
| 557 |
return s.v; |
| 558 |
} |
| 559 |
|
| 560 |
void test31() |
| 561 |
{ |
| 562 |
int i = foo31(); |
| 563 |
printf("%d\n", i); |
| 564 |
assert(i == 6); |
| 565 |
} |
| 566 |
|
| 567 |
/*******************************************/ |
| 568 |
|
| 569 |
|
| 570 |
struct T32 |
| 571 |
{ |
| 572 |
int opApply(int delegate(ref int i) dg) |
| 573 |
{ |
| 574 |
int i; |
| 575 |
return dg(i); |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
struct S32 |
| 580 |
{ |
| 581 |
static void abc(S32 *r) |
| 582 |
{ |
| 583 |
r.v += 1; |
| 584 |
} |
| 585 |
|
| 586 |
static S32 opCall(int v) |
| 587 |
{ |
| 588 |
S32 result; |
| 589 |
T32 t; |
| 590 |
|
| 591 |
result.v = v; |
| 592 |
foreach (i; t) |
| 593 |
{ |
| 594 |
result.v += 1; |
| 595 |
break; |
| 596 |
} |
| 597 |
return result; |
| 598 |
} |
| 599 |
int a; |
| 600 |
int v; |
| 601 |
int x,y,z; |
| 602 |
} |
| 603 |
|
| 604 |
int foo32() |
| 605 |
{ |
| 606 |
auto s = S32(5); |
| 607 |
return s.v; |
| 608 |
} |
| 609 |
|
| 610 |
void test32() |
| 611 |
{ |
| 612 |
int i = foo32(); |
| 613 |
printf("%d\n", i); |
| 614 |
assert(i == 6); |
| 615 |
} |
| 616 |
|
| 617 |
/*******************************************/ |
| 618 |
|
| 619 |
class Confectionary |
| 620 |
{ |
| 621 |
this(int sugar) |
| 622 |
{ |
| 623 |
//if (sugar < 500) |
| 624 |
// tastiness = 200; |
| 625 |
|
| 626 |
//for (int i = 0; i < 10; ++i) |
| 627 |
// tastiness = 300; |
| 628 |
|
| 629 |
//int[] tastinesses_array; |
| 630 |
|
| 631 |
//foreach (n; tastinesses_array) |
| 632 |
// tastiness = n; |
| 633 |
|
| 634 |
//int[int] tastinesses_aa; |
| 635 |
|
| 636 |
//foreach (n; tastinesses_aa) |
| 637 |
// tastiness = n; |
| 638 |
|
| 639 |
tastiness = 1; |
| 640 |
} |
| 641 |
|
| 642 |
const int tastiness; |
| 643 |
} |
| 644 |
|
| 645 |
void test33() |
| 646 |
{ |
| 647 |
} |
| 648 |
|
| 649 |
/*******************************************/ |
| 650 |
|
| 651 |
template a34(string name, T...) |
| 652 |
{ |
| 653 |
string a34(string name,T t) |
| 654 |
{ |
| 655 |
string localchar; |
| 656 |
foreach (a34; T) |
| 657 |
{ |
| 658 |
localchar ~= a34.mangleof; |
| 659 |
} |
| 660 |
return localchar; |
| 661 |
} |
| 662 |
} |
| 663 |
|
| 664 |
void test34() |
| 665 |
{ |
| 666 |
assert(a34!("Adf"[], typeof("adf"),uint)("Adf"[],"adf",1234) == "Ayak"); |
| 667 |
} |
| 668 |
|
| 669 |
/*******************************************/ |
| 670 |
|
| 671 |
template a35(string name, T...) |
| 672 |
{ |
| 673 |
int a35(M...)(M m) |
| 674 |
{ |
| 675 |
return 3; |
| 676 |
} |
| 677 |
} |
| 678 |
|
| 679 |
void test35() |
| 680 |
{ |
| 681 |
assert(a35!("adf")() == 3); |
| 682 |
} |
| 683 |
|
| 684 |
/*******************************************/ |
| 685 |
|
| 686 |
template a36(AnotherT,string name,T...){ |
| 687 |
AnotherT a36(M...)(M){ |
| 688 |
AnotherT localchar; |
| 689 |
foreach(a;T) |
| 690 |
{ |
| 691 |
localchar~=a.mangleof; |
| 692 |
} |
| 693 |
return cast(AnotherT)localchar; |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
void test36() |
| 698 |
{ |
| 699 |
string b="adf"; |
| 700 |
uint i=123; |
| 701 |
char[3] c="Adf"; |
| 702 |
assert(a36!(typeof(b),"Adf")() == ""); |
| 703 |
} |
| 704 |
|
| 705 |
/*******************************************/ |
| 706 |
|
| 707 |
struct Q37 { |
| 708 |
Y37 opCast() { |
| 709 |
return Y37.init; |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
struct Y37 { |
| 714 |
Q37 asdfg() { |
| 715 |
return Q37.init; |
| 716 |
} |
| 717 |
|
| 718 |
void hjkl() { |
| 719 |
Q37 zxcvb = asdfg(); // line 13 |
| 720 |
} |
| 721 |
} |
| 722 |
|
| 723 |
void test37() |
| 724 |
{ |
| 725 |
} |
| 726 |
|
| 727 |
/*******************************************/ |
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
class C38 { } |
| 732 |
|
| 733 |
const(Object)[] foo38(C38[3] c) @system |
| 734 |
{ const(Object)[] x = c; |
| 735 |
return x; |
| 736 |
} |
| 737 |
|
| 738 |
void test38() |
| 739 |
{ |
| 740 |
} |
| 741 |
|
| 742 |
/*******************************************/ |
| 743 |
|
| 744 |
void test39() |
| 745 |
{ |
| 746 |
void print(string[] strs) |
| 747 |
{ |
| 748 |
assert(strs == ["Matt", "Andrew"]); |
| 749 |
} |
| 750 |
|
| 751 |
print(["Matt", "Andrew"]); |
| 752 |
} |
| 753 |
|
| 754 |
/*******************************************/ |
| 755 |
|
| 756 |
void test40() |
| 757 |
{ |
| 758 |
class C |
| 759 |
{ |
| 760 |
Object propName() |
| 761 |
{ |
| 762 |
return this; |
| 763 |
} |
| 764 |
} |
| 765 |
|
| 766 |
auto c = new C; |
| 767 |
|
| 768 |
with (c.propName) |
| 769 |
{ |
| 770 |
assert(toString() == "test.test40.C"); |
| 771 |
} |
| 772 |
|
| 773 |
auto foo = c.propName; |
| 774 |
} |
| 775 |
|
| 776 |
/*******************************************/ |
| 777 |
|
| 778 |
void test41() |
| 779 |
{ |
| 780 |
auto test = new char [2]; |
| 781 |
|
| 782 |
int x1, x2, x3; |
| 783 |
char[] foo1() { x1++; return test; } |
| 784 |
int foo2() { x2++; return 0; } |
| 785 |
int foo3() { x3++; return 1; } |
| 786 |
|
| 787 |
test [] = 'a'; |
| 788 |
test = test [0 .. 1]; |
| 789 |
|
| 790 |
foo1() [foo2() .. foo3()] = 'b'; |
| 791 |
assert(x1 == 1); |
| 792 |
assert(x2 == 1); |
| 793 |
assert(x3 == 1); |
| 794 |
|
| 795 |
//test [0 .. 2] = 'b'; // this line should assert |
| 796 |
assert(test.ptr[0 .. 2] == "ba"); |
| 797 |
} |
| 798 |
|
| 799 |
/*******************************************/ |
| 800 |
|
| 801 |
void test42() |
| 802 |
{ |
| 803 |
struct X { int x; } |
| 804 |
|
| 805 |
X x; |
| 806 |
assert(x.x == 0); |
| 807 |
x = x.init; |
| 808 |
assert(x.x == 0); |
| 809 |
} |
| 810 |
|
| 811 |
/*******************************************/ |
| 812 |
|
| 813 |
void vararg43(string fmt, ...) |
| 814 |
{ |
| 815 |
assert(_arguments[0] is typeid(const string)); |
| 816 |
assert(va_arg!(const string)(_argptr) == "hello"); |
| 817 |
} |
| 818 |
|
| 819 |
struct A43 |
| 820 |
{ |
| 821 |
static const MY_CONST_STRING = "hello"; |
| 822 |
|
| 823 |
void foo() |
| 824 |
{ |
| 825 |
// This will either print garbage or throw a UTF exception. |
| 826 |
// But if never_called() is commented out, then it will work. |
| 827 |
vararg43("%s", MY_CONST_STRING); |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
void never_called43() |
| 832 |
{ |
| 833 |
// This can be anything; there just needs to be a reference to |
| 834 |
// A43.MY_CONST_STRING somewhere. |
| 835 |
vararg43("%s", A43.MY_CONST_STRING); |
| 836 |
} |
| 837 |
|
| 838 |
void test43() |
| 839 |
{ |
| 840 |
A43 a; |
| 841 |
a.foo(); |
| 842 |
} |
| 843 |
|
| 844 |
/*******************************************/ |
| 845 |
|
| 846 |
void vararg44(string fmt, ...) |
| 847 |
{ |
| 848 |
assert(_arguments[0] is typeid(const string)); |
| 849 |
assert(va_arg!(const string)(_argptr) == "hello"); |
| 850 |
} |
| 851 |
|
| 852 |
class A44 |
| 853 |
{ |
| 854 |
static const MY_CONST_STRING = "hello"; |
| 855 |
|
| 856 |
this() |
| 857 |
{ |
| 858 |
// This will either print garbage or throw a UTF exception. |
| 859 |
// But if never_called() is commented out, then it will work. |
| 860 |
vararg44("%s", MY_CONST_STRING); |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
void never_called44() |
| 865 |
{ |
| 866 |
// This can be anything; there just needs to be a reference to |
| 867 |
// A44.MY_CONST_STRING somewhere. |
| 868 |
vararg44("%s", A44.MY_CONST_STRING); |
| 869 |
} |
| 870 |
|
| 871 |
void test44() |
| 872 |
{ |
| 873 |
A44 a = new A44(); |
| 874 |
} |
| 875 |
|
| 876 |
/*******************************************/ |
| 877 |
|
| 878 |
class C45 |
| 879 |
{ |
| 880 |
void func(lazy size_t x) |
| 881 |
{ |
| 882 |
(new C45).func(super.toHash()); |
| 883 |
} |
| 884 |
} |
| 885 |
|
| 886 |
void test45() |
| 887 |
{ |
| 888 |
} |
| 889 |
|
| 890 |
/*******************************************/ |
| 891 |
|
| 892 |
template T46(double v) |
| 893 |
{ |
| 894 |
double T46 = v; |
| 895 |
} |
| 896 |
|
| 897 |
void test46() |
| 898 |
{ |
| 899 |
double g = T46!(double.nan) + T46!(-double.nan); |
| 900 |
} |
| 901 |
|
| 902 |
/*******************************************/ |
| 903 |
|
| 904 |
void test47() |
| 905 |
{ |
| 906 |
uint* where = (new uint[](5)).ptr; |
| 907 |
|
| 908 |
where[0 .. 5] = 1; |
| 909 |
assert(where[2] == 1); |
| 910 |
where[0 .. 0] = 0; |
| 911 |
assert(where[0] == 1); |
| 912 |
assert(where[2] == 1); |
| 913 |
} |
| 914 |
|
| 915 |
/*******************************************/ |
| 916 |
|
| 917 |
void test48() |
| 918 |
{ |
| 919 |
Object o = new Object(); |
| 920 |
printf("%.*s\n", cast(int)typeof(o).classinfo.name.length, typeof(o).classinfo.name.ptr); |
| 921 |
printf("%.*s\n", cast(int)(typeof(o)).classinfo.name.length, (typeof(o)).classinfo.name.ptr); |
| 922 |
printf("%.*s\n", cast(int)(Object).classinfo.name.length, (Object).classinfo.name.ptr); |
| 923 |
} |
| 924 |
|
| 925 |
/*******************************************/ |
| 926 |
|
| 927 |
void test49() |
| 928 |
{ |
| 929 |
foo49(); |
| 930 |
} |
| 931 |
|
| 932 |
void foo49() |
| 933 |
{ |
| 934 |
char[] bar; |
| 935 |
assert(true, bar ~ "foo"); |
| 936 |
} |
| 937 |
|
| 938 |
/*******************************************/ |
| 939 |
|
| 940 |
void test50() |
| 941 |
{ |
| 942 |
foo50("foo"); |
| 943 |
} |
| 944 |
|
| 945 |
void foo50(string bar) |
| 946 |
{ |
| 947 |
assert(true, bar ~ "foo"); |
| 948 |
} |
| 949 |
|
| 950 |
/*******************************************/ |
| 951 |
|
| 952 |
struct Foo51 |
| 953 |
{ |
| 954 |
static Foo51 opCall() |
| 955 |
{ |
| 956 |
return Foo51.init; |
| 957 |
} |
| 958 |
private char[] _a; |
| 959 |
private bool _b; |
| 960 |
} |
| 961 |
|
| 962 |
void test51() |
| 963 |
{ |
| 964 |
} |
| 965 |
|
| 966 |
/*******************************************/ |
| 967 |
|
| 968 |
template A52(T ...) { } |
| 969 |
mixin A52!(["abc2", "def"]); |
| 970 |
|
| 971 |
void test52() |
| 972 |
{ |
| 973 |
} |
| 974 |
|
| 975 |
/*******************************************/ |
| 976 |
|
| 977 |
enum: int |
| 978 |
{ |
| 979 |
AF_INET53 = 2, |
| 980 |
PF_INET53 = AF_INET53, |
| 981 |
} |
| 982 |
|
| 983 |
enum: int |
| 984 |
{ |
| 985 |
SOCK_STREAM53 = 1, |
| 986 |
} |
| 987 |
|
| 988 |
struct sockaddr_in53 |
| 989 |
{ |
| 990 |
int sin_family = AF_INET53; |
| 991 |
} |
| 992 |
|
| 993 |
enum AddressFamily53: int |
| 994 |
{ |
| 995 |
INET = AF_INET53, |
| 996 |
} |
| 997 |
|
| 998 |
enum SocketType53: int |
| 999 |
{ |
| 1000 |
STREAM = SOCK_STREAM53, |
| 1001 |
} |
| 1002 |
|
| 1003 |
|
| 1004 |
class Socket53 |
| 1005 |
{ |
| 1006 |
this(AddressFamily53 af, SocketType53 type) |
| 1007 |
{ |
| 1008 |
} |
| 1009 |
} |
| 1010 |
|
| 1011 |
void test53() |
| 1012 |
{ |
| 1013 |
new Socket53(AddressFamily53.INET, SocketType53.STREAM); |
| 1014 |
} |
| 1015 |
|
| 1016 |
/*******************************************/ |
| 1017 |
|
| 1018 |
void test54() |
| 1019 |
{ |
| 1020 |
int[2][] a; |
| 1021 |
a ~= [1,2]; |
| 1022 |
assert(a.length == 1); |
| 1023 |
assert(a[0][0] == 1); |
| 1024 |
assert(a[0][1] == 2); |
| 1025 |
} |
| 1026 |
|
| 1027 |
/*******************************************/ |
| 1028 |
|
| 1029 |
void test55() |
| 1030 |
{ |
| 1031 |
float[][] a = new float [][](1, 1); |
| 1032 |
|
| 1033 |
if((a.length != 1) || (a[0].length != 1)){ |
| 1034 |
assert(0); |
| 1035 |
} |
| 1036 |
if (a[0][0] == a[0][0]){ |
| 1037 |
assert(0); |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
/*******************************************/ |
| 1042 |
|
| 1043 |
void test58() |
| 1044 |
{ |
| 1045 |
struct S |
| 1046 |
{ |
| 1047 |
int i; |
| 1048 |
int[4] bar = 4; |
| 1049 |
float[4] abc; |
| 1050 |
} |
| 1051 |
|
| 1052 |
static S a = {i: 1}; |
| 1053 |
static S b; |
| 1054 |
|
| 1055 |
assert(a.i == 1); |
| 1056 |
assert(a.bar[0] == 4); |
| 1057 |
assert(a.bar[1] == 4); |
| 1058 |
assert(a.bar[2] == 4); |
| 1059 |
assert(a.bar[3] == 4); |
| 1060 |
assert(b.i == 0); |
| 1061 |
assert(b.bar[0] == 4); |
| 1062 |
assert(b.bar[1] == 4); |
| 1063 |
assert(b.bar[2] == 4); |
| 1064 |
assert(b.bar[3] == 4); |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
/*******************************************/ |
| 1069 |
|
| 1070 |
void vararg59(...) |
| 1071 |
{ |
| 1072 |
if (_arguments[0] is typeid(size_t)) |
| 1073 |
assert(va_arg!size_t(_argptr) == 454); |
| 1074 |
else |
| 1075 |
assert(va_arg!string(_argptr) == "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"); |
| 1076 |
} |
| 1077 |
|
| 1078 |
void bug59(string s)() |
| 1079 |
{ |
| 1080 |
vararg59(s); |
| 1081 |
vararg59(s.length); |
| 1082 |
} |
| 1083 |
|
| 1084 |
void test59() |
| 1085 |
{ |
| 1086 |
bug59!("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234")(); |
| 1087 |
} |
| 1088 |
|
| 1089 |
/*******************************************/ |
| 1090 |
|
| 1091 |
class Foo60(T) |
| 1092 |
{ |
| 1093 |
this() { unknown_identifier; } |
| 1094 |
} |
| 1095 |
|
| 1096 |
void test60() |
| 1097 |
{ |
| 1098 |
bool foobar = is( Foo60!(int) ); |
| 1099 |
assert(!foobar); |
| 1100 |
} |
| 1101 |
|
| 1102 |
|
| 1103 |
/*******************************************/ |
| 1104 |
|
| 1105 |
void repeat( int n, void delegate() dg ) |
| 1106 |
{ |
| 1107 |
printf("n = %d\n", n); |
| 1108 |
if( n&1 ) dg(); |
| 1109 |
if( n/2 ) repeat( n/2, {dg();dg();} ); |
| 1110 |
} |
| 1111 |
|
| 1112 |
void test61() |
| 1113 |
{ |
| 1114 |
repeat( 10, {printf("Hello\n");} ); |
| 1115 |
} |
| 1116 |
|
| 1117 |
/*******************************************/ |
| 1118 |
|
| 1119 |
void test62() |
| 1120 |
{ |
| 1121 |
Vector62 a; |
| 1122 |
a.set(1,2,24); |
| 1123 |
a = a * 2; |
| 1124 |
assert(a.x == 2); |
| 1125 |
assert(a.y == 4); |
| 1126 |
assert(a.z == 48); |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
struct Vector62 |
| 1131 |
{ |
| 1132 |
float x,y,z; |
| 1133 |
|
| 1134 |
// constructor |
| 1135 |
void set(float _x, float _y, float _z) |
| 1136 |
{ |
| 1137 |
x = _x; |
| 1138 |
y = _y; |
| 1139 |
z = _z; |
| 1140 |
} |
| 1141 |
|
| 1142 |
Vector62 opBinary(string op : "*")(float s) |
| 1143 |
{ |
| 1144 |
Vector62 ret; |
| 1145 |
ret.x = x*s; |
| 1146 |
ret.y = y*s; |
| 1147 |
ret.z = z*s; |
| 1148 |
return ret; |
| 1149 |
} |
| 1150 |
} |
| 1151 |
|
| 1152 |
/*******************************************/ |
| 1153 |
|
| 1154 |
struct Data63 |
| 1155 |
{ |
| 1156 |
int x, y; |
| 1157 |
|
| 1158 |
/// To make size > 8 so NRVO is used. |
| 1159 |
/// Program runs correctly with this line commented out: |
| 1160 |
byte filler; |
| 1161 |
} |
| 1162 |
|
| 1163 |
Data63 frob(ref Data63 d) |
| 1164 |
{ |
| 1165 |
Data63 ret; |
| 1166 |
ret.y = d.x - d.y; |
| 1167 |
ret.x = d.x + d.y; |
| 1168 |
return ret; |
| 1169 |
} |
| 1170 |
|
| 1171 |
void test63() |
| 1172 |
{ |
| 1173 |
Data63 d; d.x = 1; d.y = 2; |
| 1174 |
d = frob(d); |
| 1175 |
assert(d.x == 3 && d.y == -1); |
| 1176 |
} |
| 1177 |
|
| 1178 |
/*******************************************/ |
| 1179 |
|
| 1180 |
class Foo64 |
| 1181 |
{ |
| 1182 |
this() { } |
| 1183 |
~this() { } |
| 1184 |
} |
| 1185 |
|
| 1186 |
template Mix64() |
| 1187 |
{ |
| 1188 |
void init() { |
| 1189 |
ptr = new Foo64; |
| 1190 |
} |
| 1191 |
Foo64 ptr; |
| 1192 |
} |
| 1193 |
|
| 1194 |
class Container64 |
| 1195 |
{ |
| 1196 |
this() { init(); } |
| 1197 |
mixin Mix64; |
| 1198 |
} |
| 1199 |
|
| 1200 |
|
| 1201 |
void test64() |
| 1202 |
{ |
| 1203 |
auto x = new Container64; |
| 1204 |
|
| 1205 |
assert(!(x.classinfo.flags & 2)); |
| 1206 |
} |
| 1207 |
|
| 1208 |
/*******************************************/ |
| 1209 |
|
| 1210 |
struct Vector65(T, uint dim) |
| 1211 |
{ |
| 1212 |
T[dim] data; |
| 1213 |
} |
| 1214 |
|
| 1215 |
T dot65(T, uint dim)(Vector65!(T,dim) a, Vector65!(T,dim) b) |
| 1216 |
{ |
| 1217 |
T tmp; |
| 1218 |
for ( int i = 0; i < dim; ++i ) |
| 1219 |
tmp += a.data[i] * b.data[i]; |
| 1220 |
return tmp; |
| 1221 |
} |
| 1222 |
|
| 1223 |
void test65() |
| 1224 |
{ |
| 1225 |
Vector65!(double,3u) a,b; |
| 1226 |
auto t = dot65(a,b); |
| 1227 |
} |
| 1228 |
|
| 1229 |
|
| 1230 |
/*******************************************/ |
| 1231 |
// https://issues.dlang.org/show_bug.cgi?id=18576 |
| 1232 |
|
| 1233 |
void delegate() callback; |
| 1234 |
|
| 1235 |
struct S66 { |
| 1236 |
int x; |
| 1237 |
@disable this(this); |
| 1238 |
|
| 1239 |
this(int x) { |
| 1240 |
this.x = x; |
| 1241 |
callback = &inc; |
| 1242 |
} |
| 1243 |
void inc() { |
| 1244 |
x++; |
| 1245 |
} |
| 1246 |
} |
| 1247 |
|
| 1248 |
auto f66() |
| 1249 |
{ |
| 1250 |
return g66(); // RVO should be done |
| 1251 |
} |
| 1252 |
|
| 1253 |
auto g66() |
| 1254 |
{ |
| 1255 |
return h66(); // RVO should be done |
| 1256 |
} |
| 1257 |
|
| 1258 |
auto h66() |
| 1259 |
{ |
| 1260 |
return S66(100); |
| 1261 |
} |
| 1262 |
|
| 1263 |
void test18576() |
| 1264 |
{ |
| 1265 |
auto s = f66(); |
| 1266 |
printf("%p vs %p\n", &s, callback.ptr); |
| 1267 |
callback(); |
| 1268 |
printf("s.x = %d\n", s.x); |
| 1269 |
assert(s.x == 101); |
| 1270 |
assert(&s == callback.ptr); |
| 1271 |
} |
| 1272 |
|
| 1273 |
/*******************************************/ |
| 1274 |
|
| 1275 |
void main() |
| 1276 |
{ |
| 1277 |
printf("Start\n"); |
| 1278 |
|
| 1279 |
test1(); |
| 1280 |
test2(); |
| 1281 |
test3(); |
| 1282 |
test4(); |
| 1283 |
test6(); |
| 1284 |
test7(); |
| 1285 |
test8(); |
| 1286 |
test10(); |
| 1287 |
test11(); |
| 1288 |
test12(); |
| 1289 |
test13(); |
| 1290 |
test14(); |
| 1291 |
test15(); |
| 1292 |
test17(); |
| 1293 |
test18(); |
| 1294 |
test19(); |
| 1295 |
test20(); |
| 1296 |
test21(); |
| 1297 |
test22(); |
| 1298 |
test23(); |
| 1299 |
test24(); |
| 1300 |
test26(); |
| 1301 |
test27(); |
| 1302 |
test28(); |
| 1303 |
test29(); |
| 1304 |
test30(); |
| 1305 |
test31(); |
| 1306 |
test32(); |
| 1307 |
test33(); |
| 1308 |
test34(); |
| 1309 |
test35(); |
| 1310 |
test36(); |
| 1311 |
test37(); |
| 1312 |
test38(); |
| 1313 |
test39(); |
| 1314 |
test40(); |
| 1315 |
test41(); |
| 1316 |
test42(); |
| 1317 |
test43(); |
| 1318 |
test44(); |
| 1319 |
test45(); |
| 1320 |
test46(); |
| 1321 |
test47(); |
| 1322 |
test48(); |
| 1323 |
test49(); |
| 1324 |
test50(); |
| 1325 |
test51(); |
| 1326 |
test52(); |
| 1327 |
test53(); |
| 1328 |
test54(); |
| 1329 |
test55(); |
| 1330 |
test58(); |
| 1331 |
test59(); |
| 1332 |
test60(); |
| 1333 |
test61(); |
| 1334 |
test62(); |
| 1335 |
test63(); |
| 1336 |
test64(); |
| 1337 |
test65(); |
| 1338 |
test18576(); |
| 1339 |
|
| 1340 |
printf("Success\n"); |
| 1341 |
} |