| 1 |
// REQUIRED_ARGS: -preview=rvaluerefparam |
| 2 |
// |
| 3 |
/* TEST_OUTPUT: |
| 4 |
--- |
| 5 |
Boo!double |
| 6 |
Boo!int |
| 7 |
true |
| 8 |
int |
| 9 |
!! immutable(int)[] |
| 10 |
int(int i, long j = 7L) |
| 11 |
long |
| 12 |
C10390(C10390(C10390(<recursion>))) |
| 13 |
AliasSeq!(height) |
| 14 |
AliasSeq!(get, get) |
| 15 |
AliasSeq!(clear) |
| 16 |
AliasSeq!(draw, draw) |
| 17 |
const(int) |
| 18 |
string[] |
| 19 |
double[] |
| 20 |
double[] |
| 21 |
{} |
| 22 |
AliasSeq!("m") |
| 23 |
true |
| 24 |
TFunction1: extern (C) void function() |
| 25 |
--- |
| 26 |
*/ |
| 27 |
|
| 28 |
//import std.stdio; |
| 29 |
import core.stdc.stdio; |
| 30 |
|
| 31 |
/******************************************/ |
| 32 |
|
| 33 |
struct S |
| 34 |
{ |
| 35 |
int opUnary(string op)() if (op == "*") { return 7; } |
| 36 |
} |
| 37 |
|
| 38 |
void test1() |
| 39 |
{ |
| 40 |
S s; |
| 41 |
|
| 42 |
printf("%d\n", *s); |
| 43 |
assert(*s == 7); |
| 44 |
} |
| 45 |
|
| 46 |
/******************************************/ |
| 47 |
|
| 48 |
void test2() |
| 49 |
{ |
| 50 |
double[1][2] bar; |
| 51 |
bar[0][0] = 1.0; |
| 52 |
bar[1][0] = 2.0; |
| 53 |
foo2(bar); |
| 54 |
} |
| 55 |
|
| 56 |
void foo2(T...)(T args) |
| 57 |
{ |
| 58 |
foreach (arg; args[0 .. $]) |
| 59 |
{ |
| 60 |
//writeln(arg); |
| 61 |
bar2!(typeof(arg))(&arg); |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
void bar2(D)(const(void)* arg) |
| 67 |
{ |
| 68 |
D obj = *cast(D*) arg; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
/***************************************************/ |
| 73 |
|
| 74 |
void test4() |
| 75 |
{ |
| 76 |
immutable int maxi = 8; |
| 77 |
int[][maxi] neighbors = [ cast(int[])[ ], [ 0 ], [ 0, 1], [ 0, 2], [1, 2], [1, 2, 3, 4], |
| 78 |
[ 2, 3, 5], [ 4, 5, 6 ] ]; |
| 79 |
int[maxi] grid; |
| 80 |
|
| 81 |
// neighbors[0].length = 0; |
| 82 |
|
| 83 |
void place(int k, uint mask) |
| 84 |
{ if(k<maxi) { |
| 85 |
for(uint m = 1, d = 1; d <= maxi; d++, m<<=1) |
| 86 |
if(!(mask & m)) { |
| 87 |
bool ok = true; |
| 88 |
int dif; |
| 89 |
foreach(nb; neighbors[k]) |
| 90 |
if((dif=grid[nb]-d)==1 || dif==-1) { |
| 91 |
ok = false; break; |
| 92 |
} |
| 93 |
if(ok) { |
| 94 |
grid[k] = d; |
| 95 |
place(k+1, mask | m); |
| 96 |
} |
| 97 |
} |
| 98 |
} else { |
| 99 |
printf(" %d\n%d %d %d\n%d %d %d\n %d\n\n", |
| 100 |
grid[0], grid[1], grid[2], grid[3], grid[4], grid[5], grid[6], grid[7]); |
| 101 |
} |
| 102 |
} |
| 103 |
place(0, 0); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
/***************************************************/ |
| 108 |
|
| 109 |
struct S5 |
| 110 |
{ |
| 111 |
enum S5 some_constant = {2}; |
| 112 |
|
| 113 |
int member; |
| 114 |
} |
| 115 |
|
| 116 |
void test5() |
| 117 |
{ |
| 118 |
} |
| 119 |
|
| 120 |
/***************************************************/ |
| 121 |
|
| 122 |
struct S6 |
| 123 |
{ |
| 124 |
int a, b, c; |
| 125 |
} |
| 126 |
|
| 127 |
struct T6 |
| 128 |
{ |
| 129 |
S6 s; |
| 130 |
int b = 7; |
| 131 |
|
| 132 |
alias s this; |
| 133 |
} |
| 134 |
|
| 135 |
void test6() |
| 136 |
{ |
| 137 |
T6 t; |
| 138 |
t.a = 4; |
| 139 |
t.b = 5; |
| 140 |
t.c = 6; |
| 141 |
assert(t.a == 4); |
| 142 |
assert(t.b == 5); |
| 143 |
assert(t.c == 6); |
| 144 |
assert(t.s.b == 0); |
| 145 |
assert(t.sizeof == 4*4); |
| 146 |
assert(t.init.sizeof == 4*4); |
| 147 |
} |
| 148 |
|
| 149 |
/***************************************************/ |
| 150 |
|
| 151 |
struct S7 |
| 152 |
{ |
| 153 |
int a, b, c; |
| 154 |
} |
| 155 |
|
| 156 |
class C7 |
| 157 |
{ |
| 158 |
S7 s; |
| 159 |
int b = 7; |
| 160 |
|
| 161 |
alias s this; |
| 162 |
} |
| 163 |
|
| 164 |
void test7() |
| 165 |
{ |
| 166 |
C7 t = new C7(); |
| 167 |
t.a = 4; |
| 168 |
t.b = 5; |
| 169 |
t.c = 6; |
| 170 |
assert(t.a == 4); |
| 171 |
assert(t.b == 5); |
| 172 |
assert(t.c == 6); |
| 173 |
assert(t.s.b == 0); |
| 174 |
assert(t.sizeof == (void*).sizeof); |
| 175 |
assert(t.init is null); |
| 176 |
} |
| 177 |
|
| 178 |
/***************************************************/ |
| 179 |
|
| 180 |
void foo8(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__) |
| 181 |
{ |
| 182 |
assert(n1 == n2); |
| 183 |
printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, cast(int)s.length, s.ptr); |
| 184 |
} |
| 185 |
|
| 186 |
void test8() |
| 187 |
{ |
| 188 |
foo8(); |
| 189 |
} |
| 190 |
|
| 191 |
/***************************************************/ |
| 192 |
|
| 193 |
void foo9(int n1 = __LINE__ + 0, int n2 = __LINE__, string s = __FILE__)() |
| 194 |
{ |
| 195 |
assert(n1 == n2); |
| 196 |
printf("n1 = %d, n2 = %d, s = %.*s\n", n1, n2, cast(int)s.length, s.ptr); |
| 197 |
} |
| 198 |
|
| 199 |
void test9() |
| 200 |
{ |
| 201 |
foo9(); |
| 202 |
} |
| 203 |
|
| 204 |
/***************************************************/ |
| 205 |
|
| 206 |
int foo10(char c) pure nothrow |
| 207 |
{ |
| 208 |
return 1; |
| 209 |
} |
| 210 |
|
| 211 |
void test10() |
| 212 |
{ |
| 213 |
int function(char c) fp; |
| 214 |
int function(char c) pure nothrow fq; |
| 215 |
|
| 216 |
fp = &foo10; |
| 217 |
fq = &foo10; |
| 218 |
} |
| 219 |
|
| 220 |
/***************************************************/ |
| 221 |
|
| 222 |
class Base11 {} |
| 223 |
class Derived11 : Base11 {} |
| 224 |
class MoreDerived11 : Derived11 {} |
| 225 |
|
| 226 |
int fun11(Base11) { return 1; } |
| 227 |
int fun11(Derived11) { return 2; } |
| 228 |
|
| 229 |
void test11() |
| 230 |
{ |
| 231 |
MoreDerived11 m; |
| 232 |
|
| 233 |
auto i = fun11(m); |
| 234 |
assert(i == 2); |
| 235 |
} |
| 236 |
|
| 237 |
/***************************************************/ |
| 238 |
|
| 239 |
interface ABC {}; |
| 240 |
interface AB: ABC {}; |
| 241 |
interface BC: ABC {}; |
| 242 |
interface AC: ABC {}; |
| 243 |
interface A: AB, AC {}; |
| 244 |
interface B: AB, BC {}; |
| 245 |
interface C: AC, BC {}; |
| 246 |
|
| 247 |
int f12(AB ab) { return 1; } |
| 248 |
int f12(ABC abc) { return 2; } |
| 249 |
|
| 250 |
void test12() |
| 251 |
{ |
| 252 |
A a; |
| 253 |
auto i = f12(a); |
| 254 |
assert(i == 1); |
| 255 |
} |
| 256 |
|
| 257 |
/***************************************************/ |
| 258 |
|
| 259 |
template Foo13(alias x) |
| 260 |
{ |
| 261 |
enum bar = x + 1; |
| 262 |
} |
| 263 |
|
| 264 |
static assert(Foo13!(2+1).bar == 4); |
| 265 |
|
| 266 |
template Bar13(alias x) |
| 267 |
{ |
| 268 |
enum bar = x; |
| 269 |
} |
| 270 |
|
| 271 |
static assert(Bar13!("abc").bar == "abc"); |
| 272 |
|
| 273 |
void test13() |
| 274 |
{ |
| 275 |
} |
| 276 |
|
| 277 |
/***************************************************/ |
| 278 |
|
| 279 |
template Foo14(alias a) |
| 280 |
{ |
| 281 |
alias Bar14!(a) Foo14; |
| 282 |
} |
| 283 |
|
| 284 |
int Bar14(alias a)() |
| 285 |
{ |
| 286 |
return a.sizeof; |
| 287 |
} |
| 288 |
|
| 289 |
void test14() |
| 290 |
{ |
| 291 |
auto i = Foo14!("hello")(); |
| 292 |
printf("i = %d\n", i); |
| 293 |
assert(i == "hello".sizeof); |
| 294 |
i = Foo14!(1)(); |
| 295 |
printf("i = %d\n", i); |
| 296 |
assert(i == 4); |
| 297 |
} |
| 298 |
|
| 299 |
/***************************************************/ |
| 300 |
|
| 301 |
auto foo15()(int x) |
| 302 |
{ |
| 303 |
return 3 + x; |
| 304 |
} |
| 305 |
|
| 306 |
void test15() |
| 307 |
{ |
| 308 |
|
| 309 |
auto bar()(int x) |
| 310 |
{ |
| 311 |
return 5 + x; |
| 312 |
} |
| 313 |
|
| 314 |
printf("%d\n", foo15(4)); |
| 315 |
printf("%d\n", bar(4)); |
| 316 |
} |
| 317 |
|
| 318 |
/***************************************************/ |
| 319 |
|
| 320 |
int foo16(int x) { return 1; } |
| 321 |
int foo16(ref int x) { return 2; } |
| 322 |
|
| 323 |
void test16() |
| 324 |
{ |
| 325 |
int y; |
| 326 |
auto i = foo16(y); |
| 327 |
printf("i == %d\n", i); |
| 328 |
assert(i == 2); |
| 329 |
i = foo16(3); |
| 330 |
assert(i == 1); |
| 331 |
} |
| 332 |
|
| 333 |
/***************************************************/ |
| 334 |
|
| 335 |
class A17 { } |
| 336 |
class B17 : A17 { } |
| 337 |
class C17 : B17 { } |
| 338 |
|
| 339 |
int foo17(A17, ref int x) { return 1; } |
| 340 |
int foo17(B17, ref int x) { return 2; } |
| 341 |
|
| 342 |
void test17() |
| 343 |
{ |
| 344 |
C17 c; |
| 345 |
int y; |
| 346 |
auto i = foo17(c, y); |
| 347 |
printf("i == %d\n", i); |
| 348 |
assert(i == 2); |
| 349 |
} |
| 350 |
|
| 351 |
/***************************************************/ |
| 352 |
|
| 353 |
class C18 |
| 354 |
{ |
| 355 |
void foo(int x) { foo("abc"); } |
| 356 |
void foo(string s) { } // this is hidden, but that's ok 'cuz no overlap |
| 357 |
void bar() |
| 358 |
{ |
| 359 |
foo("abc"); |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
class D18 : C18 |
| 364 |
{ |
| 365 |
override void foo(int x) { } |
| 366 |
} |
| 367 |
|
| 368 |
void test18() |
| 369 |
{ |
| 370 |
D18 d = new D18(); |
| 371 |
d.bar(); |
| 372 |
} |
| 373 |
|
| 374 |
/***************************************************/ |
| 375 |
|
| 376 |
int foo19(alias int a)() { return a; } |
| 377 |
|
| 378 |
void test19() |
| 379 |
{ |
| 380 |
int y = 7; |
| 381 |
auto i = foo19!(y)(); |
| 382 |
printf("i == %d\n", i); |
| 383 |
assert(i == 7); |
| 384 |
|
| 385 |
i = foo19!(4)(); |
| 386 |
printf("i == %d\n", i); |
| 387 |
assert(i == 4); |
| 388 |
} |
| 389 |
|
| 390 |
/***************************************************/ |
| 391 |
|
| 392 |
template Foo20(int x) if (x & 1) |
| 393 |
{ |
| 394 |
const int Foo20 = 6; |
| 395 |
} |
| 396 |
|
| 397 |
template Foo20(int x) if ((x & 1) == 0) |
| 398 |
{ |
| 399 |
const int Foo20 = 7; |
| 400 |
} |
| 401 |
|
| 402 |
void test20() |
| 403 |
{ |
| 404 |
int i = Foo20!(3); |
| 405 |
printf("%d\n", i); |
| 406 |
assert(i == 6); |
| 407 |
i = Foo20!(4); |
| 408 |
printf("%d\n", i); |
| 409 |
assert(i == 7); |
| 410 |
} |
| 411 |
|
| 412 |
/***************************************************/ |
| 413 |
|
| 414 |
template isArray21(T : U[], U) |
| 415 |
{ |
| 416 |
static const isArray21 = 1; |
| 417 |
} |
| 418 |
|
| 419 |
template isArray21(T) |
| 420 |
{ |
| 421 |
static const isArray21 = 0; |
| 422 |
} |
| 423 |
|
| 424 |
int foo21(T)(T x) if (isArray21!(T)) |
| 425 |
{ |
| 426 |
return 1; |
| 427 |
} |
| 428 |
|
| 429 |
int foo21(T)(T x) if (!isArray21!(T)) |
| 430 |
{ |
| 431 |
return 2; |
| 432 |
} |
| 433 |
|
| 434 |
void test21() |
| 435 |
{ |
| 436 |
auto i = foo21(5); |
| 437 |
assert(i == 2); |
| 438 |
int[] a; |
| 439 |
i = foo21(a); |
| 440 |
assert(i == 1); |
| 441 |
} |
| 442 |
|
| 443 |
/***************************************************/ |
| 444 |
|
| 445 |
void test22() |
| 446 |
{ |
| 447 |
immutable uint x, y; |
| 448 |
foreach (i; x .. y) {} |
| 449 |
} |
| 450 |
|
| 451 |
/***************************************************/ |
| 452 |
|
| 453 |
const bool foo23 = is(typeof(function void() { })); |
| 454 |
const bar23 = is(typeof(function void() { })); |
| 455 |
|
| 456 |
void test23() |
| 457 |
{ |
| 458 |
assert(foo23 == true); |
| 459 |
assert(bar23 == true); |
| 460 |
} |
| 461 |
|
| 462 |
/***************************************************/ |
| 463 |
|
| 464 |
ref int foo24(int i) |
| 465 |
{ |
| 466 |
static int x; |
| 467 |
x = i; |
| 468 |
return x; |
| 469 |
} |
| 470 |
|
| 471 |
void test24() |
| 472 |
{ |
| 473 |
int x = foo24(3); |
| 474 |
assert(x == 3); |
| 475 |
} |
| 476 |
|
| 477 |
/***************************************************/ |
| 478 |
|
| 479 |
ref int foo25(int i) |
| 480 |
{ |
| 481 |
static int x; |
| 482 |
x = i; |
| 483 |
return x; |
| 484 |
} |
| 485 |
|
| 486 |
int bar25(ref int x) |
| 487 |
{ |
| 488 |
return x + 1; |
| 489 |
} |
| 490 |
|
| 491 |
void test25() |
| 492 |
{ |
| 493 |
int x = bar25(foo25(3)); |
| 494 |
assert(x == 4); |
| 495 |
} |
| 496 |
|
| 497 |
/***************************************************/ |
| 498 |
|
| 499 |
static int x26; |
| 500 |
|
| 501 |
ref int foo26(int i) |
| 502 |
{ |
| 503 |
x26 = i; |
| 504 |
return x26; |
| 505 |
} |
| 506 |
|
| 507 |
void test26() |
| 508 |
{ |
| 509 |
int* p = &foo26(3); |
| 510 |
assert(*p == 3); |
| 511 |
} |
| 512 |
|
| 513 |
/***************************************************/ |
| 514 |
|
| 515 |
static int x27 = 3; |
| 516 |
|
| 517 |
ref int foo27(int i) |
| 518 |
{ |
| 519 |
return x27; |
| 520 |
} |
| 521 |
|
| 522 |
void test27() |
| 523 |
{ |
| 524 |
foo27(3) = 4; |
| 525 |
assert(x27 == 4); |
| 526 |
} |
| 527 |
|
| 528 |
/***************************************************/ |
| 529 |
|
| 530 |
ref int foo28(return ref int x) { return x; } |
| 531 |
|
| 532 |
void test28() |
| 533 |
{ |
| 534 |
int a; |
| 535 |
foo28(a); |
| 536 |
} |
| 537 |
|
| 538 |
/***************************************************/ |
| 539 |
|
| 540 |
void wyda(int[] a) { printf("aaa\n"); } |
| 541 |
void wyda(int[int] a) { printf("bbb\n"); } |
| 542 |
|
| 543 |
struct S29 |
| 544 |
{ |
| 545 |
int[] a; |
| 546 |
|
| 547 |
void wyda() |
| 548 |
{ |
| 549 |
a.wyda; |
| 550 |
a.wyda(); |
| 551 |
} |
| 552 |
} |
| 553 |
|
| 554 |
void test29() |
| 555 |
{ |
| 556 |
int[] a; |
| 557 |
a.wyda; |
| 558 |
int[5] b; |
| 559 |
b.wyda; |
| 560 |
int[int] c; |
| 561 |
c.wyda; |
| 562 |
|
| 563 |
S29 s; |
| 564 |
s.wyda(); |
| 565 |
} |
| 566 |
|
| 567 |
/***************************************************/ |
| 568 |
|
| 569 |
void foo30(D)(D arg) if (isIntegral!D) |
| 570 |
{ |
| 571 |
} |
| 572 |
|
| 573 |
struct S30(T) { } |
| 574 |
struct U30(int T) { } |
| 575 |
|
| 576 |
alias int myint30; |
| 577 |
|
| 578 |
void test30() |
| 579 |
{ |
| 580 |
|
| 581 |
S30!myint30 u; |
| 582 |
S30!int s; |
| 583 |
S30!(int) t = s; |
| 584 |
|
| 585 |
// U30!3 v = s; |
| 586 |
} |
| 587 |
|
| 588 |
/***************************************************/ |
| 589 |
|
| 590 |
class A31 |
| 591 |
{ |
| 592 |
void foo(int* p) { } |
| 593 |
} |
| 594 |
|
| 595 |
class B31 : A31 |
| 596 |
{ |
| 597 |
override void foo(scope int* p) { } |
| 598 |
} |
| 599 |
|
| 600 |
void test31() |
| 601 |
{ |
| 602 |
} |
| 603 |
|
| 604 |
/***************************************************/ |
| 605 |
|
| 606 |
void bar32() { } |
| 607 |
|
| 608 |
nothrow void foo32(int* p) |
| 609 |
{ |
| 610 |
//try { bar32(); } catch (Object o) { } |
| 611 |
try { bar32(); } catch (Throwable o) { } |
| 612 |
try { bar32(); } catch (Exception o) { } |
| 613 |
} |
| 614 |
|
| 615 |
void test32() |
| 616 |
{ int i; |
| 617 |
|
| 618 |
foo32(&i); |
| 619 |
} |
| 620 |
|
| 621 |
/***************************************************/ |
| 622 |
|
| 623 |
struct Integer |
| 624 |
{ |
| 625 |
this(int i) |
| 626 |
{ |
| 627 |
this.i = i; |
| 628 |
} |
| 629 |
|
| 630 |
this(long ii) |
| 631 |
{ |
| 632 |
i = 3; |
| 633 |
} |
| 634 |
|
| 635 |
const int i; |
| 636 |
} |
| 637 |
|
| 638 |
void test33() |
| 639 |
{ |
| 640 |
} |
| 641 |
|
| 642 |
/***************************************************/ |
| 643 |
|
| 644 |
void test34() |
| 645 |
{ |
| 646 |
alias uint Uint; |
| 647 |
foreach(Uint u;1..10) {} |
| 648 |
for(Uint u=1;u<10;u++) {} |
| 649 |
} |
| 650 |
|
| 651 |
/***************************************************/ |
| 652 |
|
| 653 |
ref int foo35(bool condition, return ref int lhs, return ref int rhs) |
| 654 |
{ |
| 655 |
if ( condition ) return lhs; |
| 656 |
return rhs; |
| 657 |
} |
| 658 |
|
| 659 |
ref int bar35()(bool condition, return ref int lhs, return ref int rhs) |
| 660 |
{ |
| 661 |
if ( condition ) return lhs; |
| 662 |
return rhs; |
| 663 |
} |
| 664 |
|
| 665 |
void test35() |
| 666 |
{ |
| 667 |
int a = 10, b = 11; |
| 668 |
|
| 669 |
foo35(a<b, a, b) = 42; |
| 670 |
printf("a = %d and b = %d\n", a, b); // a = 42 and b = 11 |
| 671 |
assert(a == 42 && b == 11); |
| 672 |
|
| 673 |
bar35(a<b, a, b) = 52; |
| 674 |
printf("a = %d and b = %d\n", a, b); |
| 675 |
assert(a == 42 && b == 52); |
| 676 |
} |
| 677 |
|
| 678 |
/***************************************************/ |
| 679 |
|
| 680 |
int foo36(T...)(T ts) |
| 681 |
if (T.length > 1) |
| 682 |
{ |
| 683 |
return T.length; |
| 684 |
} |
| 685 |
|
| 686 |
int foo36(T...)(T ts) |
| 687 |
if (T.length <= 1) |
| 688 |
{ |
| 689 |
return T.length * 7; |
| 690 |
} |
| 691 |
|
| 692 |
void test36() |
| 693 |
{ |
| 694 |
auto i = foo36!(int,int)(1, 2); |
| 695 |
assert(i == 2); |
| 696 |
i = foo36(1, 2, 3); |
| 697 |
assert(i == 3); |
| 698 |
i = foo36(1); |
| 699 |
assert(i == 7); |
| 700 |
i = foo36(); |
| 701 |
assert(i == 0); |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
/***************************************************/ |
| 706 |
|
| 707 |
void test6685() |
| 708 |
{ |
| 709 |
struct S { int x; } |
| 710 |
with({ return S(); }()) |
| 711 |
{ |
| 712 |
x++; |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
/***************************************************/ |
| 717 |
|
| 718 |
struct A37(alias T) |
| 719 |
{ |
| 720 |
} |
| 721 |
|
| 722 |
void foo37(X)(X x) if (is(X Y == A37!(U), alias U)) |
| 723 |
{ |
| 724 |
} |
| 725 |
|
| 726 |
void bar37() {} |
| 727 |
|
| 728 |
void test37() |
| 729 |
{ |
| 730 |
A37!(bar37) a2; |
| 731 |
foo37(a2); |
| 732 |
foo37!(A37!bar37)(a2); |
| 733 |
} |
| 734 |
|
| 735 |
/***************************************************/ |
| 736 |
|
| 737 |
struct A38 |
| 738 |
{ |
| 739 |
this(this) |
| 740 |
{ |
| 741 |
printf("B's copy\n"); |
| 742 |
} |
| 743 |
bool empty() {return false;} |
| 744 |
void popFront() {} |
| 745 |
int front() { return 1; } |
| 746 |
// ref A38 opSlice() { return this; } |
| 747 |
} |
| 748 |
|
| 749 |
void test38() |
| 750 |
{ |
| 751 |
A38 a; |
| 752 |
int i; |
| 753 |
foreach (e; a) { if (++i == 100) break; } |
| 754 |
} |
| 755 |
|
| 756 |
/***************************************************/ |
| 757 |
|
| 758 |
alias int function() Fun39; |
| 759 |
alias ref int function() Gun39; |
| 760 |
static assert(!is(Fun39 == Gun39)); |
| 761 |
|
| 762 |
void test39() |
| 763 |
{ |
| 764 |
} |
| 765 |
|
| 766 |
/***************************************************/ |
| 767 |
|
| 768 |
int x40; |
| 769 |
|
| 770 |
struct Proxy |
| 771 |
{ |
| 772 |
ref int at(int i)() { return x40; } |
| 773 |
} |
| 774 |
|
| 775 |
void test40() |
| 776 |
{ |
| 777 |
Proxy p; |
| 778 |
auto x = p.at!(1); |
| 779 |
} |
| 780 |
|
| 781 |
/***************************************************/ |
| 782 |
|
| 783 |
template Foo41(TList...) |
| 784 |
{ |
| 785 |
alias TList Foo41; |
| 786 |
} |
| 787 |
|
| 788 |
alias Foo41!(immutable(ubyte)[], ubyte[]) X41; |
| 789 |
|
| 790 |
void test41() |
| 791 |
{ |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
/***************************************************/ |
| 796 |
|
| 797 |
bool endsWith(A1, A2)(A1 longer, A2 shorter) |
| 798 |
{ |
| 799 |
static if (is(typeof(longer[0 .. 0] == shorter))) |
| 800 |
{ |
| 801 |
} |
| 802 |
else |
| 803 |
{ |
| 804 |
} |
| 805 |
return false; |
| 806 |
} |
| 807 |
|
| 808 |
void test42() |
| 809 |
{ |
| 810 |
char[] a; |
| 811 |
byte[] b; |
| 812 |
endsWith(a, b); |
| 813 |
} |
| 814 |
|
| 815 |
/***************************************************/ |
| 816 |
|
| 817 |
void f43(S...)(S s) if (S.length > 3) |
| 818 |
{ |
| 819 |
} |
| 820 |
|
| 821 |
void test43() |
| 822 |
{ |
| 823 |
f43(1, 2, 3, 4); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
/***************************************************/ |
| 828 |
|
| 829 |
struct S44(int x = 1){} |
| 830 |
|
| 831 |
void fun()(S44!(1) b) { } |
| 832 |
|
| 833 |
void test44() |
| 834 |
{ |
| 835 |
S44!() s; |
| 836 |
fun(s); |
| 837 |
} |
| 838 |
|
| 839 |
/***************************************************/ |
| 840 |
// https://issues.dlang.org/show_bug.cgi?id=2006 |
| 841 |
|
| 842 |
void test2006() |
| 843 |
{ |
| 844 |
string [][] aas = []; |
| 845 |
assert(aas.length == 0); |
| 846 |
aas ~= cast (string []) []; |
| 847 |
assert(aas.length == 1); |
| 848 |
aas = aas ~ cast (string []) []; |
| 849 |
assert(aas.length == 2); |
| 850 |
} |
| 851 |
|
| 852 |
/***************************************************/ |
| 853 |
// https://issues.dlang.org/show_bug.cgi?id=8442 |
| 854 |
|
| 855 |
void test8442() |
| 856 |
{ |
| 857 |
enum int[] fooEnum = []; |
| 858 |
immutable fooImmutable = fooEnum; |
| 859 |
} |
| 860 |
|
| 861 |
/***************************************************/ |
| 862 |
|
| 863 |
class A45 |
| 864 |
{ |
| 865 |
int x; |
| 866 |
int f() |
| 867 |
{ |
| 868 |
printf("A\n"); |
| 869 |
return 1; |
| 870 |
} |
| 871 |
} |
| 872 |
|
| 873 |
class B45 : A45 |
| 874 |
{ |
| 875 |
override const int f() |
| 876 |
{ |
| 877 |
printf("B\n"); |
| 878 |
return 2; |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
void test45() |
| 883 |
{ |
| 884 |
A45 y = new B45; |
| 885 |
int i = y.f; |
| 886 |
assert(i == 2); |
| 887 |
} |
| 888 |
|
| 889 |
/***************************************************/ |
| 890 |
|
| 891 |
void text10682() |
| 892 |
{ |
| 893 |
ulong x = 1; |
| 894 |
ulong y = 2 ^^ x; |
| 895 |
} |
| 896 |
|
| 897 |
/***************************************************/ |
| 898 |
|
| 899 |
struct Test46 |
| 900 |
{ |
| 901 |
int foo; |
| 902 |
} |
| 903 |
|
| 904 |
void test46() |
| 905 |
{ |
| 906 |
enum Test46 test = {}; |
| 907 |
enum q = test.foo; |
| 908 |
} |
| 909 |
|
| 910 |
/***************************************************/ |
| 911 |
|
| 912 |
pure int double_sqr(int x) { |
| 913 |
int y = x; |
| 914 |
void do_sqr() { y *= y; } |
| 915 |
do_sqr(); |
| 916 |
return y; |
| 917 |
} |
| 918 |
|
| 919 |
void test47() |
| 920 |
{ |
| 921 |
assert(double_sqr(10) == 100); |
| 922 |
} |
| 923 |
|
| 924 |
/***************************************************/ |
| 925 |
|
| 926 |
void sort(alias less)(string[] r) |
| 927 |
{ |
| 928 |
bool pred() |
| 929 |
{ |
| 930 |
return less("a", "a"); |
| 931 |
} |
| 932 |
.sort!(less)(r); |
| 933 |
} |
| 934 |
|
| 935 |
void foo48() |
| 936 |
{ |
| 937 |
int[string] freqs; |
| 938 |
string[] words; |
| 939 |
|
| 940 |
sort!((a, b) { return freqs[a] > freqs[b]; })(words); |
| 941 |
sort!((string a, string b) { return freqs[a] > freqs[b]; })(words); |
| 942 |
//sort!(bool (a, b) { return freqs[a] > freqs[b]; })(words); |
| 943 |
//sort!(function (a, b) { return freqs[a] > freqs[b]; })(words); |
| 944 |
//sort!(function bool(a, b) { return freqs[a] > freqs[b]; })(words); |
| 945 |
sort!(delegate bool(string a, string b) { return freqs[a] > freqs[b]; })(words); |
| 946 |
|
| 947 |
} |
| 948 |
|
| 949 |
void test48() |
| 950 |
{ |
| 951 |
} |
| 952 |
|
| 953 |
/***************************************************/ |
| 954 |
// https://issues.dlang.org/show_bug.cgi?id=6408 |
| 955 |
|
| 956 |
static assert(!is(typeof(string[0..1].init))); |
| 957 |
static assert(is(typeof(string[].init) == string[])); |
| 958 |
static assert(is(typeof(string[][].init) == string[][])); |
| 959 |
static assert(is(typeof(string[][][].init) == string[][][])); |
| 960 |
|
| 961 |
static assert(is(typeof(string[1].init) == string[1])); |
| 962 |
static assert(is(typeof(string[1][1].init) == string[1][1])); |
| 963 |
static assert(is(typeof(string[1][1][1].init) == string[1][1][1])); |
| 964 |
|
| 965 |
static assert(is(typeof(string[string].init) == string[string])); |
| 966 |
static assert(is(typeof(string[string][string].init) == string[string][string])); |
| 967 |
static assert(is(typeof(string[string][string][string].init) == string[string][string][string])); |
| 968 |
|
| 969 |
template TT6408(T...) { alias T TT6408; } |
| 970 |
static assert(is(typeof(TT6408!(int, int)[].init) == TT6408!(int, int))); |
| 971 |
static assert(is(typeof(TT6408!(int, int)[0..$].init) == TT6408!(int, int))); |
| 972 |
static assert(is(typeof(TT6408!(int, int)[$-1].init) == int)); |
| 973 |
|
| 974 |
/***************************************************/ |
| 975 |
// https://issues.dlang.org/show_bug.cgi?id=9409 |
| 976 |
|
| 977 |
template TT9409(T...) { alias T TT9409; } |
| 978 |
|
| 979 |
template idxTypes9409(Prefix...) |
| 980 |
{ |
| 981 |
TT9409!((Prefix[$-1])) idxTypes9409; |
| 982 |
} |
| 983 |
|
| 984 |
alias idxTypes9409!(int) Types9409; |
| 985 |
|
| 986 |
/***************************************************/ |
| 987 |
|
| 988 |
struct S49 |
| 989 |
{ |
| 990 |
static void* p; |
| 991 |
|
| 992 |
this( string name ) |
| 993 |
{ |
| 994 |
printf( "(ctor) &%.*s.x = %p\n", cast(int)name.length, name.ptr, &x ); |
| 995 |
p = cast(void*)&x; |
| 996 |
} |
| 997 |
|
| 998 |
invariant() {} |
| 999 |
|
| 1000 |
int x; |
| 1001 |
} |
| 1002 |
|
| 1003 |
void test49() |
| 1004 |
{ |
| 1005 |
auto s = new S49("s2"); |
| 1006 |
|
| 1007 |
printf( "&s2.x = %p\n", &s.x ); |
| 1008 |
assert(cast(void*)&s.x == S49.p); |
| 1009 |
} |
| 1010 |
|
| 1011 |
/***************************************************/ |
| 1012 |
|
| 1013 |
auto max50(Ts...)(Ts args) |
| 1014 |
if (Ts.length >= 2 |
| 1015 |
&& is(typeof(Ts[0].init > Ts[1].init ? Ts[1].init : Ts[0].init))) |
| 1016 |
{ |
| 1017 |
static if (Ts.length == 2) |
| 1018 |
return args[1] > args[0] ? args[1] : args[0]; |
| 1019 |
else |
| 1020 |
return max50(max50(args[0], args[1]), args[2 .. $]); |
| 1021 |
} |
| 1022 |
|
| 1023 |
void test50() |
| 1024 |
{ |
| 1025 |
assert(max50(4, 5) == 5); |
| 1026 |
assert(max50(2.2, 4.5) == 4.5); |
| 1027 |
assert(max50("Little", "Big") == "Little"); |
| 1028 |
|
| 1029 |
assert(max50(4, 5.5) == 5.5); |
| 1030 |
assert(max50(5.5, 4) == 5.5); |
| 1031 |
} |
| 1032 |
|
| 1033 |
/***************************************************/ |
| 1034 |
|
| 1035 |
void test51() |
| 1036 |
{ |
| 1037 |
static immutable int[2] array = [ 42 ]; |
| 1038 |
enum e = array[1]; |
| 1039 |
static immutable int[1] array2 = [ 0: 42 ]; |
| 1040 |
enum e2 = array2[0]; |
| 1041 |
assert(e == 0); |
| 1042 |
assert(e2 == 42); |
| 1043 |
} |
| 1044 |
|
| 1045 |
/***************************************************/ |
| 1046 |
|
| 1047 |
enum ubyte[4] a52 = [5,6,7,8]; |
| 1048 |
|
| 1049 |
void test52() |
| 1050 |
{ |
| 1051 |
int x=3; |
| 1052 |
assert(a52[x]==8); |
| 1053 |
} |
| 1054 |
|
| 1055 |
/***************************************************/ |
| 1056 |
|
| 1057 |
void test53() |
| 1058 |
{ |
| 1059 |
size_t func2(immutable(void)[] t) |
| 1060 |
{ |
| 1061 |
return 0; |
| 1062 |
} |
| 1063 |
} |
| 1064 |
|
| 1065 |
/***************************************************/ |
| 1066 |
|
| 1067 |
void foo54(void delegate(void[]) dg) { } |
| 1068 |
|
| 1069 |
void test54() |
| 1070 |
{ |
| 1071 |
void func(void[] t) pure { } |
| 1072 |
foo54(&func); |
| 1073 |
|
| 1074 |
// void func2(const(void)[] t) { } |
| 1075 |
// foo54(&func2); |
| 1076 |
} |
| 1077 |
|
| 1078 |
/***************************************************/ |
| 1079 |
|
| 1080 |
class Foo55 |
| 1081 |
{ |
| 1082 |
synchronized void noop1() { } |
| 1083 |
void noop2() shared { } |
| 1084 |
} |
| 1085 |
|
| 1086 |
void test55() |
| 1087 |
{ |
| 1088 |
auto foo = new shared(Foo55); |
| 1089 |
foo.noop1(); |
| 1090 |
foo.noop2(); |
| 1091 |
} |
| 1092 |
|
| 1093 |
/***************************************************/ |
| 1094 |
|
| 1095 |
enum float one56 = 1 * 1; |
| 1096 |
template X56(float E) { int X56 = 2; } |
| 1097 |
alias X56!(one56 * one56) Y56; |
| 1098 |
|
| 1099 |
void test56() |
| 1100 |
{ |
| 1101 |
assert(Y56 == 2); |
| 1102 |
} |
| 1103 |
|
| 1104 |
/***************************************************/ |
| 1105 |
|
| 1106 |
void test57() |
| 1107 |
{ |
| 1108 |
alias shared(int) T; |
| 1109 |
assert (is(T == shared)); |
| 1110 |
} |
| 1111 |
|
| 1112 |
/***************************************************/ |
| 1113 |
|
| 1114 |
struct A58 |
| 1115 |
{ |
| 1116 |
int a,b; |
| 1117 |
} |
| 1118 |
|
| 1119 |
void test58() |
| 1120 |
{ |
| 1121 |
A58[2] rg=[{1,2},{5,6}]; |
| 1122 |
assert(rg[0].a == 1); |
| 1123 |
assert(rg[0].b == 2); |
| 1124 |
assert(rg[1].a == 5); |
| 1125 |
assert(rg[1].b == 6); |
| 1126 |
} |
| 1127 |
|
| 1128 |
/***************************************************/ |
| 1129 |
|
| 1130 |
class A59 { |
| 1131 |
const foo(int i) { return i; } |
| 1132 |
} |
| 1133 |
|
| 1134 |
/***************************************************/ |
| 1135 |
|
| 1136 |
void test60() |
| 1137 |
{ |
| 1138 |
enum real ONE = 1.0; |
| 1139 |
real x; |
| 1140 |
for (x=0.0; x<10.0; x+=ONE) |
| 1141 |
printf("%Lg\n", x); |
| 1142 |
printf("%Lg\n", x); |
| 1143 |
assert(x == 10); |
| 1144 |
} |
| 1145 |
|
| 1146 |
/***************************************************/ |
| 1147 |
|
| 1148 |
pure immutable(T)[] fooPT(T)(immutable(T)[] x, immutable(T)[] y){ |
| 1149 |
|
| 1150 |
immutable(T)[] fooState; |
| 1151 |
|
| 1152 |
immutable(T)[] bar(immutable(T)[] x){ |
| 1153 |
fooState = "hello "; |
| 1154 |
return x ~ y; |
| 1155 |
} |
| 1156 |
|
| 1157 |
return fooState ~ bar(x); |
| 1158 |
|
| 1159 |
} |
| 1160 |
|
| 1161 |
|
| 1162 |
void test61() |
| 1163 |
{ |
| 1164 |
auto s = fooPT("p", "c"); |
| 1165 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 1166 |
} |
| 1167 |
|
| 1168 |
/***************************************************/ |
| 1169 |
|
| 1170 |
void test9577() |
| 1171 |
{ |
| 1172 |
static int function(int)[] foo = [x => x]; |
| 1173 |
foo[0](0); |
| 1174 |
} |
| 1175 |
|
| 1176 |
/***************************************************/ |
| 1177 |
|
| 1178 |
int[3] foo62(int[3] a) |
| 1179 |
{ |
| 1180 |
a[1]++; |
| 1181 |
return a; |
| 1182 |
} |
| 1183 |
|
| 1184 |
void test62() |
| 1185 |
{ |
| 1186 |
int[3] b; |
| 1187 |
b[0] = 1; |
| 1188 |
b[1] = 2; |
| 1189 |
b[2] = 3; |
| 1190 |
auto c = foo62(b); |
| 1191 |
assert(b[0] == 1); |
| 1192 |
assert(b[1] == 2); |
| 1193 |
assert(b[2] == 3); |
| 1194 |
|
| 1195 |
assert(c[0] == 1); |
| 1196 |
assert(c[1] == 3); |
| 1197 |
assert(c[2] == 3); |
| 1198 |
} |
| 1199 |
|
| 1200 |
/***************************************************/ |
| 1201 |
|
| 1202 |
void test3927() |
| 1203 |
{ |
| 1204 |
int[] array; |
| 1205 |
assert(array.length++ == 0); |
| 1206 |
assert(array.length == 1); |
| 1207 |
assert(array.length-- == 1); |
| 1208 |
assert(array.length == 0); |
| 1209 |
} |
| 1210 |
|
| 1211 |
/***************************************************/ |
| 1212 |
|
| 1213 |
void test63() |
| 1214 |
{ |
| 1215 |
int[3] b; |
| 1216 |
b[0] = 1; |
| 1217 |
b[1] = 2; |
| 1218 |
b[2] = 3; |
| 1219 |
auto c = b; |
| 1220 |
b[1]++; |
| 1221 |
assert(b[0] == 1); |
| 1222 |
assert(b[1] == 3); |
| 1223 |
assert(b[2] == 3); |
| 1224 |
|
| 1225 |
assert(c[0] == 1); |
| 1226 |
assert(c[1] == 2); |
| 1227 |
assert(c[2] == 3); |
| 1228 |
} |
| 1229 |
|
| 1230 |
/***************************************************/ |
| 1231 |
|
| 1232 |
void test64() |
| 1233 |
{ |
| 1234 |
int[3] b; |
| 1235 |
b[0] = 1; |
| 1236 |
b[1] = 2; |
| 1237 |
b[2] = 3; |
| 1238 |
int[3] c; |
| 1239 |
c = b; |
| 1240 |
b[1]++; |
| 1241 |
assert(b[0] == 1); |
| 1242 |
assert(b[1] == 3); |
| 1243 |
assert(b[2] == 3); |
| 1244 |
|
| 1245 |
assert(c[0] == 1); |
| 1246 |
assert(c[1] == 2); |
| 1247 |
assert(c[2] == 3); |
| 1248 |
} |
| 1249 |
|
| 1250 |
/***************************************************/ |
| 1251 |
|
| 1252 |
int[2] foo65(int[2] a) |
| 1253 |
{ |
| 1254 |
a[1]++; |
| 1255 |
return a; |
| 1256 |
} |
| 1257 |
|
| 1258 |
void test65() |
| 1259 |
{ |
| 1260 |
int[2] b; |
| 1261 |
b[0] = 1; |
| 1262 |
b[1] = 2; |
| 1263 |
int[2] c = foo65(b); |
| 1264 |
assert(b[0] == 1); |
| 1265 |
assert(b[1] == 2); |
| 1266 |
|
| 1267 |
assert(c[0] == 1); |
| 1268 |
assert(c[1] == 3); |
| 1269 |
} |
| 1270 |
|
| 1271 |
/***************************************************/ |
| 1272 |
|
| 1273 |
int[1] foo66(int[1] a) |
| 1274 |
{ |
| 1275 |
a[0]++; |
| 1276 |
return a; |
| 1277 |
} |
| 1278 |
|
| 1279 |
void test66() |
| 1280 |
{ |
| 1281 |
int[1] b; |
| 1282 |
b[0] = 1; |
| 1283 |
int[1] c = foo66(b); |
| 1284 |
assert(b[0] == 1); |
| 1285 |
assert(c[0] == 2); |
| 1286 |
} |
| 1287 |
|
| 1288 |
/***************************************************/ |
| 1289 |
|
| 1290 |
int[2] foo67(out int[2] a) |
| 1291 |
{ |
| 1292 |
a[0] = 5; |
| 1293 |
a[1] = 6; |
| 1294 |
return a; |
| 1295 |
} |
| 1296 |
|
| 1297 |
void test67() |
| 1298 |
{ |
| 1299 |
int[2] b; |
| 1300 |
b[0] = 1; |
| 1301 |
b[1] = 2; |
| 1302 |
int[2] c = foo67(b); |
| 1303 |
assert(b[0] == 5); |
| 1304 |
assert(b[1] == 6); |
| 1305 |
|
| 1306 |
assert(c[0] == 5); |
| 1307 |
assert(c[1] == 6); |
| 1308 |
} |
| 1309 |
|
| 1310 |
/***************************************************/ |
| 1311 |
|
| 1312 |
void test68() |
| 1313 |
{ |
| 1314 |
digestToString(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"); |
| 1315 |
} |
| 1316 |
|
| 1317 |
void digestToString(const ubyte[16] digest) |
| 1318 |
{ |
| 1319 |
assert(digest[0] == 0xc3); |
| 1320 |
assert(digest[15] == 0x3b); |
| 1321 |
} |
| 1322 |
|
| 1323 |
/***************************************************/ |
| 1324 |
|
| 1325 |
void test69() |
| 1326 |
{ |
| 1327 |
digestToString69(cast(ubyte[16])"\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b"); |
| 1328 |
} |
| 1329 |
|
| 1330 |
void digestToString69(ref const ubyte[16] digest) |
| 1331 |
{ |
| 1332 |
assert(digest[0] == 0xc3); |
| 1333 |
assert(digest[15] == 0x3b); |
| 1334 |
} |
| 1335 |
|
| 1336 |
/***************************************************/ |
| 1337 |
|
| 1338 |
void test70() |
| 1339 |
{ |
| 1340 |
digestToString70("1234567890123456"); |
| 1341 |
} |
| 1342 |
|
| 1343 |
void digestToString70(ref const char[16] digest) |
| 1344 |
{ |
| 1345 |
assert(digest[0] == '1'); |
| 1346 |
assert(digest[15] == '6'); |
| 1347 |
} |
| 1348 |
|
| 1349 |
/***************************************************/ |
| 1350 |
|
| 1351 |
void foo71(out shared int o) {} |
| 1352 |
|
| 1353 |
/***************************************************/ |
| 1354 |
|
| 1355 |
struct foo72 |
| 1356 |
{ |
| 1357 |
int bar() shared { return 1; } |
| 1358 |
} |
| 1359 |
|
| 1360 |
void test72() |
| 1361 |
{ |
| 1362 |
shared foo72 f; |
| 1363 |
auto x = f.bar; |
| 1364 |
} |
| 1365 |
|
| 1366 |
/***************************************************/ |
| 1367 |
|
| 1368 |
class Foo73 |
| 1369 |
{ |
| 1370 |
static if (is(typeof(this) T : shared T)) |
| 1371 |
static assert(0); |
| 1372 |
static if (is(typeof(this) U == shared U)) |
| 1373 |
static assert(0); |
| 1374 |
static if (is(typeof(this) U == const U)) |
| 1375 |
static assert(0); |
| 1376 |
static if (is(typeof(this) U == immutable U)) |
| 1377 |
static assert(0); |
| 1378 |
static if (is(typeof(this) U == const shared U)) |
| 1379 |
static assert(0); |
| 1380 |
|
| 1381 |
static assert(!is(int == const)); |
| 1382 |
static assert(!is(int == immutable)); |
| 1383 |
static assert(!is(int == shared)); |
| 1384 |
|
| 1385 |
static assert(is(int == int)); |
| 1386 |
static assert(is(const(int) == const)); |
| 1387 |
static assert(is(immutable(int) == immutable)); |
| 1388 |
static assert(is(shared(int) == shared)); |
| 1389 |
static assert(is(const(shared(int)) == shared)); |
| 1390 |
static assert(is(const(shared(int)) == const)); |
| 1391 |
|
| 1392 |
static assert(!is(const(shared(int)) == immutable)); |
| 1393 |
static assert(!is(const(int) == immutable)); |
| 1394 |
static assert(!is(const(int) == shared)); |
| 1395 |
static assert(!is(shared(int) == const)); |
| 1396 |
static assert(!is(shared(int) == immutable)); |
| 1397 |
static assert(!is(immutable(int) == const)); |
| 1398 |
static assert(!is(immutable(int) == shared)); |
| 1399 |
} |
| 1400 |
|
| 1401 |
template Bar(T : T) |
| 1402 |
{ |
| 1403 |
alias T Bar; |
| 1404 |
} |
| 1405 |
|
| 1406 |
template Barc(T : const(T)) |
| 1407 |
{ |
| 1408 |
alias T Barc; |
| 1409 |
} |
| 1410 |
|
| 1411 |
template Bari(T : immutable(T)) |
| 1412 |
{ |
| 1413 |
alias T Bari; |
| 1414 |
} |
| 1415 |
|
| 1416 |
template Bars(T : shared(T)) |
| 1417 |
{ |
| 1418 |
alias T Bars; |
| 1419 |
} |
| 1420 |
|
| 1421 |
template Barsc(T : shared(const(T))) |
| 1422 |
{ |
| 1423 |
alias T Barsc; |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
void test73() |
| 1428 |
{ |
| 1429 |
auto f = new Foo73; |
| 1430 |
|
| 1431 |
alias int T; |
| 1432 |
|
| 1433 |
// 5*5 == 25 combinations, plus 2 for swapping const and shared |
| 1434 |
|
| 1435 |
static assert(is(Bar!(T) == T)); |
| 1436 |
static assert(is(Bar!(const(T)) == const(T))); |
| 1437 |
static assert(is(Bar!(immutable(T)) == immutable(T))); |
| 1438 |
static assert(is(Bar!(shared(T)) == shared(T))); |
| 1439 |
static assert(is(Bar!(shared(const(T))) == shared(const(T)))); |
| 1440 |
|
| 1441 |
static assert(is(Barc!(const(T)) == T)); |
| 1442 |
static assert(is(Bari!(immutable(T)) == T)); |
| 1443 |
static assert(is(Bars!(shared(T)) == T)); |
| 1444 |
static assert(is(Barsc!(shared(const(T))) == T)); |
| 1445 |
|
| 1446 |
static assert(is(Barc!(T) == T)); |
| 1447 |
static assert(is(Barc!(immutable(T)) == T)); |
| 1448 |
static assert(is(Barc!(const(shared(T))) == shared(T))); |
| 1449 |
static assert(is(Barsc!(immutable(T)) == T)); |
| 1450 |
|
| 1451 |
static assert(is(Bars!(const(shared(T))) == const(T))); |
| 1452 |
static assert(is(Barsc!(shared(T)) == T)); |
| 1453 |
|
| 1454 |
Bars!(shared(const(T))) b; |
| 1455 |
pragma(msg, typeof(b)); |
| 1456 |
|
| 1457 |
static assert(is(Bars!(shared(const(T))) == const(T))); |
| 1458 |
static assert(is(Barc!(shared(const(T))) == shared(T))); |
| 1459 |
|
| 1460 |
static assert(!is(Bari!(T))); |
| 1461 |
static assert(!is(Bari!(const(T)))); |
| 1462 |
static assert(!is(Bari!(shared(T)))); |
| 1463 |
static assert(!is(Bari!(const(shared(T))))); |
| 1464 |
|
| 1465 |
static assert(is(Barc!(shared(T)))); |
| 1466 |
|
| 1467 |
static assert(!is(Bars!(T))); |
| 1468 |
static assert(!is(Bars!(const(T)))); |
| 1469 |
static assert(!is(Bars!(immutable(T)))); |
| 1470 |
static assert(!is(Barsc!(T))); |
| 1471 |
static assert(!is(Barsc!(const(T)))); |
| 1472 |
} |
| 1473 |
|
| 1474 |
/***************************************************/ |
| 1475 |
|
| 1476 |
pure nothrow { |
| 1477 |
alias void function(int) A74; |
| 1478 |
} |
| 1479 |
|
| 1480 |
alias void function(int) pure nothrow B74; |
| 1481 |
alias pure nothrow void function(int) C74; |
| 1482 |
|
| 1483 |
void test74() |
| 1484 |
{ |
| 1485 |
A74 a = null; |
| 1486 |
B74 b = null; |
| 1487 |
C74 c = null; |
| 1488 |
a = b; |
| 1489 |
a = c; |
| 1490 |
} |
| 1491 |
|
| 1492 |
/***************************************************/ |
| 1493 |
|
| 1494 |
void test9212() |
| 1495 |
{ |
| 1496 |
int[int] aa; |
| 1497 |
foreach (const key, const val; aa) {} |
| 1498 |
foreach (size_t key, size_t val; aa) {} |
| 1499 |
} |
| 1500 |
|
| 1501 |
/***************************************************/ |
| 1502 |
|
| 1503 |
class A75 |
| 1504 |
{ |
| 1505 |
pure static void raise(string s) |
| 1506 |
{ |
| 1507 |
throw new Exception(s); |
| 1508 |
} |
| 1509 |
} |
| 1510 |
|
| 1511 |
void test75() |
| 1512 |
{ int x = 0; |
| 1513 |
try |
| 1514 |
{ |
| 1515 |
A75.raise("a"); |
| 1516 |
} catch (Exception e) |
| 1517 |
{ |
| 1518 |
x = 1; |
| 1519 |
} |
| 1520 |
assert(x == 1); |
| 1521 |
} |
| 1522 |
|
| 1523 |
/***************************************************/ |
| 1524 |
|
| 1525 |
void test76() |
| 1526 |
{ |
| 1527 |
int x, y; |
| 1528 |
bool which; |
| 1529 |
(which ? x : y) += 5; |
| 1530 |
assert(y == 5); |
| 1531 |
} |
| 1532 |
|
| 1533 |
/***************************************************/ |
| 1534 |
|
| 1535 |
void test77() |
| 1536 |
{ |
| 1537 |
auto a = ["hello", "world"]; |
| 1538 |
pragma(msg, typeof(a)); |
| 1539 |
auto b = a; |
| 1540 |
assert(a is b); |
| 1541 |
assert(a == b); |
| 1542 |
b = a.dup; |
| 1543 |
assert(a == b); |
| 1544 |
assert(a !is b); |
| 1545 |
} |
| 1546 |
|
| 1547 |
/***************************************************/ |
| 1548 |
|
| 1549 |
void test78() |
| 1550 |
{ |
| 1551 |
auto array = [0, 2, 4, 6, 8, 10]; |
| 1552 |
array = array[0 .. $ - 2]; // Right-shrink by two elements |
| 1553 |
assert(array == [0, 2, 4, 6]); |
| 1554 |
array = array[1 .. $]; // Left-shrink by one element |
| 1555 |
assert(array == [2, 4, 6]); |
| 1556 |
array = array[1 .. $ - 1]; // Shrink from both sides |
| 1557 |
assert(array == [4]); |
| 1558 |
} |
| 1559 |
|
| 1560 |
/***************************************************/ |
| 1561 |
|
| 1562 |
void test79() |
| 1563 |
{ |
| 1564 |
auto a = [87, 40, 10]; |
| 1565 |
a ~= 42; |
| 1566 |
assert(a == [87, 40, 10, 42]); |
| 1567 |
a ~= [5, 17]; |
| 1568 |
assert(a == [87, 40, 10, 42, 5, 17]); |
| 1569 |
} |
| 1570 |
|
| 1571 |
/***************************************************/ |
| 1572 |
|
| 1573 |
void test6317() |
| 1574 |
{ |
| 1575 |
int b = 12345; |
| 1576 |
struct nested { int a; int fun() { return b; } } |
| 1577 |
static assert(!__traits(compiles, { nested x = { 3, null }; })); |
| 1578 |
nested g = { 7 }; |
| 1579 |
auto h = nested(7); |
| 1580 |
assert(g.fun() == 12345); |
| 1581 |
assert(h.fun() == 12345); |
| 1582 |
} |
| 1583 |
|
| 1584 |
/***************************************************/ |
| 1585 |
|
| 1586 |
void test80() |
| 1587 |
{ |
| 1588 |
auto array = new int[10]; |
| 1589 |
array.length += 1000; |
| 1590 |
assert(array.length == 1010); |
| 1591 |
array.length /= 10; |
| 1592 |
assert(array.length == 101); |
| 1593 |
array.length -= 1; |
| 1594 |
assert(array.length == 100); |
| 1595 |
array.length |= 1; |
| 1596 |
assert(array.length == 101); |
| 1597 |
array.length ^= 3; |
| 1598 |
assert(array.length == 102); |
| 1599 |
array.length &= 2; |
| 1600 |
assert(array.length == 2); |
| 1601 |
array.length *= 2; |
| 1602 |
assert(array.length == 4); |
| 1603 |
array.length <<= 1; |
| 1604 |
assert(array.length == 8); |
| 1605 |
array.length >>= 1; |
| 1606 |
assert(array.length == 4); |
| 1607 |
array.length >>>= 1; |
| 1608 |
assert(array.length == 2); |
| 1609 |
array.length %= 2; |
| 1610 |
assert(array.length == 0); |
| 1611 |
|
| 1612 |
int[]* foo() |
| 1613 |
{ |
| 1614 |
static int x; |
| 1615 |
x++; |
| 1616 |
assert(x == 1); |
| 1617 |
auto p = &array; |
| 1618 |
return p; |
| 1619 |
} |
| 1620 |
|
| 1621 |
(*foo()).length += 2; |
| 1622 |
assert(array.length == 2); |
| 1623 |
} |
| 1624 |
|
| 1625 |
/***************************************************/ |
| 1626 |
|
| 1627 |
void test81() |
| 1628 |
{ |
| 1629 |
int[3] a = [1, 2, 3]; |
| 1630 |
int[3] b = a; |
| 1631 |
a[1] = 42; |
| 1632 |
assert(b[1] == 2); // b is an independent copy of a |
| 1633 |
int[3] fun(int[3] x, int[3] y) { |
| 1634 |
// x and y are copies of the arguments |
| 1635 |
x[0] = y[0] = 100; |
| 1636 |
return x; |
| 1637 |
} |
| 1638 |
auto c = fun(a, b); // c has type int[3] |
| 1639 |
assert(c == [100, 42, 3]); |
| 1640 |
assert(b == [1, 2, 3]); // b is unaffected by fun |
| 1641 |
} |
| 1642 |
|
| 1643 |
/***************************************************/ |
| 1644 |
|
| 1645 |
void test82() |
| 1646 |
{ |
| 1647 |
auto a1 = [ "Jane":10.0, "Jack":20, "Bob":15 ]; |
| 1648 |
auto a2 = a1; // a1 and a2 refer to the same data |
| 1649 |
a1["Bob"] = 100; // Changing a1 |
| 1650 |
assert(a2["Bob"] == 100); //is same as changing a2 |
| 1651 |
a2["Sam"] = 3.5; //and vice |
| 1652 |
assert(a2["Sam"] == 3.5); // versa |
| 1653 |
} |
| 1654 |
|
| 1655 |
/***************************************************/ |
| 1656 |
|
| 1657 |
void test7942() |
| 1658 |
{ |
| 1659 |
string a = "a"; |
| 1660 |
wstring b = "b"; |
| 1661 |
dstring c = "c"; |
| 1662 |
|
| 1663 |
a ~= "a"c; |
| 1664 |
static assert(!is(typeof(a ~= "b"w))); |
| 1665 |
static assert(!is(typeof(a ~= "c"d))); |
| 1666 |
static assert(!is(typeof(b ~= "a"c))); |
| 1667 |
b ~= "b"w; |
| 1668 |
static assert(!is(typeof(b ~= "c"d))); |
| 1669 |
static assert(!is(typeof(c ~= "a"c))); |
| 1670 |
static assert(!is(typeof(c ~= "b"w))); |
| 1671 |
c ~= "c"d; |
| 1672 |
|
| 1673 |
assert(a == "aa"); |
| 1674 |
assert(b == "bb"); |
| 1675 |
assert(c == "cc"); |
| 1676 |
} |
| 1677 |
|
| 1678 |
/***************************************************/ |
| 1679 |
|
| 1680 |
void bump(ref int x) { ++x; } |
| 1681 |
|
| 1682 |
void test83() |
| 1683 |
{ |
| 1684 |
int x = 1; |
| 1685 |
bump(x); |
| 1686 |
assert(x == 2); |
| 1687 |
} |
| 1688 |
|
| 1689 |
/***************************************************/ |
| 1690 |
|
| 1691 |
interface Test4174 |
| 1692 |
{ |
| 1693 |
void func(T)() {} |
| 1694 |
} |
| 1695 |
|
| 1696 |
/***************************************************/ |
| 1697 |
|
| 1698 |
auto foo84 = [1, 2.4]; |
| 1699 |
|
| 1700 |
void test84() |
| 1701 |
{ |
| 1702 |
pragma(msg, typeof([1, 2.4])); |
| 1703 |
static assert(is(typeof([1, 2.4]) == double[])); |
| 1704 |
|
| 1705 |
pragma(msg, typeof(foo84)); |
| 1706 |
static assert(is(typeof(foo84) == double[])); |
| 1707 |
} |
| 1708 |
|
| 1709 |
/***************************************************/ |
| 1710 |
|
| 1711 |
void test85() |
| 1712 |
{ |
| 1713 |
dstring c = "V\u00E4rld"; |
| 1714 |
c = c ~ '!'; |
| 1715 |
assert(c == "V\u00E4rld!"); |
| 1716 |
c = '@' ~ c; |
| 1717 |
assert(c == "@V\u00E4rld!"); |
| 1718 |
|
| 1719 |
wstring w = "V\u00E4rld"; |
| 1720 |
w = w ~ '!'; |
| 1721 |
assert(w == "V\u00E4rld!"); |
| 1722 |
w = '@' ~ w; |
| 1723 |
assert(w == "@V\u00E4rld!"); |
| 1724 |
|
| 1725 |
string s = "V\u00E4rld"; |
| 1726 |
s = s ~ '!'; |
| 1727 |
assert(s == "V\u00E4rld!"); |
| 1728 |
s = '@' ~ s; |
| 1729 |
assert(s == "@V\u00E4rld!"); |
| 1730 |
} |
| 1731 |
|
| 1732 |
/***************************************************/ |
| 1733 |
|
| 1734 |
void test86() |
| 1735 |
{ |
| 1736 |
int[][] a = [ [1], [2,3], [4] ]; |
| 1737 |
int[][] w = [ [1, 2], [3], [4, 5], [] ]; |
| 1738 |
int[][] x = [ [], [1, 2], [3], [4, 5], [] ]; |
| 1739 |
} |
| 1740 |
|
| 1741 |
/***************************************************/ |
| 1742 |
|
| 1743 |
// https://issues.dlang.org/show_bug.cgi?id=3379 |
| 1744 |
|
| 1745 |
T1[] find(T1, T2)(T1[] longer, T2[] shorter) |
| 1746 |
if (is(typeof(longer[0 .. 1] == shorter) : bool)) |
| 1747 |
{ |
| 1748 |
while (longer.length >= shorter.length) { |
| 1749 |
if (longer[0 .. shorter.length] == shorter) break; |
| 1750 |
longer = longer[1 .. $]; |
| 1751 |
} |
| 1752 |
return longer; |
| 1753 |
} |
| 1754 |
|
| 1755 |
auto max(T...)(T a) |
| 1756 |
if (T.length == 2 |
| 1757 |
&& is(typeof(a[1] > a[0] ? a[1] : a[0])) |
| 1758 |
|| T.length > 2 |
| 1759 |
&& is(typeof(max(max(a[0], a[1]), a[2 .. $])))) { |
| 1760 |
static if (T.length == 2) { |
| 1761 |
return a[1] > a[0] ? a[1] : a[0]; |
| 1762 |
} else { |
| 1763 |
return max(max(a[0], a[1]), a[2 .. $]); |
| 1764 |
} |
| 1765 |
} |
| 1766 |
|
| 1767 |
// Cases which would ICE or segfault |
| 1768 |
struct Bulldog(T){ |
| 1769 |
static void cat(Frog)(Frog f) if (true) |
| 1770 |
{ } |
| 1771 |
} |
| 1772 |
|
| 1773 |
void mouse(){ |
| 1774 |
Bulldog!(int).cat(0); |
| 1775 |
} |
| 1776 |
|
| 1777 |
void test87() |
| 1778 |
{ |
| 1779 |
double[] d1 = [ 6.0, 1.5, 2.4, 3 ]; |
| 1780 |
double[] d2 = [ 1.5, 2.4 ]; |
| 1781 |
assert(find(d1, d2) == d1[1 .. $]); |
| 1782 |
assert(find(d1, d2) == d1[1 .. $]); // Check for memory corruption |
| 1783 |
assert(max(4, 5) == 5); |
| 1784 |
assert(max(3, 4, 5) == 5); |
| 1785 |
} |
| 1786 |
|
| 1787 |
/***************************************************/ |
| 1788 |
|
| 1789 |
template test4284(alias v) { enum test4284 = v.length == 0; } |
| 1790 |
static assert(test4284!(cast(string)null)); |
| 1791 |
static assert(test4284!(cast(string[])null)); |
| 1792 |
|
| 1793 |
/***************************************************/ |
| 1794 |
|
| 1795 |
struct S88 |
| 1796 |
{ |
| 1797 |
void opDispatch(string s, T)(T i) |
| 1798 |
{ |
| 1799 |
printf("S.opDispatch('%.*s', %d)\n", cast(int)s.length, s.ptr, i); |
| 1800 |
} |
| 1801 |
} |
| 1802 |
|
| 1803 |
class C88 |
| 1804 |
{ |
| 1805 |
void opDispatch(string s)(int i) |
| 1806 |
{ |
| 1807 |
printf("C.opDispatch('%.*s', %d)\n", cast(int)s.length, s.ptr, i); |
| 1808 |
} |
| 1809 |
} |
| 1810 |
|
| 1811 |
struct D88 |
| 1812 |
{ |
| 1813 |
template opDispatch(string s) |
| 1814 |
{ |
| 1815 |
enum int opDispatch = 8; |
| 1816 |
} |
| 1817 |
} |
| 1818 |
|
| 1819 |
void test88() |
| 1820 |
{ |
| 1821 |
S88 s; |
| 1822 |
s.opDispatch!("hello")(7); |
| 1823 |
s.foo(7); |
| 1824 |
|
| 1825 |
auto c = new C88(); |
| 1826 |
c.foo(8); |
| 1827 |
|
| 1828 |
D88 d; |
| 1829 |
printf("d.foo = %d\n", d.foo); |
| 1830 |
assert(d.foo == 8); |
| 1831 |
} |
| 1832 |
|
| 1833 |
/***************************************************/ |
| 1834 |
|
| 1835 |
void test89() { |
| 1836 |
static struct X { |
| 1837 |
int x; |
| 1838 |
int bar() { return x; } |
| 1839 |
} |
| 1840 |
X s; |
| 1841 |
printf("%zd\n", s.sizeof); |
| 1842 |
assert(s.sizeof == 4); |
| 1843 |
} |
| 1844 |
|
| 1845 |
/***************************************************/ |
| 1846 |
|
| 1847 |
struct S90 |
| 1848 |
{ |
| 1849 |
void opDispatch( string name, T... )( T values ) |
| 1850 |
{ |
| 1851 |
assert(values[0] == 3.14); |
| 1852 |
} |
| 1853 |
} |
| 1854 |
|
| 1855 |
void test90( ) |
| 1856 |
{ S90 s; |
| 1857 |
s.opDispatch!("foo")( 3.14 ); |
| 1858 |
s.foo( 3.14 ); |
| 1859 |
} |
| 1860 |
|
| 1861 |
/***************************************************/ |
| 1862 |
|
| 1863 |
struct A7439(int r, int c) |
| 1864 |
{ |
| 1865 |
alias r R; |
| 1866 |
alias c C; |
| 1867 |
alias float[R * C] Data; |
| 1868 |
Data _data; |
| 1869 |
alias _data this; |
| 1870 |
|
| 1871 |
this(Data ar){ _data = ar; } |
| 1872 |
|
| 1873 |
pure ref float opIndex(size_t rr, size_t cc){ return _data[cc + rr * C]; } |
| 1874 |
} |
| 1875 |
|
| 1876 |
void test7439() |
| 1877 |
{ |
| 1878 |
A7439!(2, 2) a = A7439!(2, 2)([8, 3, 2, 9]); |
| 1879 |
a[0,0] -= a[0,0] * 2.0; |
| 1880 |
} |
| 1881 |
|
| 1882 |
/***************************************************/ |
| 1883 |
|
| 1884 |
void foo91(uint line = __LINE__) { printf("%d\n", line); } |
| 1885 |
|
| 1886 |
void test91() |
| 1887 |
{ |
| 1888 |
foo91(); |
| 1889 |
printf("%d\n", __LINE__); |
| 1890 |
} |
| 1891 |
|
| 1892 |
/***************************************************/ |
| 1893 |
|
| 1894 |
bool fun13468(Object e, typeof(null) needle) |
| 1895 |
{ |
| 1896 |
return (e == needle); |
| 1897 |
} |
| 1898 |
|
| 1899 |
void test13468() |
| 1900 |
{ |
| 1901 |
assert(fun13468(null, null)); |
| 1902 |
} |
| 1903 |
|
| 1904 |
/***************************************************/ |
| 1905 |
|
| 1906 |
auto ref foo92(ref int x) { return x; } |
| 1907 |
int bar92(ref int x) { return x; } |
| 1908 |
|
| 1909 |
void test92() |
| 1910 |
{ |
| 1911 |
int x = 3; |
| 1912 |
int i = bar92(foo92(x)); |
| 1913 |
assert(i == 3); |
| 1914 |
} |
| 1915 |
|
| 1916 |
/***************************************************/ |
| 1917 |
|
| 1918 |
struct Foo93 |
| 1919 |
{ |
| 1920 |
public int foo() const |
| 1921 |
{ |
| 1922 |
return 2; |
| 1923 |
} |
| 1924 |
} |
| 1925 |
|
| 1926 |
void test93() |
| 1927 |
{ |
| 1928 |
const Foo93 bar = Foo93(); |
| 1929 |
enum bla = bar.foo(); |
| 1930 |
assert(bla == 2); |
| 1931 |
} |
| 1932 |
|
| 1933 |
/***************************************************/ |
| 1934 |
|
| 1935 |
|
| 1936 |
extern(C++) class C1687 |
| 1937 |
{ |
| 1938 |
void func() {} |
| 1939 |
} |
| 1940 |
|
| 1941 |
void test1687() |
| 1942 |
{ |
| 1943 |
auto c = new C1687(); |
| 1944 |
assert(c.__vptr[0] == (&c.func).funcptr); |
| 1945 |
} |
| 1946 |
|
| 1947 |
/***************************************************/ |
| 1948 |
|
| 1949 |
struct Foo94 |
| 1950 |
{ |
| 1951 |
int x, y; |
| 1952 |
real z; |
| 1953 |
} |
| 1954 |
|
| 1955 |
pure nothrow Foo94 makeFoo(const int x, const int y) |
| 1956 |
{ |
| 1957 |
return Foo94(x, y, 3.0); |
| 1958 |
} |
| 1959 |
|
| 1960 |
void test94() |
| 1961 |
{ |
| 1962 |
auto f = makeFoo(1, 2); |
| 1963 |
assert(f.x==1); |
| 1964 |
assert(f.y==2); |
| 1965 |
assert(f.z==3); |
| 1966 |
} |
| 1967 |
|
| 1968 |
/***************************************************/ |
| 1969 |
|
| 1970 |
struct T95 |
| 1971 |
{ |
| 1972 |
@disable this(this) |
| 1973 |
{ |
| 1974 |
} |
| 1975 |
} |
| 1976 |
|
| 1977 |
struct S95 |
| 1978 |
{ |
| 1979 |
T95 t; |
| 1980 |
} |
| 1981 |
|
| 1982 |
@disable void foo95() { } |
| 1983 |
|
| 1984 |
struct T95A |
| 1985 |
{ |
| 1986 |
@disable this(this); |
| 1987 |
} |
| 1988 |
|
| 1989 |
struct S95A |
| 1990 |
{ |
| 1991 |
T95A t; |
| 1992 |
} |
| 1993 |
|
| 1994 |
@disable void foo95A() { } |
| 1995 |
|
| 1996 |
void test95() |
| 1997 |
{ |
| 1998 |
S95 s; |
| 1999 |
S95 t; |
| 2000 |
static assert(!__traits(compiles, t = s)); |
| 2001 |
static assert(!__traits(compiles, foo95())); |
| 2002 |
|
| 2003 |
S95A u; |
| 2004 |
S95A v; |
| 2005 |
static assert(!__traits(compiles, v = u)); |
| 2006 |
static assert(!__traits(compiles, foo95A())); |
| 2007 |
} |
| 2008 |
|
| 2009 |
/***************************************************/ |
| 2010 |
|
| 2011 |
struct S96(alias init) |
| 2012 |
{ |
| 2013 |
int[] content = init; |
| 2014 |
} |
| 2015 |
|
| 2016 |
void test96() |
| 2017 |
{ |
| 2018 |
S96!([12, 3]) s1; |
| 2019 |
S96!([1, 23]) s2; |
| 2020 |
//writeln(s1.content); |
| 2021 |
//writeln(s2.content); |
| 2022 |
assert(!is(typeof(s1) == typeof(s2))); |
| 2023 |
} |
| 2024 |
|
| 2025 |
/***************************************************/ |
| 2026 |
|
| 2027 |
struct A97 |
| 2028 |
{ |
| 2029 |
const bool opEquals(ref const A97) { return true; } |
| 2030 |
ref A97 opUnary(string op)() if (op == "++") |
| 2031 |
{ |
| 2032 |
return this; |
| 2033 |
} |
| 2034 |
} |
| 2035 |
|
| 2036 |
void test97() |
| 2037 |
{ |
| 2038 |
A97 a, b; |
| 2039 |
foreach (e; a .. b) { |
| 2040 |
} |
| 2041 |
} |
| 2042 |
|
| 2043 |
/***************************************************/ |
| 2044 |
|
| 2045 |
void test98() |
| 2046 |
{ |
| 2047 |
auto a = new int[2]; |
| 2048 |
// the name "length" should not pop up in an index expression |
| 2049 |
static assert(!is(typeof(a[length - 1]))); |
| 2050 |
} |
| 2051 |
|
| 2052 |
/***************************************************/ |
| 2053 |
|
| 2054 |
string s99; |
| 2055 |
|
| 2056 |
void bar99(string i) |
| 2057 |
{ |
| 2058 |
} |
| 2059 |
|
| 2060 |
void function(string) foo99(string i) |
| 2061 |
{ |
| 2062 |
return &bar99; |
| 2063 |
} |
| 2064 |
|
| 2065 |
void test99() |
| 2066 |
{ |
| 2067 |
foo99 (s99 ~= "a") (s99 ~= "b"); |
| 2068 |
assert(s99 == "ab"); |
| 2069 |
} |
| 2070 |
|
| 2071 |
/***************************************************/ |
| 2072 |
// https://issues.dlang.org/show_bug.cgi?id=5081 |
| 2073 |
|
| 2074 |
void test5081() |
| 2075 |
{ |
| 2076 |
static pure immutable(int[]) x1() |
| 2077 |
{ |
| 2078 |
int[] a = new int[](10); |
| 2079 |
return a; |
| 2080 |
} |
| 2081 |
static pure immutable(int[]) x2(int len) |
| 2082 |
{ |
| 2083 |
int[] a = new int[](len); |
| 2084 |
return a; |
| 2085 |
} |
| 2086 |
static pure immutable(int[]) x3(immutable(int[]) org) |
| 2087 |
{ |
| 2088 |
int[] a = new int[](org.length); |
| 2089 |
return a; |
| 2090 |
} |
| 2091 |
|
| 2092 |
immutable a1 = x1(); |
| 2093 |
immutable a2 = x2(10); |
| 2094 |
immutable a3 = x3([1,2]); |
| 2095 |
|
| 2096 |
static pure int[] y1() |
| 2097 |
{ |
| 2098 |
return new int[](10); |
| 2099 |
} |
| 2100 |
|
| 2101 |
immutable b1 = y1(); |
| 2102 |
} |
| 2103 |
|
| 2104 |
/***************************************************/ |
| 2105 |
|
| 2106 |
void test100() |
| 2107 |
{ |
| 2108 |
string s; |
| 2109 |
|
| 2110 |
/* Testing order of evaluation */ |
| 2111 |
void delegate(string, string) fun(string) { |
| 2112 |
s ~= "b"; |
| 2113 |
return delegate void(string x, string y) { s ~= "e"; }; |
| 2114 |
} |
| 2115 |
fun(s ~= "a")(s ~= "c", s ~= "d"); |
| 2116 |
assert(s == "abcde", s); |
| 2117 |
} |
| 2118 |
|
| 2119 |
/***************************************************/ |
| 2120 |
|
| 2121 |
void test101() |
| 2122 |
{ |
| 2123 |
int[] d1 = [ 6, 1, 2 ]; |
| 2124 |
byte[] d2 = [ 6, 1, 2 ]; |
| 2125 |
assert(d1 == d2); |
| 2126 |
d2 ~= [ 6, 1, 2 ]; |
| 2127 |
assert(d1 != d2); |
| 2128 |
} |
| 2129 |
|
| 2130 |
/***************************************************/ |
| 2131 |
|
| 2132 |
|
| 2133 |
void test5403() |
| 2134 |
{ |
| 2135 |
struct S |
| 2136 |
{ |
| 2137 |
static int front; |
| 2138 |
enum back = "yes!"; |
| 2139 |
bool empty; |
| 2140 |
void popAny() { empty = true; } |
| 2141 |
alias popAny popFront; |
| 2142 |
alias popAny popBack; |
| 2143 |
} |
| 2144 |
S.front = 7; |
| 2145 |
foreach(int i; S()) assert(i == 7); |
| 2146 |
S.front = 2; |
| 2147 |
foreach(i; S()) assert(i == 2); |
| 2148 |
foreach_reverse(i; S()) assert(i == "yes!"); |
| 2149 |
} |
| 2150 |
|
| 2151 |
/***************************************************/ |
| 2152 |
|
| 2153 |
static assert([1,2,3] == [1.0,2,3]); |
| 2154 |
|
| 2155 |
/***************************************************/ |
| 2156 |
|
| 2157 |
int transmogrify(uint) { return 1; } |
| 2158 |
int transmogrify(long) { return 2; } |
| 2159 |
|
| 2160 |
void test103() |
| 2161 |
{ |
| 2162 |
assert(transmogrify(42) == 1); |
| 2163 |
} |
| 2164 |
|
| 2165 |
/***************************************************/ |
| 2166 |
|
| 2167 |
int foo104(int x) |
| 2168 |
{ |
| 2169 |
int* p = &(x += 1); |
| 2170 |
return *p; |
| 2171 |
} |
| 2172 |
|
| 2173 |
int bar104(int *x) |
| 2174 |
{ |
| 2175 |
int* p = &(*x += 1); |
| 2176 |
return *p; |
| 2177 |
} |
| 2178 |
|
| 2179 |
void test104() |
| 2180 |
{ |
| 2181 |
auto i = foo104(1); |
| 2182 |
assert(i == 2); |
| 2183 |
i = bar104(&i); |
| 2184 |
assert(i == 3); |
| 2185 |
} |
| 2186 |
|
| 2187 |
/***************************************************/ |
| 2188 |
|
| 2189 |
ref int bump105(return ref int x) { return ++x; } |
| 2190 |
|
| 2191 |
void test105() |
| 2192 |
{ |
| 2193 |
int x = 1; |
| 2194 |
bump105(bump105(x)); // two increments |
| 2195 |
assert(x == 3); |
| 2196 |
} |
| 2197 |
|
| 2198 |
/***************************************************/ |
| 2199 |
|
| 2200 |
pure int genFactorials(int n) { |
| 2201 |
static pure int factorial(int n) { |
| 2202 |
if (n==2) return 1; |
| 2203 |
return factorial(2); |
| 2204 |
} |
| 2205 |
return factorial(n); |
| 2206 |
} |
| 2207 |
|
| 2208 |
/***************************************************/ |
| 2209 |
|
| 2210 |
void test107() |
| 2211 |
{ |
| 2212 |
int[6] a; |
| 2213 |
//writeln(a); |
| 2214 |
//writeln(a.init); |
| 2215 |
assert(a.init == [0,0,0,0,0,0]); |
| 2216 |
} |
| 2217 |
|
| 2218 |
/***************************************************/ |
| 2219 |
|
| 2220 |
class A109 {} |
| 2221 |
|
| 2222 |
void test109() |
| 2223 |
{ |
| 2224 |
immutable(A109) b; |
| 2225 |
A109 c; |
| 2226 |
auto z = true ? b : c; |
| 2227 |
//writeln(typeof(z).stringof); |
| 2228 |
static assert(is(typeof(z) == const(A109))); |
| 2229 |
} |
| 2230 |
|
| 2231 |
/***************************************************/ |
| 2232 |
|
| 2233 |
template Boo(T) {} |
| 2234 |
struct Foo110(T, alias V = Boo!T) |
| 2235 |
{ |
| 2236 |
pragma(msg, V.stringof); |
| 2237 |
static const s = V.stringof; |
| 2238 |
} |
| 2239 |
alias Foo110!double B110; |
| 2240 |
alias Foo110!int A110; |
| 2241 |
|
| 2242 |
static assert(B110.s == "Boo!double"); |
| 2243 |
static assert(A110.s == "Boo!int"); |
| 2244 |
|
| 2245 |
/***************************************************/ |
| 2246 |
|
| 2247 |
int test11247() |
| 2248 |
{ |
| 2249 |
static assert(is(byte[typeof(int.init).sizeof] == byte[4])); |
| 2250 |
static assert(is(byte[typeof(return).sizeof] == byte[4])); |
| 2251 |
return 0; |
| 2252 |
} |
| 2253 |
|
| 2254 |
/***************************************************/ |
| 2255 |
|
| 2256 |
// https://issues.dlang.org/show_bug.cgi?id=3716 |
| 2257 |
void test111() |
| 2258 |
{ |
| 2259 |
auto k1 = true ? [1,2] : []; // OK |
| 2260 |
auto k2 = true ? [[1,2]] : [[]]; |
| 2261 |
auto k3 = true ? [] : [[1,2]]; |
| 2262 |
auto k4 = true ? [[[]]] : [[[1,2]]]; |
| 2263 |
auto k5 = true ? [[[1,2]]] : [[[]]]; |
| 2264 |
auto k6 = true ? [] : [[[]]]; |
| 2265 |
static assert(!is(typeof(true ? [[[]]] : [[1,2]]))); // Must fail |
| 2266 |
} |
| 2267 |
|
| 2268 |
/***************************************************/ |
| 2269 |
// https://issues.dlang.org/show_bug.cgi?id=658 |
| 2270 |
|
| 2271 |
void test658() |
| 2272 |
{ |
| 2273 |
struct S { int i; } |
| 2274 |
class C { int i; } |
| 2275 |
|
| 2276 |
S s; |
| 2277 |
S* sp = &s; |
| 2278 |
with (sp) i = 42; |
| 2279 |
assert(s.i == 42); |
| 2280 |
with (&s) i = 43; |
| 2281 |
assert(s.i == 43); |
| 2282 |
|
| 2283 |
C c = new C; |
| 2284 |
C* cp = &c; |
| 2285 |
with (cp) i = 42; |
| 2286 |
assert(c.i == 42); |
| 2287 |
with (&c) i = 43; |
| 2288 |
assert(c.i == 43); |
| 2289 |
} |
| 2290 |
|
| 2291 |
/***************************************************/ |
| 2292 |
|
| 2293 |
void test3069() |
| 2294 |
{ |
| 2295 |
ubyte id = 0; |
| 2296 |
void[] v = [id] ~ [id]; |
| 2297 |
} |
| 2298 |
|
| 2299 |
/***************************************************/ |
| 2300 |
// https://issues.dlang.org/show_bug.cgi?id=4303 |
| 2301 |
|
| 2302 |
template foo112() if (__traits(compiles,undefined)) |
| 2303 |
{ |
| 2304 |
enum foo112 = false; |
| 2305 |
} |
| 2306 |
|
| 2307 |
template foo112() if (true) |
| 2308 |
{ |
| 2309 |
enum foo112 = true; |
| 2310 |
} |
| 2311 |
|
| 2312 |
pragma(msg,__traits(compiles,foo112!())); |
| 2313 |
static assert(__traits(compiles,foo112!())); |
| 2314 |
|
| 2315 |
const bool bar112 = foo112!(); |
| 2316 |
|
| 2317 |
|
| 2318 |
/***************************************************/ |
| 2319 |
|
| 2320 |
struct File113 |
| 2321 |
{ |
| 2322 |
this(int name) { } |
| 2323 |
|
| 2324 |
~this() { } |
| 2325 |
|
| 2326 |
void opAssign(File113 rhs) { } |
| 2327 |
|
| 2328 |
struct ByLine |
| 2329 |
{ |
| 2330 |
File113 file; |
| 2331 |
|
| 2332 |
this(int) { } |
| 2333 |
|
| 2334 |
} |
| 2335 |
|
| 2336 |
ByLine byLine() |
| 2337 |
{ |
| 2338 |
return ByLine(1); |
| 2339 |
} |
| 2340 |
} |
| 2341 |
|
| 2342 |
auto filter113(File113.ByLine rs) |
| 2343 |
{ |
| 2344 |
struct Filter |
| 2345 |
{ |
| 2346 |
this(File113.ByLine r) { } |
| 2347 |
} |
| 2348 |
|
| 2349 |
return Filter(rs); |
| 2350 |
} |
| 2351 |
|
| 2352 |
void test113() |
| 2353 |
{ |
| 2354 |
auto f = File113(1); |
| 2355 |
auto rx = f.byLine(); |
| 2356 |
auto file = filter113(rx); |
| 2357 |
} |
| 2358 |
|
| 2359 |
/***************************************************/ |
| 2360 |
|
| 2361 |
template foo114(fun...) |
| 2362 |
{ |
| 2363 |
auto foo114(int[] args) |
| 2364 |
{ |
| 2365 |
return 1; |
| 2366 |
} |
| 2367 |
} |
| 2368 |
|
| 2369 |
pragma(msg, typeof(foo114!"a + b"([1,2,3]))); |
| 2370 |
|
| 2371 |
/***************************************************/ |
| 2372 |
// https://issues.dlang.org/show_bug.cgi?id=3935 |
| 2373 |
|
| 2374 |
struct Foo115 { |
| 2375 |
void opBinary(string op)(Foo other) { |
| 2376 |
pragma(msg, "op: " ~ op); |
| 2377 |
assert(0); |
| 2378 |
} |
| 2379 |
} |
| 2380 |
|
| 2381 |
void test115() |
| 2382 |
{ |
| 2383 |
Foo115 f; |
| 2384 |
f = f; |
| 2385 |
} |
| 2386 |
|
| 2387 |
/***************************************************/ |
| 2388 |
// https://issues.dlang.org/show_bug.cgi?id=2477 |
| 2389 |
|
| 2390 |
void foo116(T,)(T t) { T x; } |
| 2391 |
|
| 2392 |
void test116() |
| 2393 |
{ |
| 2394 |
int[] data = [1,2,3,]; // OK |
| 2395 |
|
| 2396 |
data = [ 1,2,3, ]; // fails |
| 2397 |
auto i = data[1,]; |
| 2398 |
foo116!(int)(3); |
| 2399 |
foo116!(int,)(3); |
| 2400 |
foo116!(int,)(3,); |
| 2401 |
} |
| 2402 |
|
| 2403 |
/***************************************************/ |
| 2404 |
|
| 2405 |
void test1891() |
| 2406 |
{ |
| 2407 |
struct C { |
| 2408 |
char[8] x = "helloabc"; |
| 2409 |
} |
| 2410 |
|
| 2411 |
int main() |
| 2412 |
{ |
| 2413 |
C* a = new C; |
| 2414 |
C*[] b; |
| 2415 |
b ~= new C; |
| 2416 |
|
| 2417 |
auto g = a ~ b; |
| 2418 |
assert(g[0] && g[1] && g[0].x == g[1].x); |
| 2419 |
|
| 2420 |
return 0; |
| 2421 |
} |
| 2422 |
} |
| 2423 |
|
| 2424 |
/***************************************************/ |
| 2425 |
// https://issues.dlang.org/show_bug.cgi?id=4291 |
| 2426 |
|
| 2427 |
void test117() pure |
| 2428 |
{ |
| 2429 |
mixin declareVariable; |
| 2430 |
var = 42; |
| 2431 |
mixin declareFunction; |
| 2432 |
readVar(); |
| 2433 |
} |
| 2434 |
template declareVariable() { int var; } |
| 2435 |
template declareFunction() |
| 2436 |
{ |
| 2437 |
int readVar() { return var; } |
| 2438 |
} |
| 2439 |
|
| 2440 |
/***************************************************/ |
| 2441 |
// https://issues.dlang.org/show_bug.cgi?id=4177 |
| 2442 |
|
| 2443 |
pure real log118(real x) { |
| 2444 |
if (__ctfe) |
| 2445 |
return 0.0; |
| 2446 |
else |
| 2447 |
return 1.0; |
| 2448 |
} |
| 2449 |
|
| 2450 |
enum x118 = log118(4.0); |
| 2451 |
|
| 2452 |
void test118() {} |
| 2453 |
|
| 2454 |
/***************************************************/ |
| 2455 |
|
| 2456 |
void bug4465() |
| 2457 |
{ |
| 2458 |
const a = 2 ^^ 2; |
| 2459 |
int b = a; |
| 2460 |
} |
| 2461 |
|
| 2462 |
/***************************************************/ |
| 2463 |
|
| 2464 |
pure void foo(int *p) |
| 2465 |
{ |
| 2466 |
*p = 3; |
| 2467 |
} |
| 2468 |
|
| 2469 |
pure void test120() |
| 2470 |
{ |
| 2471 |
int i; |
| 2472 |
foo(&i); |
| 2473 |
assert(i == 3); |
| 2474 |
} |
| 2475 |
|
| 2476 |
/***************************************************/ |
| 2477 |
// https://issues.dlang.org/show_bug.cgi?id=4866 |
| 2478 |
|
| 2479 |
immutable int[3] statik = [ 1, 2, 3 ]; |
| 2480 |
enum immutable(int)[] dynamic = statik; |
| 2481 |
|
| 2482 |
static assert(is(typeof(dynamic) == immutable(int)[])); |
| 2483 |
static if (! is(typeof(dynamic) == immutable(int)[])) |
| 2484 |
{ |
| 2485 |
static assert(0); // (7) |
| 2486 |
} |
| 2487 |
pragma(msg, "!! ", typeof(dynamic)); |
| 2488 |
|
| 2489 |
/***************************************************/ |
| 2490 |
// https://issues.dlang.org/show_bug.cgi?id=2943 |
| 2491 |
|
| 2492 |
struct Foo2943 |
| 2493 |
{ |
| 2494 |
int a; |
| 2495 |
int b; |
| 2496 |
alias b this; |
| 2497 |
} |
| 2498 |
|
| 2499 |
void test122() |
| 2500 |
{ |
| 2501 |
Foo2943 foo, foo2; |
| 2502 |
foo.a = 1; |
| 2503 |
foo.b = 2; |
| 2504 |
foo2.a = 3; |
| 2505 |
foo2.b = 4; |
| 2506 |
|
| 2507 |
foo2 = foo; |
| 2508 |
assert(foo2.a == foo.a); |
| 2509 |
} |
| 2510 |
|
| 2511 |
/***************************************************/ |
| 2512 |
// https://issues.dlang.org/show_bug.cgi?id=4641 |
| 2513 |
|
| 2514 |
struct S123 { |
| 2515 |
int i; |
| 2516 |
alias i this; |
| 2517 |
} |
| 2518 |
|
| 2519 |
void test123() { |
| 2520 |
S123[int] ss; |
| 2521 |
ss[0] = S123.init; // This line causes Range Violation. |
| 2522 |
} |
| 2523 |
|
| 2524 |
/***************************************************/ |
| 2525 |
// https://issues.dlang.org/show_bug.cgi?id=2451 |
| 2526 |
|
| 2527 |
struct Foo124 { |
| 2528 |
int z = 3; |
| 2529 |
void opAssign(Foo124 x) { z= 2;} |
| 2530 |
} |
| 2531 |
|
| 2532 |
struct Bar124 { |
| 2533 |
int z = 3; |
| 2534 |
this(this){ z = 17; } |
| 2535 |
} |
| 2536 |
|
| 2537 |
void test124() { |
| 2538 |
Foo124[string] stuff; |
| 2539 |
stuff["foo"] = Foo124.init; |
| 2540 |
assert(stuff["foo"].z == 3); |
| 2541 |
stuff["foo"] = Foo124.init; |
| 2542 |
assert(stuff["foo"].z == 2); |
| 2543 |
|
| 2544 |
Bar124[string] stuff2; |
| 2545 |
Bar124 q; |
| 2546 |
stuff2["dog"] = q; |
| 2547 |
assert(stuff2["dog"].z == 17); |
| 2548 |
} |
| 2549 |
|
| 2550 |
/***************************************************/ |
| 2551 |
|
| 2552 |
void doNothing() {} |
| 2553 |
|
| 2554 |
void bug5071(short d, ref short c) { |
| 2555 |
assert(c==0x76); |
| 2556 |
|
| 2557 |
void closure() { |
| 2558 |
auto c2 = c; |
| 2559 |
auto d2 = d; |
| 2560 |
doNothing(); |
| 2561 |
} |
| 2562 |
auto useless = &closure; |
| 2563 |
} |
| 2564 |
|
| 2565 |
void test125() |
| 2566 |
{ |
| 2567 |
short c = 0x76; |
| 2568 |
bug5071(7, c); |
| 2569 |
} |
| 2570 |
|
| 2571 |
/***************************************************/ |
| 2572 |
|
| 2573 |
struct Foo126 |
| 2574 |
{ |
| 2575 |
static Foo126 opCall(in Foo126 _f) pure |
| 2576 |
{ |
| 2577 |
return _f; |
| 2578 |
} |
| 2579 |
} |
| 2580 |
|
| 2581 |
/***************************************************/ |
| 2582 |
|
| 2583 |
void test796() |
| 2584 |
{ |
| 2585 |
struct S { invariant() { throw new Exception(""); } } |
| 2586 |
S* s; |
| 2587 |
try { |
| 2588 |
assert(s); |
| 2589 |
} catch (Error) { |
| 2590 |
} |
| 2591 |
} |
| 2592 |
|
| 2593 |
/***************************************************/ |
| 2594 |
|
| 2595 |
void test7077() |
| 2596 |
{ |
| 2597 |
if(0) mixin("auto x = 2;"); |
| 2598 |
auto x = 1; |
| 2599 |
} |
| 2600 |
|
| 2601 |
/***************************************************/ |
| 2602 |
|
| 2603 |
struct Tuple127(S...) |
| 2604 |
{ |
| 2605 |
S expand; |
| 2606 |
alias expand this; |
| 2607 |
} |
| 2608 |
|
| 2609 |
alias Tuple127!(int, int) Foo127; |
| 2610 |
|
| 2611 |
void test127() |
| 2612 |
{ |
| 2613 |
Foo127[] m_array; |
| 2614 |
Foo127 f; |
| 2615 |
m_array ~= f; |
| 2616 |
} |
| 2617 |
|
| 2618 |
/***************************************************/ |
| 2619 |
|
| 2620 |
struct Bug4434 {} |
| 2621 |
alias const Bug4434* IceConst4434; |
| 2622 |
alias shared Bug4434* IceShared4434; |
| 2623 |
alias shared Bug4434[] IceSharedArray4434; |
| 2624 |
alias immutable Bug4434* IceImmutable4434; |
| 2625 |
alias shared const Bug4434* IceSharedConst4434; |
| 2626 |
|
| 2627 |
alias int MyInt4434; |
| 2628 |
alias const MyInt4434[3] IceConstInt4434; |
| 2629 |
|
| 2630 |
alias immutable string[] Bug4830; |
| 2631 |
|
| 2632 |
/***************************************************/ |
| 2633 |
// https://issues.dlang.org/show_bug.cgi?id=4254 |
| 2634 |
|
| 2635 |
void bub(const inout int other) {} |
| 2636 |
|
| 2637 |
void test128() |
| 2638 |
{ |
| 2639 |
bub(1); |
| 2640 |
} |
| 2641 |
|
| 2642 |
|
| 2643 |
/***************************************************/ |
| 2644 |
|
| 2645 |
pure nothrow @safe auto bug4915a() { return 0; } |
| 2646 |
pure nothrow @safe int bug4915b() { return bug4915a(); } |
| 2647 |
|
| 2648 |
void bug4915c() |
| 2649 |
{ |
| 2650 |
pure nothrow @safe int d() { return 0; } |
| 2651 |
int e() pure nothrow @safe { return d(); } |
| 2652 |
} |
| 2653 |
|
| 2654 |
/***************************************************/ |
| 2655 |
// https://issues.dlang.org/show_bug.cgi?id=5164 |
| 2656 |
|
| 2657 |
static if (is(int Q == int, Z...)) { } |
| 2658 |
|
| 2659 |
/***************************************************/ |
| 2660 |
// https://issues.dlang.org/show_bug.cgi?id=5195 |
| 2661 |
|
| 2662 |
alias typeof(foo5195) food5195; |
| 2663 |
const int * foo5195 = null; |
| 2664 |
alias typeof(foo5195) good5195; |
| 2665 |
static assert( is (food5195 == good5195)); |
| 2666 |
|
| 2667 |
/***************************************************/ |
| 2668 |
|
| 2669 |
version (Windows) |
| 2670 |
{ |
| 2671 |
} |
| 2672 |
else |
| 2673 |
{ |
| 2674 |
int[0] var5332; |
| 2675 |
void test5332() { auto x = var5332; } |
| 2676 |
} |
| 2677 |
|
| 2678 |
/***************************************************/ |
| 2679 |
// https://issues.dlang.org/show_bug.cgi?id=5191 |
| 2680 |
|
| 2681 |
struct Foo129 |
| 2682 |
{ |
| 2683 |
void add(T)(T value) nothrow |
| 2684 |
{ |
| 2685 |
this.value += value; |
| 2686 |
} |
| 2687 |
|
| 2688 |
this(int value) |
| 2689 |
{ |
| 2690 |
this.value = value; |
| 2691 |
} |
| 2692 |
|
| 2693 |
int value; |
| 2694 |
} |
| 2695 |
|
| 2696 |
void test129() |
| 2697 |
{ |
| 2698 |
auto foo = Foo129(5); |
| 2699 |
assert(foo.value == 5); |
| 2700 |
|
| 2701 |
foo.add(2); |
| 2702 |
printf("%d\n", foo.value); |
| 2703 |
assert(foo.value == 7); |
| 2704 |
|
| 2705 |
foo.add(3); |
| 2706 |
printf("%d\n", foo.value); |
| 2707 |
assert(foo.value == 10); |
| 2708 |
|
| 2709 |
foo.add(3); |
| 2710 |
printf("%d\n", foo.value); |
| 2711 |
assert(foo.value == 13); |
| 2712 |
|
| 2713 |
void delegate (int) nothrow dg = &foo.add!(int); |
| 2714 |
dg(7); |
| 2715 |
assert(foo.value == 20); |
| 2716 |
} |
| 2717 |
|
| 2718 |
/***************************************************/ |
| 2719 |
// https://issues.dlang.org/show_bug.cgi?id=6169 |
| 2720 |
|
| 2721 |
auto ctfefunc6169() { return "{}"; } |
| 2722 |
enum ctfefptr6169 = &ctfefunc6169; |
| 2723 |
int ctfefunc6169a() { return 1; } |
| 2724 |
template x6169(string c) { alias int x6169; } |
| 2725 |
template TT6169(T...) { alias T TT6169; } |
| 2726 |
@property ctfeprop6169() { return "g"; } |
| 2727 |
|
| 2728 |
void test6169() pure @safe |
| 2729 |
{ |
| 2730 |
enum a = ctfefunc6169(); |
| 2731 |
static b = ctfefunc6169(); |
| 2732 |
x6169!(ctfefunc6169()) tt; |
| 2733 |
mixin(ctfefunc6169()); |
| 2734 |
static if(ctfefunc6169()) {} |
| 2735 |
pragma(msg, ctfefunc6169()); |
| 2736 |
enum xx |
| 2737 |
{ |
| 2738 |
k = 0, |
| 2739 |
j = ctfefunc6169a() |
| 2740 |
} |
| 2741 |
auto g = mixin('"' ~ ctfefunc6169() ~ '"'); |
| 2742 |
//auto h = import("testx.d" ~ false ? ctfefunc() : ""); |
| 2743 |
alias TT6169!(int, int)[ctfefunc6169a()..ctfefunc6169a()] i; |
| 2744 |
alias TT6169!(int, int)[ctfefunc6169a()] j; |
| 2745 |
int[ctfefunc6169a()+1] k; |
| 2746 |
alias int[ctfefunc6169a()] l; |
| 2747 |
switch(1) |
| 2748 |
{ |
| 2749 |
//case ctfefunc6169a(): // Can't do this because of case variables |
| 2750 |
case ctfefunc6169a()+1: |
| 2751 |
.. |
| 2752 |
case ctfefunc6169a()+2: |
| 2753 |
default: |
| 2754 |
break; |
| 2755 |
} |
| 2756 |
static assert(ctfefunc6169a()); |
| 2757 |
void fun(int i : ctfefunc6169a() = ctfefunc6169a(), alias j)() if (ctfefunc6169a()) {} |
| 2758 |
fun!(ctfefunc6169a(), ctfefunc6169())(); |
| 2759 |
enum z = ctfefptr6169(); |
| 2760 |
|
| 2761 |
auto p = mixin(ctfeprop6169); |
| 2762 |
} |
| 2763 |
|
| 2764 |
/***************************************************/ |
| 2765 |
// https://issues.dlang.org/show_bug.cgi?id=10506 |
| 2766 |
|
| 2767 |
void impureFunc10506() {} |
| 2768 |
string join10506(RoR)(RoR ror) |
| 2769 |
{ |
| 2770 |
impureFunc10506(); |
| 2771 |
return ror[0] ~ ror[1]; |
| 2772 |
} |
| 2773 |
|
| 2774 |
void test10506() pure |
| 2775 |
{ |
| 2776 |
void foobar() {} |
| 2777 |
|
| 2778 |
mixin(["foo", "bar"].join10506()~";"); |
| 2779 |
} |
| 2780 |
|
| 2781 |
/***************************************************/ |
| 2782 |
|
| 2783 |
const shared class C5107 |
| 2784 |
{ |
| 2785 |
int x; |
| 2786 |
} |
| 2787 |
|
| 2788 |
static assert(is(typeof(C5107.x) == const)); // okay |
| 2789 |
static assert(is(typeof(C5107.x) == shared)); // fails! |
| 2790 |
|
| 2791 |
/***************************************************/ |
| 2792 |
|
| 2793 |
immutable struct S3598 |
| 2794 |
{ |
| 2795 |
static void funkcja() { } |
| 2796 |
} |
| 2797 |
|
| 2798 |
/***************************************************/ |
| 2799 |
// https://issues.dlang.org/show_bug.cgi?id=4211 |
| 2800 |
|
| 2801 |
@safe struct X130 |
| 2802 |
{ |
| 2803 |
void func() { } |
| 2804 |
} |
| 2805 |
|
| 2806 |
@safe class Y130 |
| 2807 |
{ |
| 2808 |
void func() { } |
| 2809 |
} |
| 2810 |
|
| 2811 |
@safe void test130() |
| 2812 |
{ |
| 2813 |
X130 x; |
| 2814 |
x.func(); |
| 2815 |
auto y = new Y130; |
| 2816 |
y.func(); |
| 2817 |
} |
| 2818 |
|
| 2819 |
/***************************************************/ |
| 2820 |
|
| 2821 |
template Return(alias fun) |
| 2822 |
{ |
| 2823 |
static if (is(typeof(fun) R == return)) alias R Return; |
| 2824 |
} |
| 2825 |
|
| 2826 |
interface I4217 |
| 2827 |
{ |
| 2828 |
int square(int n); |
| 2829 |
real square(real n); |
| 2830 |
} |
| 2831 |
alias Return!( __traits(getOverloads, I4217, "square")[0] ) R4217; |
| 2832 |
alias Return!( __traits(getOverloads, I4217, "square")[1] ) S4217; |
| 2833 |
|
| 2834 |
static assert(! is(R4217 == S4217)); |
| 2835 |
|
| 2836 |
/***************************************************/ |
| 2837 |
// https://issues.dlang.org/show_bug.cgi?id=5094 |
| 2838 |
|
| 2839 |
void test131() |
| 2840 |
{ |
| 2841 |
S131 s; |
| 2842 |
int[] conv = s; |
| 2843 |
} |
| 2844 |
|
| 2845 |
struct S131 |
| 2846 |
{ |
| 2847 |
@property int[] get() { return [1,2,3]; } |
| 2848 |
alias get this; |
| 2849 |
} |
| 2850 |
|
| 2851 |
/***************************************************/ |
| 2852 |
|
| 2853 |
struct S7545 |
| 2854 |
{ |
| 2855 |
uint id; |
| 2856 |
alias id this; |
| 2857 |
} |
| 2858 |
|
| 2859 |
void test7545() |
| 2860 |
{ |
| 2861 |
auto id = 0 ? S7545() : -1; |
| 2862 |
} |
| 2863 |
|
| 2864 |
/***************************************************/ |
| 2865 |
// https://issues.dlang.org/show_bug.cgi?id=5020 |
| 2866 |
|
| 2867 |
void test132() |
| 2868 |
{ |
| 2869 |
S132 s; |
| 2870 |
if (!s) {} |
| 2871 |
} |
| 2872 |
|
| 2873 |
struct S132 |
| 2874 |
{ |
| 2875 |
bool cond; |
| 2876 |
alias cond this; |
| 2877 |
} |
| 2878 |
|
| 2879 |
/***************************************************/ |
| 2880 |
// https://issues.dlang.org/show_bug.cgi?id=5343 |
| 2881 |
|
| 2882 |
struct Tuple5343(Specs...) |
| 2883 |
{ |
| 2884 |
Specs[0] field; |
| 2885 |
} |
| 2886 |
|
| 2887 |
struct S5343(E) |
| 2888 |
{ |
| 2889 |
immutable E x; |
| 2890 |
} |
| 2891 |
enum A5343{a,b,c} |
| 2892 |
alias Tuple5343!(A5343) TA5343; |
| 2893 |
alias S5343!(A5343) SA5343; |
| 2894 |
|
| 2895 |
/***************************************************/ |
| 2896 |
// https://issues.dlang.org/show_bug.cgi?id=5365 |
| 2897 |
|
| 2898 |
interface IFactory |
| 2899 |
{ |
| 2900 |
void foo(); |
| 2901 |
} |
| 2902 |
|
| 2903 |
class A133 |
| 2904 |
{ |
| 2905 |
protected static class Factory : IFactory |
| 2906 |
{ |
| 2907 |
void foo() |
| 2908 |
{ |
| 2909 |
} |
| 2910 |
} |
| 2911 |
|
| 2912 |
this() |
| 2913 |
{ |
| 2914 |
_factory = createFactory(); |
| 2915 |
} |
| 2916 |
|
| 2917 |
protected IFactory createFactory() |
| 2918 |
{ |
| 2919 |
return new Factory; |
| 2920 |
} |
| 2921 |
|
| 2922 |
private IFactory _factory; |
| 2923 |
@property final IFactory factory() |
| 2924 |
{ |
| 2925 |
return _factory; |
| 2926 |
} |
| 2927 |
|
| 2928 |
alias factory this; |
| 2929 |
} |
| 2930 |
|
| 2931 |
void test133() |
| 2932 |
{ |
| 2933 |
|
| 2934 |
IFactory f = new A133; |
| 2935 |
f.foo(); // segfault |
| 2936 |
} |
| 2937 |
|
| 2938 |
/***************************************************/ |
| 2939 |
// https://issues.dlang.org/show_bug.cgi?id=5365 |
| 2940 |
|
| 2941 |
class B134 |
| 2942 |
{ |
| 2943 |
} |
| 2944 |
|
| 2945 |
class A134 |
| 2946 |
{ |
| 2947 |
|
| 2948 |
B134 _b; |
| 2949 |
|
| 2950 |
this() |
| 2951 |
{ |
| 2952 |
_b = new B134; |
| 2953 |
} |
| 2954 |
|
| 2955 |
B134 b() |
| 2956 |
{ |
| 2957 |
return _b; |
| 2958 |
} |
| 2959 |
|
| 2960 |
alias b this; |
| 2961 |
} |
| 2962 |
|
| 2963 |
void test134() |
| 2964 |
{ |
| 2965 |
|
| 2966 |
auto a = new A134; |
| 2967 |
B134 b = a; // b is null |
| 2968 |
assert(a._b is b); // fails |
| 2969 |
} |
| 2970 |
|
| 2971 |
/***************************************************/ |
| 2972 |
// https://issues.dlang.org/show_bug.cgi?id=5025 |
| 2973 |
|
| 2974 |
struct S135 { |
| 2975 |
void delegate() d; |
| 2976 |
} |
| 2977 |
|
| 2978 |
void test135() |
| 2979 |
{ |
| 2980 |
shared S135[] s; |
| 2981 |
if (0) |
| 2982 |
s[0] = S135(); |
| 2983 |
} |
| 2984 |
|
| 2985 |
/***************************************************/ |
| 2986 |
// https://issues.dlang.org/show_bug.cgi?id=5545 |
| 2987 |
|
| 2988 |
bool enforce136(bool value, lazy const(char)[] msg = null) { |
| 2989 |
if(!value) { |
| 2990 |
return false; |
| 2991 |
} |
| 2992 |
|
| 2993 |
return value; |
| 2994 |
} |
| 2995 |
|
| 2996 |
struct Perm { |
| 2997 |
byte[3] perm; |
| 2998 |
ubyte i; |
| 2999 |
|
| 3000 |
this(byte[] input) { |
| 3001 |
foreach(elem; input) { |
| 3002 |
enforce136(i < 3); |
| 3003 |
perm[i++] = elem; |
| 3004 |
printf("%d\n", i); // Never gets incremented. Stays at 0. |
| 3005 |
} |
| 3006 |
} |
| 3007 |
} |
| 3008 |
|
| 3009 |
void test136() { |
| 3010 |
byte[] stuff = [0, 1, 2]; |
| 3011 |
auto perm2 = Perm(stuff); |
| 3012 |
//writeln(perm2.perm); // Prints [2, 0, 0] |
| 3013 |
assert(perm2.perm[] == [0, 1, 2]); |
| 3014 |
} |
| 3015 |
|
| 3016 |
/***************************************************/ |
| 3017 |
// https://issues.dlang.org/show_bug.cgi?id=4097 |
| 3018 |
|
| 3019 |
void foo4097() { } |
| 3020 |
alias typeof(&foo4097) T4097; |
| 3021 |
static assert(is(T4097 X : X*) && is(X == function)); |
| 3022 |
|
| 3023 |
static assert(!is(X)); |
| 3024 |
|
| 3025 |
/***************************************************/ |
| 3026 |
// https://issues.dlang.org/show_bug.cgi?id=5798 |
| 3027 |
|
| 3028 |
void assign9(ref int lhs) pure { |
| 3029 |
lhs = 9; |
| 3030 |
} |
| 3031 |
|
| 3032 |
void assign8(ref int rhs) pure { |
| 3033 |
rhs = 8; |
| 3034 |
} |
| 3035 |
|
| 3036 |
int test137(){ |
| 3037 |
int a=1,b=2; |
| 3038 |
assign8(b),assign9(a); |
| 3039 |
assert(a == 9); |
| 3040 |
assert(b == 8); // <-- fail |
| 3041 |
|
| 3042 |
assign9(b),assign8(a); |
| 3043 |
assert(a == 8); |
| 3044 |
assert(b == 9); // <-- fail |
| 3045 |
|
| 3046 |
return 0; |
| 3047 |
} |
| 3048 |
|
| 3049 |
/***************************************************/ |
| 3050 |
|
| 3051 |
// https://issues.dlang.org/show_bug.cgi?id=9366 |
| 3052 |
static assert(!is(typeof((void[]).init ~ cast(void)0))); |
| 3053 |
static assert(!is(typeof(cast(void)0 ~ (void[]).init))); |
| 3054 |
|
| 3055 |
/***************************************************/ |
| 3056 |
|
| 3057 |
struct Size138 |
| 3058 |
{ |
| 3059 |
union |
| 3060 |
{ |
| 3061 |
struct |
| 3062 |
{ |
| 3063 |
int width; |
| 3064 |
int height; |
| 3065 |
} |
| 3066 |
|
| 3067 |
long size; |
| 3068 |
} |
| 3069 |
} |
| 3070 |
|
| 3071 |
enum Size138 foo138 = {2 ,5}; |
| 3072 |
|
| 3073 |
Size138 bar138 = foo138; |
| 3074 |
|
| 3075 |
void test138() |
| 3076 |
{ |
| 3077 |
assert(bar138.width == 2); |
| 3078 |
assert(bar138.height == 5); |
| 3079 |
} |
| 3080 |
|
| 3081 |
/***************************************************/ |
| 3082 |
|
| 3083 |
void test3822() |
| 3084 |
{ |
| 3085 |
import core.stdc.stdlib; |
| 3086 |
int i = 0; |
| 3087 |
void* ptr; |
| 3088 |
while(i++ != 2) |
| 3089 |
{ |
| 3090 |
auto p = alloca(2); |
| 3091 |
assert(p != ptr); |
| 3092 |
ptr = p; |
| 3093 |
} |
| 3094 |
} |
| 3095 |
|
| 3096 |
/***************************************************/ |
| 3097 |
|
| 3098 |
// https://issues.dlang.org/show_bug.cgi?id=5939 |
| 3099 |
// https://issues.dlang.org/show_bug.cgi?id=5940 |
| 3100 |
|
| 3101 |
template map(fun...) |
| 3102 |
{ |
| 3103 |
auto map(double[] r) |
| 3104 |
{ |
| 3105 |
struct Result |
| 3106 |
{ |
| 3107 |
this(double[] input) |
| 3108 |
{ |
| 3109 |
} |
| 3110 |
} |
| 3111 |
|
| 3112 |
return Result(r); |
| 3113 |
} |
| 3114 |
} |
| 3115 |
|
| 3116 |
|
| 3117 |
void test139() |
| 3118 |
{ |
| 3119 |
double[] x; |
| 3120 |
alias typeof(map!"a"(x)) T; |
| 3121 |
T a = void; |
| 3122 |
auto b = map!"a"(x); |
| 3123 |
auto c = [map!"a"(x)]; |
| 3124 |
T[3] d = void; |
| 3125 |
} |
| 3126 |
|
| 3127 |
|
| 3128 |
/***************************************************/ |
| 3129 |
// https://issues.dlang.org/show_bug.cgi?id=5966 |
| 3130 |
|
| 3131 |
string[] foo5966(string[] a) |
| 3132 |
{ |
| 3133 |
a[0] = a[0][0..$]; |
| 3134 |
return a; |
| 3135 |
} |
| 3136 |
|
| 3137 |
enum var5966 = foo5966([""]); |
| 3138 |
|
| 3139 |
/***************************************************/ |
| 3140 |
// https://issues.dlang.org/show_bug.cgi?id=5975 |
| 3141 |
|
| 3142 |
int foo5975(wstring replace) |
| 3143 |
{ |
| 3144 |
wstring value = ""; |
| 3145 |
value ~= replace; |
| 3146 |
return 1; |
| 3147 |
} |
| 3148 |
|
| 3149 |
enum X5975 = foo5975("X"w); |
| 3150 |
|
| 3151 |
/***************************************************/ |
| 3152 |
// https://issues.dlang.org/show_bug.cgi?id=5965 |
| 3153 |
|
| 3154 |
template mapx(fun...) if (fun.length >= 1) |
| 3155 |
{ |
| 3156 |
int mapx(Range)(Range r) |
| 3157 |
{ |
| 3158 |
return 1; |
| 3159 |
} |
| 3160 |
} |
| 3161 |
|
| 3162 |
void test140() |
| 3163 |
{ |
| 3164 |
int foo(int i) { return i; } |
| 3165 |
|
| 3166 |
int[] arr; |
| 3167 |
auto x = mapx!( (int a){return foo(a);} )(arr); |
| 3168 |
} |
| 3169 |
|
| 3170 |
/***************************************************/ |
| 3171 |
|
| 3172 |
void bug5976() |
| 3173 |
{ |
| 3174 |
int[] barr; |
| 3175 |
int * k; |
| 3176 |
foreach (ref b; barr) |
| 3177 |
{ |
| 3178 |
scope(failure) |
| 3179 |
k = &b; |
| 3180 |
k = &b; |
| 3181 |
} |
| 3182 |
} |
| 3183 |
|
| 3184 |
/***************************************************/ |
| 3185 |
// https://issues.dlang.org/show_bug.cgi?id=5771 |
| 3186 |
|
| 3187 |
struct S141 |
| 3188 |
{ |
| 3189 |
this(A)(auto ref A a){} |
| 3190 |
} |
| 3191 |
|
| 3192 |
void test141() |
| 3193 |
{ |
| 3194 |
S141 s = S141(10); |
| 3195 |
} |
| 3196 |
|
| 3197 |
/***************************************************/ |
| 3198 |
|
| 3199 |
class test5498_A {} |
| 3200 |
class test5498_B : test5498_A {} |
| 3201 |
class test5498_C : test5498_A {} |
| 3202 |
|
| 3203 |
static assert(is(typeof([test5498_B.init, test5498_C.init]) == test5498_A[])); |
| 3204 |
|
| 3205 |
/***************************************************/ |
| 3206 |
// https://issues.dlang.org/show_bug.cgi?id=3688 |
| 3207 |
|
| 3208 |
struct S142 |
| 3209 |
{ |
| 3210 |
int v; |
| 3211 |
this(int n) pure { v = n; } |
| 3212 |
const bool opCast(T:bool)() { return true; } |
| 3213 |
} |
| 3214 |
|
| 3215 |
void test142() |
| 3216 |
{ |
| 3217 |
if (int a = 1) |
| 3218 |
assert(a == 1); |
| 3219 |
else assert(0); |
| 3220 |
|
| 3221 |
if (const int a = 2) |
| 3222 |
assert(a == 2); |
| 3223 |
else assert(0); |
| 3224 |
|
| 3225 |
if (immutable int a = 3) |
| 3226 |
assert(a == 3); |
| 3227 |
else assert(0); |
| 3228 |
|
| 3229 |
if (auto s = S142(10)) |
| 3230 |
assert(s.v == 10); |
| 3231 |
else assert(0); |
| 3232 |
|
| 3233 |
if (auto s = const(S142)(20)) |
| 3234 |
assert(s.v == 20); |
| 3235 |
else assert(0); |
| 3236 |
|
| 3237 |
if (auto s = immutable(S142)(30)) |
| 3238 |
assert(s.v == 30); |
| 3239 |
else assert(0); |
| 3240 |
} |
| 3241 |
|
| 3242 |
/***************************************************/ |
| 3243 |
// https://issues.dlang.org/show_bug.cgi?id=6072 |
| 3244 |
|
| 3245 |
static assert({ |
| 3246 |
if (int x = 5) {} |
| 3247 |
return true; |
| 3248 |
}()); |
| 3249 |
|
| 3250 |
/***************************************************/ |
| 3251 |
// https://issues.dlang.org/show_bug.cgi?id=5959 |
| 3252 |
|
| 3253 |
int n; |
| 3254 |
|
| 3255 |
void test143() |
| 3256 |
{ |
| 3257 |
ref int f(){ return n; } // NG |
| 3258 |
f() = 1; |
| 3259 |
assert(n == 1); |
| 3260 |
|
| 3261 |
nothrow ref int f1(){ return n; } // OK |
| 3262 |
f1() = 2; |
| 3263 |
assert(n == 2); |
| 3264 |
|
| 3265 |
auto ref int f2(){ return n; } // OK |
| 3266 |
f2() = 3; |
| 3267 |
assert(n == 3); |
| 3268 |
} |
| 3269 |
|
| 3270 |
/***************************************************/ |
| 3271 |
// https://issues.dlang.org/show_bug.cgi?id=6119 |
| 3272 |
|
| 3273 |
void startsWith(alias pred) () if (is(typeof(pred('c', 'd')) : bool)) |
| 3274 |
{ |
| 3275 |
} |
| 3276 |
|
| 3277 |
void startsWith(alias pred) () if (is(typeof(pred('c', "abc")) : bool)) |
| 3278 |
{ |
| 3279 |
} |
| 3280 |
|
| 3281 |
void test144() |
| 3282 |
{ |
| 3283 |
startsWith!((a, b) { return a == b; })(); |
| 3284 |
} |
| 3285 |
|
| 3286 |
/***************************************************/ |
| 3287 |
|
| 3288 |
void test145() |
| 3289 |
{ |
| 3290 |
import core.stdc.stdio; |
| 3291 |
printf("hello world 145\n"); |
| 3292 |
} |
| 3293 |
|
| 3294 |
void test146() |
| 3295 |
{ |
| 3296 |
test1(); |
| 3297 |
static import core.stdc.stdio; |
| 3298 |
core.stdc.stdio.printf("hello world 146\n"); |
| 3299 |
} |
| 3300 |
|
| 3301 |
/***************************************************/ |
| 3302 |
// https://issues.dlang.org/show_bug.cgi?id=5856 |
| 3303 |
|
| 3304 |
struct X147 |
| 3305 |
{ |
| 3306 |
void f() { printf("X.f mutable\n"); } |
| 3307 |
void f() const { printf("X.f const\n"); } |
| 3308 |
|
| 3309 |
void g()() { printf("X.g mutable\n"); } |
| 3310 |
void g()() const { printf("X.g const\n"); } |
| 3311 |
|
| 3312 |
void opOpAssign(string op)(int n) { printf("X+= mutable\n"); } |
| 3313 |
void opOpAssign(string op)(int n) const { printf("X+= const\n"); } |
| 3314 |
} |
| 3315 |
|
| 3316 |
void test147() |
| 3317 |
{ |
| 3318 |
X147 xm; |
| 3319 |
xm.f(); // prints "X.f mutable" |
| 3320 |
xm.g(); // prints "X.g mutable" |
| 3321 |
xm += 10; // should print "X+= mutable" (1) |
| 3322 |
|
| 3323 |
const(X147) xc; |
| 3324 |
xc.f(); // prints "X.f const" |
| 3325 |
xc.g(); // prints "X.g const" |
| 3326 |
xc += 10; // should print "X+= const" (2) |
| 3327 |
} |
| 3328 |
|
| 3329 |
|
| 3330 |
/***************************************************/ |
| 3331 |
|
| 3332 |
void test3559() |
| 3333 |
{ |
| 3334 |
static class A |
| 3335 |
{ |
| 3336 |
int foo(int a) { return 0; } |
| 3337 |
int foo(float a) { return 1; } |
| 3338 |
|
| 3339 |
int bar(float a) { return 1; } |
| 3340 |
int bar(int a) { return 0; } |
| 3341 |
} |
| 3342 |
|
| 3343 |
static class B : A |
| 3344 |
{ |
| 3345 |
override int foo(float a) { return 2; } |
| 3346 |
alias A.foo foo; |
| 3347 |
|
| 3348 |
alias A.bar bar; |
| 3349 |
override int bar(float a) { return 2; } |
| 3350 |
} |
| 3351 |
|
| 3352 |
{ |
| 3353 |
auto x = new A; |
| 3354 |
auto f1 = cast(int delegate(int))&x.foo; |
| 3355 |
auto f2 = cast(int delegate(float))&x.foo; |
| 3356 |
int delegate(int) f3 = &x.foo; |
| 3357 |
int delegate(float) f4 = &x.foo; |
| 3358 |
|
| 3359 |
assert(f1(0) == 0); |
| 3360 |
assert(f2(0) == 1); |
| 3361 |
assert(f3(0) == 0); |
| 3362 |
assert(f4(0) == 1); |
| 3363 |
} |
| 3364 |
|
| 3365 |
{ |
| 3366 |
auto x = new B; |
| 3367 |
auto f1 = cast(int delegate(int))&x.foo; |
| 3368 |
auto f2 = cast(int delegate(float))&x.foo; |
| 3369 |
int delegate(int) f3 = &x.foo; |
| 3370 |
int delegate(float) f4 = &x.foo; |
| 3371 |
|
| 3372 |
assert(f1(0) == 0); |
| 3373 |
assert(f2(0) == 2); |
| 3374 |
assert(f3(0) == 0); |
| 3375 |
assert(f4(0) == 2); |
| 3376 |
} |
| 3377 |
|
| 3378 |
{ |
| 3379 |
auto x = new A; |
| 3380 |
auto f1 = cast(int delegate(int))&x.bar; |
| 3381 |
auto f2 = cast(int delegate(float))&x.bar; |
| 3382 |
int delegate(int) f3 = &x.bar; |
| 3383 |
int delegate(float) f4 = &x.bar; |
| 3384 |
|
| 3385 |
assert(f1(0) == 0); |
| 3386 |
assert(f2(0) == 1); |
| 3387 |
assert(f3(0) == 0); |
| 3388 |
assert(f4(0) == 1); |
| 3389 |
} |
| 3390 |
|
| 3391 |
{ |
| 3392 |
auto x = new B; |
| 3393 |
auto f1 = cast(int delegate(int))&x.bar; |
| 3394 |
auto f2 = cast(int delegate(float))&x.bar; |
| 3395 |
int delegate(int) f3 = &x.bar; |
| 3396 |
int delegate(float) f4 = &x.bar; |
| 3397 |
|
| 3398 |
assert(f1(0) == 0); |
| 3399 |
assert(f2(0) == 2); |
| 3400 |
assert(f3(0) == 0); |
| 3401 |
assert(f4(0) == 2); |
| 3402 |
} |
| 3403 |
} |
| 3404 |
|
| 3405 |
/***************************************************/ |
| 3406 |
|
| 3407 |
extern(C++) |
| 3408 |
class C13182 |
| 3409 |
{ |
| 3410 |
} |
| 3411 |
|
| 3412 |
void test13182() |
| 3413 |
{ |
| 3414 |
scope C13182 c = new C13182(); |
| 3415 |
} |
| 3416 |
|
| 3417 |
/***************************************************/ |
| 3418 |
// https://issues.dlang.org/show_bug.cgi?id=5897 |
| 3419 |
|
| 3420 |
struct A148{ int n; } |
| 3421 |
struct B148{ |
| 3422 |
int n, m; |
| 3423 |
this(A148 a){ n = a.n, m = a.n*2; } |
| 3424 |
} |
| 3425 |
|
| 3426 |
struct C148{ |
| 3427 |
int n, m; |
| 3428 |
static C148 opCall(A148 a) |
| 3429 |
{ |
| 3430 |
C148 b; |
| 3431 |
b.n = a.n, b.m = a.n*2; |
| 3432 |
return b; |
| 3433 |
} |
| 3434 |
} |
| 3435 |
|
| 3436 |
void test148() |
| 3437 |
{ |
| 3438 |
auto a = A148(10); |
| 3439 |
auto b = cast(B148)a; |
| 3440 |
assert(b.n == 10 && b.m == 20); |
| 3441 |
auto c = cast(C148)a; |
| 3442 |
assert(c.n == 10 && c.m == 20); |
| 3443 |
} |
| 3444 |
|
| 3445 |
/***************************************************/ |
| 3446 |
// https://issues.dlang.org/show_bug.cgi?id=4969 |
| 3447 |
|
| 3448 |
class MyException : Exception |
| 3449 |
{ |
| 3450 |
this() |
| 3451 |
{ |
| 3452 |
super("An exception!"); |
| 3453 |
} |
| 3454 |
} |
| 3455 |
|
| 3456 |
void throwAway() |
| 3457 |
{ |
| 3458 |
throw new MyException; |
| 3459 |
} |
| 3460 |
|
| 3461 |
void cantthrow() nothrow |
| 3462 |
{ |
| 3463 |
try |
| 3464 |
throwAway(); |
| 3465 |
catch(MyException me) |
| 3466 |
assert(0); |
| 3467 |
catch(Exception e) |
| 3468 |
assert(0); |
| 3469 |
} |
| 3470 |
|
| 3471 |
/***************************************************/ |
| 3472 |
// https://issues.dlang.org/show_bug.cgi?id=2356 |
| 3473 |
|
| 3474 |
void test2356() |
| 3475 |
{ |
| 3476 |
int[3] x = [1,2,3]; |
| 3477 |
printf("x[] = [%d %d %d]\n", x[0], x[1], x[2]); |
| 3478 |
assert(x[0] == 1 && x[1] == 2 && x[2] == 3); |
| 3479 |
|
| 3480 |
struct S |
| 3481 |
{ |
| 3482 |
static int pblit; |
| 3483 |
int n; |
| 3484 |
this(this) { ++pblit; printf("postblit: %d\n", n); } |
| 3485 |
} |
| 3486 |
S s2 = S(2); |
| 3487 |
S[3] s = [S(1), s2, S(3)]; |
| 3488 |
assert(s[0].n == 1 && s[1].n == 2 && s[2].n == 3); |
| 3489 |
printf("s[].n = [%d %d %d]\n", s[0].n, s[1].n, s[2].n); |
| 3490 |
assert(S.pblit == 1); |
| 3491 |
|
| 3492 |
ubyte[1024] v; |
| 3493 |
v = typeof(v).init; |
| 3494 |
printf("v[] = [%d %d %d, ..., %d]\n", v[0], v[1], v[2], v[$-1]); |
| 3495 |
foreach (ref a; v) assert(a == 0); |
| 3496 |
|
| 3497 |
int n = 5; |
| 3498 |
int[3] y = [n, n, n]; |
| 3499 |
printf("y[] = [%d %d %d]\n", y[0], y[1], y[2]); |
| 3500 |
assert(y[0] == 5 && y[1] == 5 && y[2] == 5); |
| 3501 |
|
| 3502 |
S[3] z = [s2, s2, s2]; |
| 3503 |
assert(z[0].n == 2 && z[1].n == 2 && z[2].n == 2); |
| 3504 |
printf("z[].n = [%d %d %d]\n", z[0].n, z[1].n, z[2].n); |
| 3505 |
assert(S.pblit == 1 + 3); |
| 3506 |
|
| 3507 |
int[0] nsa0 = []; |
| 3508 |
void[0] vsa0 = []; |
| 3509 |
|
| 3510 |
void foo(T)(T){} |
| 3511 |
foo(vsa0); |
| 3512 |
|
| 3513 |
ref int[0] bar() { static int[1] sa; return *cast(int[0]*)&sa; } |
| 3514 |
bar() = []; |
| 3515 |
} |
| 3516 |
|
| 3517 |
/***************************************************/ |
| 3518 |
// https://issues.dlang.org/show_bug.cgi?id=13652 |
| 3519 |
|
| 3520 |
void test13652() |
| 3521 |
{ |
| 3522 |
// reduced case |
| 3523 |
uint[9][5] arr = |
| 3524 |
[[0, 0, 0, 0, 1, 5, 8, 0, 7], |
| 3525 |
[0, 3, 8, 0, 2, 0, 0, 6, 0], |
| 3526 |
[0, 0, 7, 0, 6, 8, 9, 4, 0], |
| 3527 |
[0, 0, 0, 0, 0, 1, 2, 9, 0], |
| 3528 |
[9, 7, 0, 0, 0, 0, 0, 8, 3]]; |
| 3529 |
assert(arr[0][0] == 0 && arr[0][1] == 0 && arr[0][2] == 0 && |
| 3530 |
arr[0][3] == 0 && arr[0][4] == 1 && arr[0][5] == 5 && |
| 3531 |
arr[0][6] == 8 && arr[0][7] == 0 && arr[0][8] == 7); |
| 3532 |
assert(arr[1][0] == 0 && arr[1][1] == 3 && arr[1][2] == 8 && |
| 3533 |
arr[1][3] == 0 && arr[1][4] == 2 && arr[1][5] == 0 && |
| 3534 |
arr[1][6] == 0 && arr[1][7] == 6 && arr[1][8] == 0); |
| 3535 |
assert(arr[2][0] == 0 && arr[2][1] == 0 && arr[2][2] == 7 && |
| 3536 |
arr[2][3] == 0 && arr[2][4] == 6 && arr[2][5] == 8 && |
| 3537 |
arr[2][6] == 9 && arr[2][7] == 4 && arr[2][8] == 0); |
| 3538 |
assert(arr[3][0] == 0 && arr[3][1] == 0 && arr[3][2] == 0 && |
| 3539 |
arr[3][3] == 0 && arr[3][4] == 0 && arr[3][5] == 1 && |
| 3540 |
arr[3][6] == 2 && arr[3][7] == 9 && arr[3][8] == 0); |
| 3541 |
assert(arr[4][0] == 9 && arr[4][1] == 7 && arr[4][2] == 0 && |
| 3542 |
arr[4][3] == 0 && arr[4][4] == 0 && arr[4][5] == 0 && |
| 3543 |
arr[4][6] == 0 && arr[4][7] == 8 && arr[4][8] == 3); |
| 3544 |
|
| 3545 |
// original case |
| 3546 |
uint[9][9] tbl = |
| 3547 |
[[0, 0, 0, 0, 1, 5, 8, 0, 7], |
| 3548 |
[0, 3, 8, 0, 2, 0, 0, 6, 0], |
| 3549 |
[0, 0, 7, 0, 6, 8, 9, 4, 0], |
| 3550 |
[0, 0, 0, 0, 0, 1, 2, 9, 0], |
| 3551 |
[9, 7, 0, 0, 0, 0, 0, 8, 3], |
| 3552 |
[0, 2, 1, 6, 0, 0, 0, 0, 0], |
| 3553 |
[0, 6, 9, 5, 4, 0, 3, 0, 0], |
| 3554 |
[0, 4, 0, 0, 8, 0, 6, 5, 0], |
| 3555 |
[2, 0, 5, 9, 3, 0, 0, 0, 0]]; |
| 3556 |
assert(tbl[0][0] == 0 && tbl[0][1] == 0 && tbl[0][2] == 0 && |
| 3557 |
tbl[0][3] == 0 && tbl[0][4] == 1 && tbl[0][5] == 5 && |
| 3558 |
tbl[0][6] == 8 && tbl[0][7] == 0 && tbl[0][8] == 7); |
| 3559 |
assert(tbl[1][0] == 0 && tbl[1][1] == 3 && tbl[1][2] == 8 && |
| 3560 |
tbl[1][3] == 0 && tbl[1][4] == 2 && tbl[1][5] == 0 && |
| 3561 |
tbl[1][6] == 0 && tbl[1][7] == 6 && tbl[1][8] == 0); |
| 3562 |
assert(tbl[2][0] == 0 && tbl[2][1] == 0 && tbl[2][2] == 7 && |
| 3563 |
tbl[2][3] == 0 && tbl[2][4] == 6 && tbl[2][5] == 8 && |
| 3564 |
tbl[2][6] == 9 && tbl[2][7] == 4 && tbl[2][8] == 0); |
| 3565 |
assert(tbl[3][0] == 0 && tbl[3][1] == 0 && tbl[3][2] == 0 && |
| 3566 |
tbl[3][3] == 0 && tbl[3][4] == 0 && tbl[3][5] == 1 && |
| 3567 |
tbl[3][6] == 2 && tbl[3][7] == 9 && tbl[3][8] == 0); |
| 3568 |
assert(tbl[4][0] == 9 && tbl[4][1] == 7 && tbl[4][2] == 0 && |
| 3569 |
tbl[4][3] == 0 && tbl[4][4] == 0 && tbl[4][5] == 0 && |
| 3570 |
tbl[4][6] == 0 && tbl[4][7] == 8 && tbl[4][8] == 3); |
| 3571 |
assert(tbl[5][0] == 0 && tbl[5][1] == 2 && tbl[5][2] == 1 && |
| 3572 |
tbl[5][3] == 6 && tbl[5][4] == 0 && tbl[5][5] == 0 && |
| 3573 |
tbl[5][6] == 0 && tbl[5][7] == 0 && tbl[5][8] == 0); |
| 3574 |
assert(tbl[6][0] == 0 && tbl[6][1] == 6 && tbl[6][2] == 9 && |
| 3575 |
tbl[6][3] == 5 && tbl[6][4] == 4 && tbl[6][5] == 0 && |
| 3576 |
tbl[6][6] == 3 && tbl[6][7] == 0 && tbl[6][8] == 0); |
| 3577 |
assert(tbl[7][0] == 0 && tbl[7][1] == 4 && tbl[7][2] == 0 && |
| 3578 |
tbl[7][3] == 0 && tbl[7][4] == 8 && tbl[7][5] == 0 && |
| 3579 |
tbl[7][6] == 6 && tbl[7][7] == 5 && tbl[7][8] == 0); |
| 3580 |
assert(tbl[8][0] == 2 && tbl[8][1] == 0 && tbl[8][2] == 5 && |
| 3581 |
tbl[8][3] == 9 && tbl[8][4] == 3 && tbl[8][5] == 0 && |
| 3582 |
tbl[8][6] == 0 && tbl[8][6] == 0 && tbl[8][8] == 0); |
| 3583 |
} |
| 3584 |
|
| 3585 |
/***************************************************/ |
| 3586 |
// https://issues.dlang.org/show_bug.cgi?id=11238 |
| 3587 |
|
| 3588 |
void test11238() |
| 3589 |
{ |
| 3590 |
int[2] m; |
| 3591 |
m[0] = 4,m[1] = 6; |
| 3592 |
//printf("%d,%d\n", m[0], m[1]); |
| 3593 |
assert(m[0] == 4 && m[1] == 6); |
| 3594 |
|
| 3595 |
m = [m[1], m[0]]; // swap |
| 3596 |
assert(m[0] == 6 && m[1] == 4); |
| 3597 |
//printf("%d,%d\n", m[0], m[1]); |
| 3598 |
|
| 3599 |
m = [m[1], m[0]]; // swap |
| 3600 |
//printf("%d,%d\n", m[0], m[1]); |
| 3601 |
assert(m[0] == 4 && m[1] == 6); |
| 3602 |
} |
| 3603 |
|
| 3604 |
/***************************************************/ |
| 3605 |
|
| 3606 |
void test11805() |
| 3607 |
{ |
| 3608 |
int i; |
| 3609 |
|
| 3610 |
i = 47; |
| 3611 |
i = 1 && i; |
| 3612 |
assert(i == 1); |
| 3613 |
i = 0 || i; |
| 3614 |
assert(i == 1); |
| 3615 |
} |
| 3616 |
|
| 3617 |
/***************************************************/ |
| 3618 |
|
| 3619 |
class A2540 |
| 3620 |
{ |
| 3621 |
int a; |
| 3622 |
int foo() { return 0; } |
| 3623 |
alias int X; |
| 3624 |
} |
| 3625 |
|
| 3626 |
class B2540 : A2540 |
| 3627 |
{ |
| 3628 |
int b; |
| 3629 |
override typeof(super).X foo() { return 1; } |
| 3630 |
|
| 3631 |
alias typeof(this) athis; |
| 3632 |
alias typeof(this).b thisb; |
| 3633 |
alias typeof(super).a supera; |
| 3634 |
alias typeof(super).foo superfoo; |
| 3635 |
alias typeof(this).foo thisfoo; |
| 3636 |
} |
| 3637 |
|
| 3638 |
struct X2540 |
| 3639 |
{ |
| 3640 |
alias typeof(this) athis; |
| 3641 |
} |
| 3642 |
|
| 3643 |
void test2540() |
| 3644 |
{ |
| 3645 |
auto x = X2540.athis.init; |
| 3646 |
static assert(is(typeof(x) == X2540)); |
| 3647 |
|
| 3648 |
B2540 b = new B2540(); |
| 3649 |
|
| 3650 |
assert(&b.a == &b.supera); |
| 3651 |
assert(&b.b == &b.thisb); |
| 3652 |
assert(b.thisfoo() == 1); |
| 3653 |
} |
| 3654 |
|
| 3655 |
/***************************************************/ |
| 3656 |
|
| 3657 |
class B14348 |
| 3658 |
{ |
| 3659 |
int foo() { return 0; } |
| 3660 |
} |
| 3661 |
|
| 3662 |
class C14348 : B14348 |
| 3663 |
{ |
| 3664 |
override int foo() { return 1; } |
| 3665 |
|
| 3666 |
alias superfoo = typeof(super).foo; |
| 3667 |
alias thisfoo = typeof(this).foo; |
| 3668 |
} |
| 3669 |
|
| 3670 |
B14348 test14348() |
| 3671 |
{ |
| 3672 |
alias foo = typeof(return).foo; // currently doesn't work. |
| 3673 |
assert(&B14348.foo is &C14348.superfoo); |
| 3674 |
assert(&C14348.foo is &C14348.thisfoo); |
| 3675 |
return null; |
| 3676 |
} |
| 3677 |
|
| 3678 |
/***************************************************/ |
| 3679 |
// https://issues.dlang.org/show_bug.cgi?id=7295 |
| 3680 |
|
| 3681 |
struct S7295 |
| 3682 |
{ |
| 3683 |
int member; |
| 3684 |
@property ref int refCountedPayload() return { return member; } |
| 3685 |
alias refCountedPayload this; |
| 3686 |
} |
| 3687 |
|
| 3688 |
void foo7295(S)(immutable S t, int qq) pure { } |
| 3689 |
void foo7295(S)(S s) pure { } |
| 3690 |
|
| 3691 |
void bar7295() pure |
| 3692 |
{ |
| 3693 |
S7295 b; |
| 3694 |
foo7295(b); |
| 3695 |
} |
| 3696 |
|
| 3697 |
/***************************************************/ |
| 3698 |
// https://issues.dlang.org/show_bug.cgi?id=5659 |
| 3699 |
|
| 3700 |
void test149() |
| 3701 |
{ |
| 3702 |
char a; |
| 3703 |
immutable(char) b; |
| 3704 |
|
| 3705 |
static assert(is(typeof(true ? a : b) == const(char))); |
| 3706 |
static assert(is(typeof([a, b][0]) == const(char))); |
| 3707 |
} |
| 3708 |
|
| 3709 |
|
| 3710 |
/***************************************************/ |
| 3711 |
// https://issues.dlang.org/show_bug.cgi?id=1373 |
| 3712 |
|
| 3713 |
void func1373a(){} |
| 3714 |
|
| 3715 |
static assert(typeof(func1373a).stringof == "void()"); |
| 3716 |
static assert(typeof(func1373a).mangleof == "FZv"); |
| 3717 |
static assert(!__traits(compiles, typeof(func1373a).alignof)); |
| 3718 |
static assert(!__traits(compiles, typeof(func1373a).init)); |
| 3719 |
static assert(!__traits(compiles, typeof(func1373a).offsetof)); |
| 3720 |
|
| 3721 |
void func1373b(int n){} |
| 3722 |
|
| 3723 |
static assert(typeof(func1373b).stringof == "void(int n)"); |
| 3724 |
static assert(typeof(func1373b).mangleof == "FiZv"); |
| 3725 |
static assert(!__traits(compiles, typeof(func1373b).alignof)); |
| 3726 |
static assert(!__traits(compiles, typeof(func1373b).init)); |
| 3727 |
static assert(!__traits(compiles, typeof(func1373b).offsetof)); |
| 3728 |
|
| 3729 |
/***************************************************/ |
| 3730 |
|
| 3731 |
void bar150(T)(T n) { } |
| 3732 |
|
| 3733 |
@safe void test150() |
| 3734 |
{ |
| 3735 |
bar150(1); |
| 3736 |
} |
| 3737 |
|
| 3738 |
/***************************************************/ |
| 3739 |
|
| 3740 |
void test5785() |
| 3741 |
{ |
| 3742 |
static struct x { static int y; } |
| 3743 |
assert(x.y !is 1); |
| 3744 |
assert(x.y !in [1:0]); |
| 3745 |
} |
| 3746 |
|
| 3747 |
/***************************************************/ |
| 3748 |
|
| 3749 |
void bar151(T)(T n) { } |
| 3750 |
|
| 3751 |
nothrow void test151() |
| 3752 |
{ |
| 3753 |
bar151(1); |
| 3754 |
} |
| 3755 |
|
| 3756 |
/***************************************************/ |
| 3757 |
|
| 3758 |
@property int coo() { return 1; } |
| 3759 |
@property auto doo(int i) { return i; } |
| 3760 |
|
| 3761 |
@property int eoo() { return 1; } |
| 3762 |
@property auto ref hoo(int i) { return i; } |
| 3763 |
|
| 3764 |
// https://issues.dlang.org/show_bug.cgi?id=3359 |
| 3765 |
|
| 3766 |
int goo(int i) pure { return i; } |
| 3767 |
auto ioo(int i) pure { return i; } |
| 3768 |
auto ref boo(int i) pure nothrow { return i; } |
| 3769 |
|
| 3770 |
class A152 { |
| 3771 |
auto hoo(int i) pure { return i; } |
| 3772 |
const boo(int i) nothrow { return i; } |
| 3773 |
auto coo(int i) const { return i; } |
| 3774 |
auto doo(int i) immutable { return i; } |
| 3775 |
auto eoo(int i) shared { return i; } |
| 3776 |
} |
| 3777 |
|
| 3778 |
// https://issues.dlang.org/show_bug.cgi?id=4706 |
| 3779 |
|
| 3780 |
struct Foo152(T) { |
| 3781 |
@property auto ref front() { |
| 3782 |
return T.init; |
| 3783 |
} |
| 3784 |
|
| 3785 |
@property void front(T num) {} |
| 3786 |
} |
| 3787 |
|
| 3788 |
void test152() { |
| 3789 |
Foo152!int foo; |
| 3790 |
auto a = foo.front; |
| 3791 |
foo.front = 2; |
| 3792 |
} |
| 3793 |
|
| 3794 |
/***************************************************/ |
| 3795 |
// https://issues.dlang.org/show_bug.cgi?id=6733 |
| 3796 |
|
| 3797 |
void bug6733(int a, int b) pure nothrow { } |
| 3798 |
void test6733() { |
| 3799 |
int z = 1; |
| 3800 |
bug6733(z++, z++); |
| 3801 |
assert(z==3); |
| 3802 |
} |
| 3803 |
|
| 3804 |
/***************************************************/ |
| 3805 |
// https://issues.dlang.org/show_bug.cgi?id=3799 |
| 3806 |
|
| 3807 |
void test153() |
| 3808 |
{ |
| 3809 |
void bar() |
| 3810 |
{ |
| 3811 |
} |
| 3812 |
|
| 3813 |
static assert(!__traits(isStaticFunction, bar)); |
| 3814 |
} |
| 3815 |
|
| 3816 |
/***************************************************/ |
| 3817 |
// https://issues.dlang.org/show_bug.cgi?id=3632 |
| 3818 |
|
| 3819 |
void test154() |
| 3820 |
{ |
| 3821 |
float f; |
| 3822 |
assert(f is float.init); |
| 3823 |
double d; |
| 3824 |
assert(d is double.init); |
| 3825 |
real r; |
| 3826 |
assert(r is real.init); |
| 3827 |
|
| 3828 |
assert(float.nan is float.nan); |
| 3829 |
assert(double.nan is double.nan); |
| 3830 |
assert(real.nan is real.nan); |
| 3831 |
} |
| 3832 |
|
| 3833 |
/***************************************************/ |
| 3834 |
|
| 3835 |
__gshared int global3632 = 1; |
| 3836 |
|
| 3837 |
void test3632() |
| 3838 |
{ |
| 3839 |
int test(T)() |
| 3840 |
{ |
| 3841 |
static struct W |
| 3842 |
{ |
| 3843 |
T f; |
| 3844 |
this(T g) { if (__ctfe || global3632) f = g; } |
| 3845 |
} |
| 3846 |
auto nan = W(T.nan); |
| 3847 |
auto nan2 = W(T.nan); |
| 3848 |
auto init = W(T.init); |
| 3849 |
auto init2 = W(T.init); |
| 3850 |
auto zero = W(cast(T)0); |
| 3851 |
auto zero2 = W(cast(T)0); |
| 3852 |
auto nzero2 = W(-cast(T)0); |
| 3853 |
|
| 3854 |
// Struct equality |
| 3855 |
assert(!(nan == nan2)); |
| 3856 |
assert(!(nan == init2)); |
| 3857 |
assert(!(init == init2)); |
| 3858 |
assert( (zero == zero2)); |
| 3859 |
assert( (zero == nzero2)); |
| 3860 |
|
| 3861 |
// Float equality |
| 3862 |
assert(!(nan.f == nan2.f)); |
| 3863 |
assert(!(nan.f == init2.f)); |
| 3864 |
assert(!(init.f == init2.f)); |
| 3865 |
assert( (zero.f == zero2.f)); |
| 3866 |
assert( (zero.f == nzero2.f)); |
| 3867 |
|
| 3868 |
// Struct identity |
| 3869 |
assert( (nan is nan2)); |
| 3870 |
assert( (nan is init2)); |
| 3871 |
assert( (init is init2)); |
| 3872 |
assert( (zero is zero2)); |
| 3873 |
assert(!(zero is nzero2)); |
| 3874 |
|
| 3875 |
// Float identity |
| 3876 |
assert( (nan.f is nan2.f)); |
| 3877 |
assert( (nan.f is init2.f)); |
| 3878 |
assert( (init.f is init2.f)); |
| 3879 |
assert( (zero.f is zero2.f)); |
| 3880 |
assert(!(zero.f is nzero2.f)); |
| 3881 |
|
| 3882 |
// Struct !identity |
| 3883 |
assert(!(nan !is nan2)); |
| 3884 |
assert( (nan is init2)); |
| 3885 |
assert(!(init !is init2)); |
| 3886 |
assert(!(zero !is zero2)); |
| 3887 |
assert( (zero !is nzero2)); |
| 3888 |
|
| 3889 |
// float !identity |
| 3890 |
assert(!(nan.f !is nan2.f)); |
| 3891 |
assert( (nan.f is init2.f)); |
| 3892 |
assert(!(init.f !is init2.f)); |
| 3893 |
assert(!(zero.f !is zero2.f)); |
| 3894 |
assert( (zero.f !is nzero2.f)); |
| 3895 |
|
| 3896 |
// .init identity |
| 3897 |
assert(W.init is W.init); |
| 3898 |
|
| 3899 |
return 1; |
| 3900 |
} |
| 3901 |
|
| 3902 |
auto rtF = test!float(); |
| 3903 |
enum ctF = test!float(); |
| 3904 |
auto rtD = test!double(); |
| 3905 |
enum ctD = test!double(); |
| 3906 |
auto rtR = test!real(); |
| 3907 |
enum ctR = test!real(); |
| 3908 |
|
| 3909 |
assert(float.nan !is -float.nan); |
| 3910 |
assert(double.nan !is -double.nan); |
| 3911 |
assert(real.nan !is -real.nan); |
| 3912 |
} |
| 3913 |
|
| 3914 |
/***************************************************/ |
| 3915 |
|
| 3916 |
void test6545() |
| 3917 |
{ |
| 3918 |
static int[] func() |
| 3919 |
{ |
| 3920 |
auto a = [1, 2, 3]; |
| 3921 |
auto b = [2, 3, 4]; |
| 3922 |
auto c = [3, 4, 5]; |
| 3923 |
|
| 3924 |
a[] = b[] + c[]; |
| 3925 |
|
| 3926 |
return a; |
| 3927 |
} |
| 3928 |
|
| 3929 |
auto a = func(); |
| 3930 |
enum b = func(); |
| 3931 |
assert(a == b); |
| 3932 |
} |
| 3933 |
|
| 3934 |
/***************************************************/ |
| 3935 |
// https://issues.dlang.org/show_bug.cgi?id=3147 |
| 3936 |
|
| 3937 |
|
| 3938 |
void test155() |
| 3939 |
{ |
| 3940 |
byte b = 1; |
| 3941 |
short s; |
| 3942 |
int i; |
| 3943 |
long l; |
| 3944 |
|
| 3945 |
s = b + b; |
| 3946 |
b = s % b; |
| 3947 |
s = s >> b; |
| 3948 |
b = 1; |
| 3949 |
b = i % b; |
| 3950 |
b = b >> i; |
| 3951 |
} |
| 3952 |
|
| 3953 |
/***************************************************/ |
| 3954 |
// https://issues.dlang.org/show_bug.cgi?id=2486 |
| 3955 |
|
| 3956 |
void test2486() |
| 3957 |
{ |
| 3958 |
void foo(ref int[] arr) {} |
| 3959 |
|
| 3960 |
int[] arr = [1,2,3]; |
| 3961 |
foo(arr); //OK |
| 3962 |
static assert(__traits(compiles, foo(arr[1..2]))); |
| 3963 |
|
| 3964 |
struct S |
| 3965 |
{ |
| 3966 |
int[] a; |
| 3967 |
auto ref opSlice(){ return a[]; } // line 4 |
| 3968 |
} |
| 3969 |
S s; |
| 3970 |
s[]; |
| 3971 |
// opSlice should return rvalue |
| 3972 |
static assert(is(typeof(&S.opSlice) == int[] function() pure nothrow @nogc @safe)); |
| 3973 |
static assert(__traits(compiles, foo(s[]))); |
| 3974 |
} |
| 3975 |
|
| 3976 |
/***************************************************/ |
| 3977 |
|
| 3978 |
extern(C++) class C15080 |
| 3979 |
{ |
| 3980 |
uint x = 1; |
| 3981 |
uint y = 2; |
| 3982 |
} |
| 3983 |
|
| 3984 |
__gshared c15080 = new C15080(); |
| 3985 |
|
| 3986 |
void test15080() |
| 3987 |
{ |
| 3988 |
assert(c15080.x == 1); |
| 3989 |
assert(c15080.y == 2); |
| 3990 |
} |
| 3991 |
|
| 3992 |
/***************************************************/ |
| 3993 |
// https://issues.dlang.org/show_bug.cgi?id=2521 |
| 3994 |
|
| 3995 |
immutable int val = 23; |
| 3996 |
const int val2 = 23; |
| 3997 |
|
| 3998 |
ref immutable(int) func2521_() { |
| 3999 |
return val; |
| 4000 |
} |
| 4001 |
ref immutable(int) func2521_2() { |
| 4002 |
return *&val; |
| 4003 |
} |
| 4004 |
ref immutable(int) func2521_3() { |
| 4005 |
return func2521_; |
| 4006 |
} |
| 4007 |
ref const(int) func2521_4() { |
| 4008 |
return val2; |
| 4009 |
} |
| 4010 |
ref const(int) func2521_5() { |
| 4011 |
return val; |
| 4012 |
} |
| 4013 |
auto ref func2521_6() { |
| 4014 |
return val; |
| 4015 |
} |
| 4016 |
ref func2521_7() { |
| 4017 |
return val; |
| 4018 |
} |
| 4019 |
|
| 4020 |
/***************************************************/ |
| 4021 |
|
| 4022 |
void test5554() |
| 4023 |
{ |
| 4024 |
class MA { } |
| 4025 |
class MB : MA { } |
| 4026 |
class MC : MB { } |
| 4027 |
|
| 4028 |
class A { abstract MA foo(); } |
| 4029 |
interface I { MB foo(); } |
| 4030 |
class B : A |
| 4031 |
{ |
| 4032 |
override MC foo() { return null; } |
| 4033 |
} |
| 4034 |
class C : B, I |
| 4035 |
{ |
| 4036 |
override MC foo() { return null; } |
| 4037 |
} |
| 4038 |
} |
| 4039 |
|
| 4040 |
/***************************************************/ |
| 4041 |
// https://issues.dlang.org/show_bug.cgi?id=5962 |
| 4042 |
|
| 4043 |
struct S156 |
| 4044 |
{ |
| 4045 |
auto g()(){ return 1; } |
| 4046 |
const auto g()(){ return 2; } |
| 4047 |
} |
| 4048 |
|
| 4049 |
void test156() |
| 4050 |
{ |
| 4051 |
auto ms = S156(); |
| 4052 |
assert(ms.g() == 1); |
| 4053 |
auto cs = const(S156)(); |
| 4054 |
assert(cs.g() == 2); |
| 4055 |
} |
| 4056 |
|
| 4057 |
/***************************************************/ |
| 4058 |
|
| 4059 |
void test10724() |
| 4060 |
{ |
| 4061 |
const(char)* s = "abc"[0..$-1]; |
| 4062 |
assert(s[2] == '\0'); |
| 4063 |
} |
| 4064 |
|
| 4065 |
/***************************************************/ |
| 4066 |
|
| 4067 |
void test6708(const ref int y) |
| 4068 |
{ |
| 4069 |
immutable int x; |
| 4070 |
test6708(x); |
| 4071 |
} |
| 4072 |
|
| 4073 |
/***************************************************/ |
| 4074 |
// https://issues.dlang.org/show_bug.cgi?id=4258 |
| 4075 |
|
| 4076 |
struct Vec4258 { |
| 4077 |
Vec4258 opOpAssign(string Op)(auto ref Vec4258 other) if (Op == "+") { |
| 4078 |
return this; |
| 4079 |
} |
| 4080 |
Vec4258 opBinary(string Op:"+")(Vec4258 other) { |
| 4081 |
Vec4258 result; |
| 4082 |
return result += other; |
| 4083 |
} |
| 4084 |
} |
| 4085 |
void test4258() { |
| 4086 |
Vec4258 v; |
| 4087 |
v += Vec4258() + Vec4258(); // line 12 |
| 4088 |
} |
| 4089 |
|
| 4090 |
// regression fix test |
| 4091 |
|
| 4092 |
struct Foo4258 { |
| 4093 |
// binary ++/-- |
| 4094 |
int opUnary(string op)() if (false) { return 0; } |
| 4095 |
|
| 4096 |
// binary 1st |
| 4097 |
int opBinary(string op, R)(R rhs) if (false) { return 0; } |
| 4098 |
int opBinaryRight(string op, R)(R rhs) if (false) { return 0; } |
| 4099 |
|
| 4100 |
// compare |
| 4101 |
int opCmp(R)(const(R) rhs) const if (false) { return 0; } |
| 4102 |
|
| 4103 |
// binary-op assign |
| 4104 |
int opOpAssign(string op, R)(R rhs) if (false) { return 0; } |
| 4105 |
} |
| 4106 |
struct Bar4258 { |
| 4107 |
// binary commutive 1 |
| 4108 |
int opBinary(string op, R)(R rhs) if (false) { return 0; } |
| 4109 |
|
| 4110 |
// binary-op assign |
| 4111 |
int opOpAssign(string op, R)(R rhs) if (false) { return 0; } |
| 4112 |
} |
| 4113 |
struct Baz4258 { |
| 4114 |
// binary commutive 2 |
| 4115 |
int opBinaryRight(string op, R)(R rhs) if (false) { return 0; } |
| 4116 |
} |
| 4117 |
static assert(!is(typeof(++Foo4258.init))); |
| 4118 |
static assert(!is(typeof(Foo4258.init + 1))); |
| 4119 |
static assert(!is(typeof(1 + Foo4258.init))); |
| 4120 |
static assert(!is(typeof(Foo4258.init < Foo4258.init))); |
| 4121 |
static assert(!is(typeof(Foo4258.init += 1))); |
| 4122 |
static assert(!is(typeof(Bar4258.init + 1))); |
| 4123 |
static assert(!is(typeof(Bar4258.init += 1))); |
| 4124 |
static assert(!is(typeof(1 + Baz4258.init))); |
| 4125 |
|
| 4126 |
/***************************************************/ |
| 4127 |
// https://issues.dlang.org/show_bug.cgi?id=4539 |
| 4128 |
|
| 4129 |
void test4539() |
| 4130 |
{ |
| 4131 |
static assert(!__traits(compiles, "hello" = "red")); |
| 4132 |
|
| 4133 |
void foo1(ref string s){} |
| 4134 |
void foo2(ref const char[10] s){} |
| 4135 |
void foo3(ref char[5] s){} |
| 4136 |
|
| 4137 |
void foo4(ref const char[5] s) |
| 4138 |
{ |
| 4139 |
assert(s[0] == 'h'); |
| 4140 |
assert(s[4] == 'o'); |
| 4141 |
} |
| 4142 |
void foo5(ref const ubyte[5] s) |
| 4143 |
{ |
| 4144 |
assert(s[0] == 0xc3); |
| 4145 |
assert(s[4] == 0x61); |
| 4146 |
} |
| 4147 |
|
| 4148 |
static assert(__traits(compiles, foo1("hello"))); |
| 4149 |
static assert(!__traits(compiles, foo2("hello"))); |
| 4150 |
static assert(!__traits(compiles, foo3("hello"))); |
| 4151 |
|
| 4152 |
// same as test68, 69, 70 |
| 4153 |
foo4("hello"); |
| 4154 |
foo5(cast(ubyte[5])"\xc3\xfc\xd3\xd7\x61"); |
| 4155 |
|
| 4156 |
//import std.conv; |
| 4157 |
//static assert(!__traits(compiles, parse!int("10") == 10)); |
| 4158 |
} |
| 4159 |
|
| 4160 |
/***************************************************/ |
| 4161 |
// https://issues.dlang.org/show_bug.cgi?id=1471 |
| 4162 |
|
| 4163 |
void test1471() |
| 4164 |
{ |
| 4165 |
int n; |
| 4166 |
string bar = "BOOM"[n..$-1]; |
| 4167 |
assert(bar == "BOO"); |
| 4168 |
} |
| 4169 |
|
| 4170 |
/***************************************************/ |
| 4171 |
|
| 4172 |
deprecated @disable int bug6389; |
| 4173 |
static assert(!is(typeof(bug6389 = bug6389))); |
| 4174 |
|
| 4175 |
/***************************************************/ |
| 4176 |
|
| 4177 |
void test4963() |
| 4178 |
{ |
| 4179 |
struct Value { |
| 4180 |
byte a; |
| 4181 |
} |
| 4182 |
Value single() |
| 4183 |
{ |
| 4184 |
return Value(); |
| 4185 |
} |
| 4186 |
|
| 4187 |
Value[] list; |
| 4188 |
auto x = single() ~ list; |
| 4189 |
} |
| 4190 |
|
| 4191 |
/***************************************************/ |
| 4192 |
|
| 4193 |
pure int test4031() |
| 4194 |
{ |
| 4195 |
static const int x = 8; |
| 4196 |
return x; |
| 4197 |
} |
| 4198 |
|
| 4199 |
/***************************************************/ |
| 4200 |
// https://issues.dlang.org/show_bug.cgi?id=5437 |
| 4201 |
|
| 4202 |
template EnumMembers5437(E) |
| 4203 |
{ |
| 4204 |
template TypeTuple(T...){ alias T TypeTuple; } |
| 4205 |
|
| 4206 |
alias TypeTuple!("A", "B") EnumMembers5437; |
| 4207 |
} |
| 4208 |
template IntValue5437() |
| 4209 |
{ |
| 4210 |
int IntValue5437 = 10; |
| 4211 |
} |
| 4212 |
|
| 4213 |
void test5437() |
| 4214 |
{ |
| 4215 |
enum Foo { A, B } |
| 4216 |
alias EnumMembers5437!Foo members; // OK |
| 4217 |
enum n1 = members.length; // OK |
| 4218 |
enum n2 = (EnumMembers5437!Foo).length; // NG, type -> symbol |
| 4219 |
|
| 4220 |
enum s1 = IntValue5437!().sizeof; // OK |
| 4221 |
enum s2 = (IntValue5437!()).sizeof; // NG, type -> expression |
| 4222 |
} |
| 4223 |
|
| 4224 |
/***************************************************/ |
| 4225 |
// https://issues.dlang.org/show_bug.cgi?id=1962 |
| 4226 |
|
| 4227 |
|
| 4228 |
void test1962() |
| 4229 |
{ |
| 4230 |
class C { abstract void x(); } |
| 4231 |
assert(C.classinfo.create() is null); |
| 4232 |
} |
| 4233 |
|
| 4234 |
/***************************************************/ |
| 4235 |
// https://issues.dlang.org/show_bug.cgi?id=6228 |
| 4236 |
|
| 4237 |
void test6228() |
| 4238 |
{ |
| 4239 |
int val; |
| 4240 |
const(int)* ptr = &val; |
| 4241 |
const(int) temp; |
| 4242 |
auto x = (*ptr) ^^ temp; |
| 4243 |
} |
| 4244 |
|
| 4245 |
/***************************************************/ |
| 4246 |
|
| 4247 |
int test7544() |
| 4248 |
{ |
| 4249 |
try { throw new Exception(""); } |
| 4250 |
catch (Exception e) static assert(1); |
| 4251 |
return 1; |
| 4252 |
} |
| 4253 |
|
| 4254 |
static assert(test7544()); |
| 4255 |
|
| 4256 |
/***************************************************/ |
| 4257 |
|
| 4258 |
struct S6230 { |
| 4259 |
int p; |
| 4260 |
int q() const pure { |
| 4261 |
return p; |
| 4262 |
} |
| 4263 |
void r() pure { |
| 4264 |
p = 231; |
| 4265 |
} |
| 4266 |
} |
| 4267 |
class C6230 { |
| 4268 |
int p; |
| 4269 |
int q() const pure { |
| 4270 |
return p; |
| 4271 |
} |
| 4272 |
void r() pure { |
| 4273 |
p = 552; |
| 4274 |
} |
| 4275 |
} |
| 4276 |
int q6230(ref const S6230 s) pure { // <-- Currently OK |
| 4277 |
return s.p; |
| 4278 |
} |
| 4279 |
int q6230(ref const C6230 c) pure { // <-- Currently OK |
| 4280 |
return c.p; |
| 4281 |
} |
| 4282 |
void r6230(ref S6230 s) pure { |
| 4283 |
s.p = 244; |
| 4284 |
} |
| 4285 |
void r6230(ref C6230 c) pure { |
| 4286 |
c.p = 156; |
| 4287 |
} |
| 4288 |
bool test6230pure() pure { |
| 4289 |
auto s = S6230(4); |
| 4290 |
assert(s.p == 4); |
| 4291 |
assert(q6230(s) == 4); |
| 4292 |
assert(s.q == 4); |
| 4293 |
|
| 4294 |
auto c = new C6230; |
| 4295 |
c.p = 6; |
| 4296 |
assert(q6230(c) == 6); |
| 4297 |
assert(c.q == 6); |
| 4298 |
|
| 4299 |
r6230(s); |
| 4300 |
assert(s.p == 244); |
| 4301 |
s.r(); |
| 4302 |
assert(s.p == 231); |
| 4303 |
|
| 4304 |
r6230(c); |
| 4305 |
assert(c.p == 156); |
| 4306 |
c.r(); |
| 4307 |
assert(c.p == 552); |
| 4308 |
|
| 4309 |
return true; |
| 4310 |
} |
| 4311 |
void test6230() { |
| 4312 |
assert(test6230pure()); |
| 4313 |
} |
| 4314 |
|
| 4315 |
/***************************************************/ |
| 4316 |
|
| 4317 |
void test6264() |
| 4318 |
{ |
| 4319 |
struct S { auto opSlice() { return this; } } |
| 4320 |
int[] a; |
| 4321 |
S s; |
| 4322 |
static assert(!is(typeof(a[] = s[]))); |
| 4323 |
int*[] b; |
| 4324 |
static assert(is(typeof(b[] = [new immutable(int)]))); |
| 4325 |
char[] c = new char[](5); |
| 4326 |
c[] = "hello"; |
| 4327 |
} |
| 4328 |
|
| 4329 |
/***************************************************/ |
| 4330 |
// https://issues.dlang.org/show_bug.cgi?id=5046 |
| 4331 |
|
| 4332 |
void test5046() |
| 4333 |
{ |
| 4334 |
auto va = S5046!("", int)(); |
| 4335 |
auto vb = makeS5046!("", int)(); |
| 4336 |
} |
| 4337 |
|
| 4338 |
struct S5046(alias p, T) |
| 4339 |
{ |
| 4340 |
T s; |
| 4341 |
T fun() { return s; } // (10) |
| 4342 |
} |
| 4343 |
|
| 4344 |
S5046!(p, T) makeS5046(alias p, T)() |
| 4345 |
{ |
| 4346 |
return typeof(return)(); |
| 4347 |
} |
| 4348 |
|
| 4349 |
/***************************************************/ |
| 4350 |
// https://issues.dlang.org/show_bug.cgi?id=6335 |
| 4351 |
|
| 4352 |
struct S6335 |
| 4353 |
{ |
| 4354 |
const int value; |
| 4355 |
this()(int n){ value = n; } |
| 4356 |
} |
| 4357 |
void test6335() |
| 4358 |
{ |
| 4359 |
S6335 s = S6335(10); |
| 4360 |
} |
| 4361 |
|
| 4362 |
/***************************************************/ |
| 4363 |
|
| 4364 |
struct S6295(int N) { |
| 4365 |
int[N] x; |
| 4366 |
const nothrow pure @safe f() { return x.length; } |
| 4367 |
} |
| 4368 |
|
| 4369 |
void test6295() { |
| 4370 |
auto bar(T: S6295!(N), int N)(T x) { |
| 4371 |
return x.f(); |
| 4372 |
} |
| 4373 |
S6295!4 x; |
| 4374 |
assert(bar(x) == 4); |
| 4375 |
} |
| 4376 |
|
| 4377 |
/***************************************************/ |
| 4378 |
|
| 4379 |
template TT4536(T...) { alias T TT4536; } |
| 4380 |
|
| 4381 |
void test4536() |
| 4382 |
{ |
| 4383 |
auto x = TT4536!(int, long, [1, 2]).init; |
| 4384 |
assert(x[0] is int.init); |
| 4385 |
assert(x[1] is long.init); |
| 4386 |
assert(x[2] is [1, 2].init); |
| 4387 |
} |
| 4388 |
|
| 4389 |
/***************************************************/ |
| 4390 |
|
| 4391 |
struct S6284 { |
| 4392 |
int a; |
| 4393 |
} |
| 4394 |
class C6284 { |
| 4395 |
int a; |
| 4396 |
} |
| 4397 |
pure int bug6284a() { |
| 4398 |
S6284 s = {4}; |
| 4399 |
auto b = s.a; // ok |
| 4400 |
with (s) { |
| 4401 |
b += a; // should be ok. |
| 4402 |
} |
| 4403 |
return b; |
| 4404 |
} |
| 4405 |
pure int bug6284b() { |
| 4406 |
auto s = new S6284; |
| 4407 |
s.a = 4; |
| 4408 |
auto b = s.a; |
| 4409 |
with (*s) { |
| 4410 |
b += a; |
| 4411 |
} |
| 4412 |
return b; |
| 4413 |
} |
| 4414 |
pure int bug6284c() { |
| 4415 |
auto s = new C6284; |
| 4416 |
s.a = 4; |
| 4417 |
auto b = s.a; |
| 4418 |
with (s) { |
| 4419 |
b += a; |
| 4420 |
} |
| 4421 |
return b; |
| 4422 |
} |
| 4423 |
void test6284() { |
| 4424 |
assert(bug6284a() == 8); |
| 4425 |
assert(bug6284b() == 8); |
| 4426 |
assert(bug6284c() == 8); |
| 4427 |
} |
| 4428 |
|
| 4429 |
/***************************************************/ |
| 4430 |
|
| 4431 |
class C6293 { |
| 4432 |
C6293 token; |
| 4433 |
} |
| 4434 |
void f6293(in C6293[] a) pure { |
| 4435 |
auto x0 = a[0].token; |
| 4436 |
assert(x0 is a[0].token.token.token); |
| 4437 |
assert(x0 is (&x0).token); |
| 4438 |
auto p1 = &x0 + 1; |
| 4439 |
assert(x0 is (p1 - 1).token); |
| 4440 |
int c = 0; |
| 4441 |
assert(x0 is a[c].token); |
| 4442 |
} |
| 4443 |
void test6293() { |
| 4444 |
auto x = new C6293; |
| 4445 |
x.token = x; |
| 4446 |
f6293([x]); |
| 4447 |
} |
| 4448 |
|
| 4449 |
/***************************************************/ |
| 4450 |
// https://issues.dlang.org/show_bug.cgi?id=3733 |
| 4451 |
|
| 4452 |
class C3733 |
| 4453 |
{ |
| 4454 |
int foo() { return 1; } |
| 4455 |
int foo() shared { return 2; } |
| 4456 |
|
| 4457 |
int bar() { return foo(); } |
| 4458 |
} |
| 4459 |
void test3733() |
| 4460 |
{ |
| 4461 |
auto c = new C3733(); |
| 4462 |
assert(c.bar() == 1); |
| 4463 |
} |
| 4464 |
|
| 4465 |
/***************************************************/ |
| 4466 |
// https://issues.dlang.org/show_bug.cgi?id=4392 |
| 4467 |
|
| 4468 |
class C4392 |
| 4469 |
{ |
| 4470 |
int foo() const { return 1; } |
| 4471 |
int foo() { return 2; } |
| 4472 |
|
| 4473 |
int bar() const { return foo(); } |
| 4474 |
} |
| 4475 |
void test4392() |
| 4476 |
{ |
| 4477 |
auto c = new C4392(); |
| 4478 |
assert(c.bar() == 1); |
| 4479 |
} |
| 4480 |
|
| 4481 |
/***************************************************/ |
| 4482 |
// https://issues.dlang.org/show_bug.cgi?id=6220 |
| 4483 |
|
| 4484 |
void test6220() { |
| 4485 |
struct Foobar { real x; real y; real z;} |
| 4486 |
switch("x") { |
| 4487 |
foreach(i,member; __traits(allMembers, Foobar)) { |
| 4488 |
case member : break; |
| 4489 |
} |
| 4490 |
default : break; |
| 4491 |
} |
| 4492 |
} |
| 4493 |
|
| 4494 |
/***************************************************/ |
| 4495 |
// https://issues.dlang.org/show_bug.cgi?id=5799 |
| 4496 |
|
| 4497 |
void test5799() |
| 4498 |
{ |
| 4499 |
int a; |
| 4500 |
int *u = &(a ? a : (a ? a : a)); |
| 4501 |
assert(u == &a); |
| 4502 |
} |
| 4503 |
|
| 4504 |
/***************************************************/ |
| 4505 |
// https://issues.dlang.org/show_bug.cgi?id=6529 |
| 4506 |
|
| 4507 |
enum Foo6529 : char { A='a' } |
| 4508 |
ref const(Foo6529) func6529(const(Foo6529)[] arr){ return arr[0]; } |
| 4509 |
|
| 4510 |
/***************************************************/ |
| 4511 |
|
| 4512 |
void test783() |
| 4513 |
{ |
| 4514 |
const arr = [ 1,2,3 ]; |
| 4515 |
const i = 2; |
| 4516 |
auto jhk = new int[arr[i]]; // "need size of rightmost array, not type arr[i]" |
| 4517 |
} |
| 4518 |
|
| 4519 |
/***************************************************/ |
| 4520 |
|
| 4521 |
template X157(alias x) |
| 4522 |
{ |
| 4523 |
alias x X157; |
| 4524 |
} |
| 4525 |
|
| 4526 |
template Parent(alias foo) |
| 4527 |
{ |
| 4528 |
alias X157!(__traits(parent, foo)) Parent; |
| 4529 |
} |
| 4530 |
|
| 4531 |
template ParameterTypeTuple(alias foo) |
| 4532 |
{ |
| 4533 |
static if (is(typeof(foo) P == function)) |
| 4534 |
alias P ParameterTypeTuple; |
| 4535 |
else |
| 4536 |
static assert(0, "argument has no parameters"); |
| 4537 |
} |
| 4538 |
|
| 4539 |
template Mfp(alias foo) |
| 4540 |
{ |
| 4541 |
auto Mfp = function(Parent!foo self, ParameterTypeTuple!foo i) { return self.foo(i); }; |
| 4542 |
} |
| 4543 |
|
| 4544 |
class C157 { |
| 4545 |
int a = 3; |
| 4546 |
int foo(int i, int y) { return i + a + y; } |
| 4547 |
} |
| 4548 |
|
| 4549 |
void test157() |
| 4550 |
{ |
| 4551 |
auto c = new C157(); |
| 4552 |
auto mfp = Mfp!(C157.foo); |
| 4553 |
auto i = mfp(c, 1, 7); |
| 4554 |
assert(i == 11); |
| 4555 |
} |
| 4556 |
|
| 4557 |
/***************************************************/ |
| 4558 |
// https://issues.dlang.org/show_bug.cgi?id=6473 |
| 4559 |
|
| 4560 |
struct Eins6473 |
| 4561 |
{ |
| 4562 |
~this() {} |
| 4563 |
} |
| 4564 |
|
| 4565 |
struct Zwei6473 |
| 4566 |
{ |
| 4567 |
void build(Eins6473 devices = Eins6473()) |
| 4568 |
{ |
| 4569 |
} |
| 4570 |
} |
| 4571 |
|
| 4572 |
void build(Eins6473 devices = Eins6473()) |
| 4573 |
{} |
| 4574 |
|
| 4575 |
void test6473() |
| 4576 |
{ |
| 4577 |
void build(Eins6473 devices = Eins6473()) |
| 4578 |
{} |
| 4579 |
} |
| 4580 |
|
| 4581 |
/***************************************************/ |
| 4582 |
|
| 4583 |
uint rol11417(uint n)(in uint x) |
| 4584 |
{ |
| 4585 |
return x << n | x >> 32 - n; |
| 4586 |
} |
| 4587 |
|
| 4588 |
uint ror11417(uint n)(in uint x) |
| 4589 |
{ |
| 4590 |
return x >> n | x << 32 - n; |
| 4591 |
} |
| 4592 |
|
| 4593 |
void test11417() |
| 4594 |
{ |
| 4595 |
assert(rol11417!1(0x8000_0000) == 0x1); |
| 4596 |
assert(ror11417!1(0x1) == 0x8000_0000); |
| 4597 |
} |
| 4598 |
|
| 4599 |
/***************************************************/ |
| 4600 |
|
| 4601 |
void test6578() |
| 4602 |
{ |
| 4603 |
static struct Foo |
| 4604 |
{ |
| 4605 |
this(int x) pure {} |
| 4606 |
} |
| 4607 |
auto f1 = new const(Foo)(1); |
| 4608 |
auto f2 = new immutable(Foo)(1); |
| 4609 |
auto f3 = new shared(Foo)(1); |
| 4610 |
auto f4 = const(Foo)(1); |
| 4611 |
auto f5 = immutable(Foo)(1); |
| 4612 |
auto f6 = shared(Foo)(1); |
| 4613 |
static assert(is(typeof(f1) == const(Foo)*)); |
| 4614 |
static assert(is(typeof(f2) == immutable(Foo)*)); |
| 4615 |
static assert(is(typeof(f3) == shared(Foo)*)); |
| 4616 |
static assert(is(typeof(f4) == const(Foo))); |
| 4617 |
static assert(is(typeof(f5) == immutable(Foo))); |
| 4618 |
static assert(is(typeof(f6) == shared(Foo))); |
| 4619 |
|
| 4620 |
static struct Bar |
| 4621 |
{ |
| 4622 |
this(int x) const pure {} |
| 4623 |
} |
| 4624 |
auto g1 = new const(Bar)(1); |
| 4625 |
auto g2 = new immutable(Bar)(1); |
| 4626 |
auto g3 = new shared(Bar)(1); |
| 4627 |
auto g4 = const(Bar)(1); |
| 4628 |
auto g5 = immutable(Bar)(1); |
| 4629 |
auto g6 = shared(Bar)(1); |
| 4630 |
static assert(is(typeof(g1) == const(Bar)*)); |
| 4631 |
static assert(is(typeof(g2) == immutable(Bar)*)); |
| 4632 |
static assert(is(typeof(g3) == shared(Bar)*)); |
| 4633 |
static assert(is(typeof(g4) == const(Bar))); |
| 4634 |
static assert(is(typeof(g5) == immutable(Bar))); |
| 4635 |
static assert(is(typeof(g6) == shared(Bar))); |
| 4636 |
|
| 4637 |
static struct Baz |
| 4638 |
{ |
| 4639 |
this()(int x) const pure {} |
| 4640 |
} |
| 4641 |
auto h1 = new const(Baz)(1); |
| 4642 |
auto h2 = new immutable(Baz)(1); |
| 4643 |
auto h3 = new shared(const(Baz))(1); |
| 4644 |
auto h4 = const(Baz)(1); |
| 4645 |
auto h5 = immutable(Baz)(1); |
| 4646 |
auto h6 = shared(const(Baz))(1); |
| 4647 |
static assert(is(typeof(h1) == const(Baz)*)); |
| 4648 |
static assert(is(typeof(h2) == immutable(Baz)*)); |
| 4649 |
static assert(is(typeof(h3) == shared(const(Baz))*)); |
| 4650 |
static assert(is(typeof(h4) == const(Baz))); |
| 4651 |
static assert(is(typeof(h5) == immutable(Baz))); |
| 4652 |
static assert(is(typeof(h6) == shared(const(Baz)))); |
| 4653 |
} |
| 4654 |
|
| 4655 |
/***************************************************/ |
| 4656 |
// https://issues.dlang.org/show_bug.cgi?id=6630 |
| 4657 |
|
| 4658 |
void test6630() |
| 4659 |
{ |
| 4660 |
static class B {} |
| 4661 |
|
| 4662 |
static class A |
| 4663 |
{ |
| 4664 |
this() { b = new B(); } |
| 4665 |
B b; |
| 4666 |
alias b this; |
| 4667 |
} |
| 4668 |
|
| 4669 |
void fun(A a) |
| 4670 |
{ |
| 4671 |
a = null; |
| 4672 |
assert(a is null); |
| 4673 |
} |
| 4674 |
|
| 4675 |
auto a = new A; |
| 4676 |
assert(a.b !is null); |
| 4677 |
fun(a); |
| 4678 |
assert(a !is null); |
| 4679 |
assert(a.b !is null); |
| 4680 |
} |
| 4681 |
|
| 4682 |
/***************************************************/ |
| 4683 |
|
| 4684 |
int i199 = 1; |
| 4685 |
|
| 4686 |
void test199() |
| 4687 |
{ |
| 4688 |
label: |
| 4689 |
{ |
| 4690 |
int i199 = 2; |
| 4691 |
} |
| 4692 |
assert(i199 == 1); |
| 4693 |
} |
| 4694 |
|
| 4695 |
/***************************************************/ |
| 4696 |
// https://issues.dlang.org/show_bug.cgi?id=6690 |
| 4697 |
|
| 4698 |
T useLazy6690(T)(lazy T val) |
| 4699 |
{ |
| 4700 |
return val; |
| 4701 |
// val is converted to delegate call, but it is typed as int delegate() - not @safe! |
| 4702 |
} |
| 4703 |
void test6690() @safe |
| 4704 |
{ |
| 4705 |
useLazy6690(0); |
| 4706 |
// Error: safe function 'test6690' cannot call system function 'useLazy6690' |
| 4707 |
} |
| 4708 |
|
| 4709 |
/***************************************************/ |
| 4710 |
|
| 4711 |
template Hoge6691() |
| 4712 |
{ |
| 4713 |
immutable static int[int] dict; |
| 4714 |
immutable static int value; |
| 4715 |
|
| 4716 |
shared static this() |
| 4717 |
{ |
| 4718 |
dict = [1:1, 2:2]; |
| 4719 |
value = 10; |
| 4720 |
} |
| 4721 |
} |
| 4722 |
alias Hoge6691!() H6691; |
| 4723 |
|
| 4724 |
/***************************************************/ |
| 4725 |
|
| 4726 |
void test10626() |
| 4727 |
{ |
| 4728 |
double[2] v, x; |
| 4729 |
struct Y { double u; } |
| 4730 |
double z; |
| 4731 |
Y y; |
| 4732 |
double[2] r = v[] * x[0]; |
| 4733 |
//double[2] s = v[] * z++; |
| 4734 |
//double[2] t = v[] * z--; |
| 4735 |
double[2] a = v[] * ++z; |
| 4736 |
double[2] b = v[] * --z; |
| 4737 |
double[2] c = v[] * y.u; |
| 4738 |
x[] = 3; |
| 4739 |
double[2] d = v[] * x[0]; |
| 4740 |
double[2] e = v[] * (v[] ~ z)[0]; |
| 4741 |
} |
| 4742 |
|
| 4743 |
|
| 4744 |
/***************************************************/ |
| 4745 |
// https://issues.dlang.org/show_bug.cgi?id=2953 |
| 4746 |
|
| 4747 |
template Tuple2953(T...) |
| 4748 |
{ |
| 4749 |
alias T Tuple2953; |
| 4750 |
} |
| 4751 |
template Range2953(int b) |
| 4752 |
{ |
| 4753 |
alias Tuple2953!(1) Range2953; |
| 4754 |
} |
| 4755 |
void foo2953()() |
| 4756 |
{ |
| 4757 |
Tuple2953!(int, int) args; |
| 4758 |
foreach( x ; Range2953!(args.length) ){ } |
| 4759 |
} |
| 4760 |
void test2953() |
| 4761 |
{ |
| 4762 |
foo2953!()(); |
| 4763 |
} |
| 4764 |
|
| 4765 |
/***************************************************/ |
| 4766 |
// https://issues.dlang.org/show_bug.cgi?id=2997 |
| 4767 |
|
| 4768 |
abstract class B2997 { void foo(); } |
| 4769 |
interface I2997 { void bar(); } |
| 4770 |
abstract class C2997 : B2997, I2997 {} |
| 4771 |
//pragma(msg, __traits(allMembers, C).stringof); |
| 4772 |
|
| 4773 |
void test2997() |
| 4774 |
{ |
| 4775 |
enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"]; |
| 4776 |
|
| 4777 |
static assert([__traits(allMembers, C2997)] == ["foo"] ~ ObjectMembers ~ ["bar"]); |
| 4778 |
} |
| 4779 |
|
| 4780 |
/***************************************************/ |
| 4781 |
// https://issues.dlang.org/show_bug.cgi?id=6596 |
| 4782 |
|
| 4783 |
extern (C) int function() pfunc6596; |
| 4784 |
extern (C) int cfunc6596(){ return 0; } |
| 4785 |
static assert(typeof(pfunc6596).stringof == "extern (C) int function()"); |
| 4786 |
static assert(typeof(cfunc6596).stringof == "extern (C) int()"); |
| 4787 |
|
| 4788 |
|
| 4789 |
/***************************************************/ |
| 4790 |
// https://issues.dlang.org/show_bug.cgi?id=4423 |
| 4791 |
|
| 4792 |
struct S4423 |
| 4793 |
{ |
| 4794 |
this(string phrase, int num) |
| 4795 |
{ |
| 4796 |
this.phrase = phrase; |
| 4797 |
this.num = num; |
| 4798 |
} |
| 4799 |
|
| 4800 |
int opCmp(const ref S4423 rhs) |
| 4801 |
{ |
| 4802 |
if (phrase < rhs.phrase) |
| 4803 |
return -1; |
| 4804 |
else if (phrase > rhs.phrase) |
| 4805 |
return 1; |
| 4806 |
|
| 4807 |
if (num < rhs.num) |
| 4808 |
return -1; |
| 4809 |
else if (num > rhs.num) |
| 4810 |
return 1; |
| 4811 |
|
| 4812 |
return 0; |
| 4813 |
} |
| 4814 |
|
| 4815 |
string phrase; |
| 4816 |
int num; |
| 4817 |
} |
| 4818 |
|
| 4819 |
enum E4423 : S4423 |
| 4820 |
{ |
| 4821 |
a = S4423("hello", 1), |
| 4822 |
b = S4423("goodbye", 45), |
| 4823 |
c = S4423("world", 22), |
| 4824 |
}; |
| 4825 |
|
| 4826 |
void test4423() |
| 4827 |
{ |
| 4828 |
E4423 e; |
| 4829 |
assert(e.phrase == "hello"); |
| 4830 |
|
| 4831 |
e = E4423.b; |
| 4832 |
assert(e.phrase == "goodbye"); |
| 4833 |
} |
| 4834 |
|
| 4835 |
/***************************************************/ |
| 4836 |
// https://issues.dlang.org/show_bug.cgi?id=4647 |
| 4837 |
|
| 4838 |
interface Timer |
| 4839 |
{ |
| 4840 |
final int run() { printf("Timer.run()\n"); fun(); return 1; }; |
| 4841 |
int fun(); |
| 4842 |
} |
| 4843 |
|
| 4844 |
interface Application |
| 4845 |
{ |
| 4846 |
final int run() { printf("Application.run()\n"); fun(); return 2; }; |
| 4847 |
int fun(); |
| 4848 |
} |
| 4849 |
|
| 4850 |
class TimedApp : Timer, Application |
| 4851 |
{ |
| 4852 |
int funCalls; |
| 4853 |
override int fun() |
| 4854 |
{ |
| 4855 |
printf("TimedApp.fun()\n"); |
| 4856 |
funCalls++; |
| 4857 |
return 2; |
| 4858 |
} |
| 4859 |
} |
| 4860 |
|
| 4861 |
class SubTimedApp : TimedApp |
| 4862 |
{ |
| 4863 |
int subFunCalls; |
| 4864 |
|
| 4865 |
override int fun() |
| 4866 |
{ |
| 4867 |
printf("SubTimedApp.fun()\n"); |
| 4868 |
subFunCalls++; |
| 4869 |
return 1; |
| 4870 |
} |
| 4871 |
} |
| 4872 |
|
| 4873 |
void test4647() |
| 4874 |
{ |
| 4875 |
//Test access to TimedApps base interfaces |
| 4876 |
auto app = new TimedApp(); |
| 4877 |
assert((cast(Application)app).run() == 2); |
| 4878 |
assert((cast(Timer)app).run() == 1); |
| 4879 |
assert(app.Timer.run() == 1); // error, no Timer property |
| 4880 |
assert(app.Application.run() == 2); // error, no Application property |
| 4881 |
assert(app.run() == 1); // This would call Timer.run() if the two calls |
| 4882 |
// above were commented out |
| 4883 |
assert(app.funCalls == 5); |
| 4884 |
|
| 4885 |
assert(app.TimedApp.fun() == 2); |
| 4886 |
assert(app.funCalls == 6); |
| 4887 |
|
| 4888 |
//Test direct access to SubTimedApp interfaces |
| 4889 |
auto app2 = new SubTimedApp(); |
| 4890 |
assert((cast(Application)app2).run() == 2); |
| 4891 |
assert((cast(Timer)app2).run() == 1); |
| 4892 |
assert(app2.Application.run() == 2); |
| 4893 |
assert(app2.Timer.run() == 1); |
| 4894 |
assert(app2.funCalls == 0); |
| 4895 |
assert(app2.subFunCalls == 4); |
| 4896 |
|
| 4897 |
assert(app2.fun() == 1); |
| 4898 |
assert(app2.SubTimedApp.fun() == 1); |
| 4899 |
assert(app2.funCalls == 0); |
| 4900 |
assert(app2.subFunCalls == 6); |
| 4901 |
|
| 4902 |
//Test access to SubTimedApp interfaces via TimedApp |
| 4903 |
auto app3 = new SubTimedApp(); |
| 4904 |
(cast(Timer)cast(TimedApp)app3).run(); |
| 4905 |
app3.TimedApp.Timer.run(); |
| 4906 |
assert((cast(Application)cast(TimedApp)app3).run() == 2); |
| 4907 |
assert((cast(Timer)cast(TimedApp)app3).run() == 1); |
| 4908 |
assert(app3.TimedApp.Application.run() == 2); |
| 4909 |
assert(app3.TimedApp.Timer.run() == 1); |
| 4910 |
assert(app3.funCalls == 0); |
| 4911 |
assert(app3.subFunCalls == 6); |
| 4912 |
} |
| 4913 |
|
| 4914 |
/***************************************************/ |
| 4915 |
|
| 4916 |
template T1064(E...) { alias E T1064; } |
| 4917 |
|
| 4918 |
int[] var1064 = [ T1064!(T1064!(T1064!(1, 2), T1064!(), T1064!(3)), T1064!(4, T1064!(T1064!(T1064!(T1064!(5)))), T1064!(T1064!(T1064!(T1064!())))),6) ]; |
| 4919 |
|
| 4920 |
void test1064() |
| 4921 |
{ |
| 4922 |
assert(var1064 == [1,2,3,4,5,6]); |
| 4923 |
} |
| 4924 |
|
| 4925 |
/***************************************************/ |
| 4926 |
// https://issues.dlang.org/show_bug.cgi?id=5696 |
| 4927 |
|
| 4928 |
template Seq5696(T...){ alias T Seq5696; } |
| 4929 |
template Pred5696(T) { alias T Pred5696; } // TOKtemplate |
| 4930 |
template Scope5696(int n){ template X(T) { alias T X; } } // TOKimport |
| 4931 |
T foo5696(T)(T x) { return x; } |
| 4932 |
void test5696() |
| 4933 |
{ |
| 4934 |
foreach (pred; Seq5696!(Pred5696, Pred5696)) |
| 4935 |
{ |
| 4936 |
static assert(is(pred!int == int)); |
| 4937 |
} |
| 4938 |
|
| 4939 |
foreach (scop; Seq5696!(Scope5696!0, Scope5696!1)) |
| 4940 |
{ |
| 4941 |
static assert(is(scop.X!int == int)); |
| 4942 |
} |
| 4943 |
|
| 4944 |
alias Seq5696!(foo5696, foo5696) funcs; |
| 4945 |
assert(funcs[0](0) == 0); |
| 4946 |
assert(funcs[1](1) == 1); |
| 4947 |
foreach (i, fn; funcs) |
| 4948 |
{ |
| 4949 |
assert(fn(i) == i); |
| 4950 |
} |
| 4951 |
} |
| 4952 |
|
| 4953 |
/***************************************************/ |
| 4954 |
// https://issues.dlang.org/show_bug.cgi?id=5933 |
| 4955 |
|
| 4956 |
int dummyfunc5933(); |
| 4957 |
alias typeof(dummyfunc5933) FuncType5933; |
| 4958 |
|
| 4959 |
struct S5933a { auto x() { return 0; } } |
| 4960 |
static assert(is(typeof(&S5933a.init.x) == int delegate() pure nothrow @nogc @safe)); |
| 4961 |
|
| 4962 |
struct S5933b { auto x() { return 0; } } |
| 4963 |
//static assert(is(typeof(S5933b.init.x) == FuncType5933)); |
| 4964 |
|
| 4965 |
struct S5933c { auto x() { return 0; } } |
| 4966 |
static assert(is(typeof(&S5933c.x) == int function())); |
| 4967 |
|
| 4968 |
struct S5933d { auto x() { return 0; } } |
| 4969 |
static assert(is(typeof(S5933d.x) == FuncType5933)); |
| 4970 |
|
| 4971 |
|
| 4972 |
class C5933a { auto x() { return 0; } } |
| 4973 |
static assert(is(typeof(&(new C5933b()).x) == int delegate() pure nothrow @nogc @safe)); |
| 4974 |
|
| 4975 |
class C5933b { auto x() { return 0; } } |
| 4976 |
//static assert(is(typeof((new C5933b()).x) == FuncType5933)); |
| 4977 |
|
| 4978 |
class C5933c { auto x() { return 0; } } |
| 4979 |
static assert(is(typeof(&C5933c.x) == int function())); |
| 4980 |
|
| 4981 |
class C5933d { auto x() { return 0; } } |
| 4982 |
static assert(is(typeof(C5933d.x) == FuncType5933)); |
| 4983 |
|
| 4984 |
/***************************************************/ |
| 4985 |
// https://issues.dlang.org/show_bug.cgi?id=6084 |
| 4986 |
|
| 4987 |
template TypeTuple6084(T...){ alias T TypeTuple6084; } |
| 4988 |
void test6084() |
| 4989 |
{ |
| 4990 |
int foo(int x)() { return x; } |
| 4991 |
foreach(i; TypeTuple6084!(0)) |
| 4992 |
foo!(i); |
| 4993 |
} |
| 4994 |
|
| 4995 |
/***************************************************/ |
| 4996 |
// https://issues.dlang.org/show_bug.cgi?id=6763 |
| 4997 |
|
| 4998 |
template TypeTuple6763(TList...) |
| 4999 |
{ |
| 5000 |
alias TList TypeTuple6763; |
| 5001 |
} |
| 5002 |
|
| 5003 |
alias TypeTuple6763!(int) T6763; |
| 5004 |
|
| 5005 |
void f6763( T6763) { } /// |
| 5006 |
void c6763(const T6763) { } ///T now is (const int) |
| 5007 |
void r6763(ref T6763) { } ///T now is(ref const int) |
| 5008 |
void i6763(in T6763) { } ///Uncomment to get an Assertion failure in 'mtype.c' |
| 5009 |
void o6763(out T6763) { } ///ditto |
| 5010 |
|
| 5011 |
void test6763() |
| 5012 |
{ |
| 5013 |
int n; |
| 5014 |
|
| 5015 |
f6763(0); //With D2: Error: function main.f ((ref const const(int) __param_0)) is not callable using argument types (int) |
| 5016 |
c6763(0); |
| 5017 |
r6763(n); static assert(__traits(compiles, r6763(0))); |
| 5018 |
i6763(0); |
| 5019 |
o6763(n); static assert(!__traits(compiles, o6763(0))); |
| 5020 |
|
| 5021 |
// https://issues.dlang.org/show_bug.cgi?id=6755 |
| 5022 |
static assert(typeof(f6763).stringof == "void(int __param_0)"); |
| 5023 |
static assert(typeof(c6763).stringof == "void(const(int) __param_0)"); |
| 5024 |
static assert(typeof(r6763).stringof == "void(ref int __param_0)"); |
| 5025 |
static assert(typeof(i6763).stringof == "void(in int __param_0)"); |
| 5026 |
static assert(typeof(o6763).stringof == "void(out int __param_0)"); |
| 5027 |
} |
| 5028 |
|
| 5029 |
/***************************************************/ |
| 5030 |
// https://issues.dlang.org/show_bug.cgi?id=6695 |
| 5031 |
|
| 5032 |
struct X6695 |
| 5033 |
{ |
| 5034 |
void mfunc() |
| 5035 |
{ |
| 5036 |
static assert(is(typeof(this) == X6695)); |
| 5037 |
} |
| 5038 |
void cfunc() const |
| 5039 |
{ |
| 5040 |
static assert(is(typeof(this) == const(X6695))); |
| 5041 |
} |
| 5042 |
void ifunc() immutable |
| 5043 |
{ |
| 5044 |
static assert(is(typeof(this) == immutable(X6695))); |
| 5045 |
} |
| 5046 |
void sfunc() shared |
| 5047 |
{ |
| 5048 |
static assert(is(typeof(this) == shared(X6695))); |
| 5049 |
} |
| 5050 |
void scfunc() shared const |
| 5051 |
{ |
| 5052 |
static assert(is(typeof(this) == shared(const(X6695)))); |
| 5053 |
} |
| 5054 |
void wfunc() inout |
| 5055 |
{ |
| 5056 |
static assert(is(typeof(this) == inout(X6695))); |
| 5057 |
} |
| 5058 |
void swfunc() shared inout |
| 5059 |
{ |
| 5060 |
static assert(is(typeof(this) == shared(inout(X6695)))); |
| 5061 |
} |
| 5062 |
|
| 5063 |
static assert(is(typeof(this) == X6695)); |
| 5064 |
} |
| 5065 |
|
| 5066 |
/***************************************************/ |
| 5067 |
// https://issues.dlang.org/show_bug.cgi?id=6087 |
| 5068 |
|
| 5069 |
template True6087(T) |
| 5070 |
{ |
| 5071 |
immutable True6087 = true; |
| 5072 |
} |
| 5073 |
struct Foo6087 |
| 5074 |
{ |
| 5075 |
static assert( True6087!(typeof(this)) ); |
| 5076 |
} |
| 5077 |
|
| 5078 |
struct Bar6087 |
| 5079 |
{ |
| 5080 |
static assert( is(typeof(this) == Bar6087) ); |
| 5081 |
} |
| 5082 |
|
| 5083 |
/***************************************************/ |
| 5084 |
// https://issues.dlang.org/show_bug.cgi?id=6848 |
| 5085 |
|
| 5086 |
class Foo6848 {} |
| 5087 |
|
| 5088 |
class Bar6848 : Foo6848 |
| 5089 |
{ |
| 5090 |
void func() immutable |
| 5091 |
{ |
| 5092 |
static assert(is(typeof(this) == immutable(Bar6848))); // immutable(Bar6848) |
| 5093 |
auto t = this; |
| 5094 |
static assert(is(typeof(t) == immutable(Bar6848))); // immutable(Bar6848) |
| 5095 |
|
| 5096 |
static assert(is(typeof(super) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848) |
| 5097 |
auto s = super; |
| 5098 |
static assert(is(typeof(s) == immutable(Foo6848))); // Foo6848 instead of immutable(Foo6848) |
| 5099 |
} |
| 5100 |
} |
| 5101 |
|
| 5102 |
/***************************************************/ |
| 5103 |
|
| 5104 |
version(none) |
| 5105 |
{ |
| 5106 |
cent issue785; |
| 5107 |
ucent issue785; |
| 5108 |
} |
| 5109 |
|
| 5110 |
static assert(is(cent) && is(ucent) || !is(cent) && !is(ucent)); |
| 5111 |
static if (is(cent)) |
| 5112 |
static assert(__traits(compiles, { cent x; })); |
| 5113 |
else |
| 5114 |
static assert(!__traits(compiles, { cent x; })); |
| 5115 |
|
| 5116 |
/***************************************************/ |
| 5117 |
// https://issues.dlang.org/show_bug.cgi?id=6847 |
| 5118 |
|
| 5119 |
template True6847(T) |
| 5120 |
{ |
| 5121 |
immutable True6847 = true; |
| 5122 |
} |
| 5123 |
class Foo6847 |
| 5124 |
{} |
| 5125 |
|
| 5126 |
class Bar6847 : Foo6847 |
| 5127 |
{ |
| 5128 |
static assert( True6847!(typeof(super)) ); |
| 5129 |
static assert( is(typeof(super) == Foo6847) ); |
| 5130 |
} |
| 5131 |
|
| 5132 |
/***************************************************/ |
| 5133 |
// https://issues.dlang.org/show_bug.cgi?id=6488 |
| 5134 |
|
| 5135 |
struct TickDuration |
| 5136 |
{ |
| 5137 |
template to(T) if (__traits(isIntegral,T)) |
| 5138 |
{ |
| 5139 |
const T to() |
| 5140 |
{ |
| 5141 |
return 1; |
| 5142 |
} |
| 5143 |
} |
| 5144 |
|
| 5145 |
template to(T) if (__traits(isFloating,T)) |
| 5146 |
{ |
| 5147 |
const T to() |
| 5148 |
{ |
| 5149 |
return 0; |
| 5150 |
} |
| 5151 |
} |
| 5152 |
|
| 5153 |
const long seconds() |
| 5154 |
{ |
| 5155 |
return to!(long)(); |
| 5156 |
} |
| 5157 |
|
| 5158 |
} |
| 5159 |
|
| 5160 |
void test6488() |
| 5161 |
{ |
| 5162 |
TickDuration d; |
| 5163 |
d.seconds(); |
| 5164 |
} |
| 5165 |
|
| 5166 |
/***************************************************/ |
| 5167 |
// https://issues.dlang.org/show_bug.cgi?id=6565 |
| 5168 |
|
| 5169 |
void foo6565(out int[2][2] m) {} |
| 5170 |
|
| 5171 |
void test6565() |
| 5172 |
{ |
| 5173 |
int[2][2] mat = [[1, 2], [3, 4]]; |
| 5174 |
foo6565(mat); |
| 5175 |
assert(mat == [[0, 0], [0, 0]]); |
| 5176 |
} |
| 5177 |
|
| 5178 |
/***************************************************/ |
| 5179 |
// https://issues.dlang.org/show_bug.cgi?id=6836 |
| 5180 |
|
| 5181 |
template map6836(fun...) if (fun.length >= 1) |
| 5182 |
{ |
| 5183 |
auto map6836(Range)(Range r) |
| 5184 |
{ |
| 5185 |
} |
| 5186 |
} |
| 5187 |
void test6836() |
| 5188 |
{ |
| 5189 |
[1].map6836!"a"(); |
| 5190 |
} |
| 5191 |
|
| 5192 |
/***************************************************/ |
| 5193 |
|
| 5194 |
string func12864() { return ['a', 'b', 'c']; } |
| 5195 |
|
| 5196 |
void test12864(string s) |
| 5197 |
{ |
| 5198 |
switch (s) |
| 5199 |
{ |
| 5200 |
case func12864(): |
| 5201 |
break; |
| 5202 |
|
| 5203 |
default: |
| 5204 |
break; |
| 5205 |
} |
| 5206 |
} |
| 5207 |
|
| 5208 |
/***************************************************/ |
| 5209 |
|
| 5210 |
void test5448() |
| 5211 |
{ |
| 5212 |
int[int][] aaa = [[1: 2]]; |
| 5213 |
int[string][] a2 = [["cc":0], ["DD":10]]; |
| 5214 |
} |
| 5215 |
|
| 5216 |
/***************************************************/ |
| 5217 |
// https://issues.dlang.org/show_bug.cgi?id=6837 |
| 5218 |
|
| 5219 |
struct Ref6837a(T) |
| 5220 |
{ |
| 5221 |
T storage; |
| 5222 |
alias storage this; |
| 5223 |
} |
| 5224 |
|
| 5225 |
struct Ref6837b(T) |
| 5226 |
{ |
| 5227 |
T storage; |
| 5228 |
@property ref T get(){ return storage; } |
| 5229 |
alias get this; |
| 5230 |
} |
| 5231 |
|
| 5232 |
int front6837(int[] arr){ return arr[0]; } |
| 5233 |
|
| 5234 |
void popFront6837(ref int[] arr){ arr = arr[1..$]; } |
| 5235 |
|
| 5236 |
void test6837() |
| 5237 |
{ |
| 5238 |
assert([1,2,3].front6837 == 1); |
| 5239 |
|
| 5240 |
auto r1 = Ref6837a!(int[])([1,2,3]); |
| 5241 |
assert(r1.front6837() == 1); // ng |
| 5242 |
assert(r1.front6837 == 1); // ok |
| 5243 |
r1.popFront6837(); // ng |
| 5244 |
r1.storage.popFront6837(); // ok |
| 5245 |
|
| 5246 |
auto r2 = Ref6837b!(int[])([1,2,3]); |
| 5247 |
assert(r2.front6837() == 1); // ng |
| 5248 |
assert(r2.front6837 == 1); // ok |
| 5249 |
r2.popFront6837(); // ng |
| 5250 |
r2.get.popFront6837(); // ng |
| 5251 |
r2.get().popFront6837(); // ok |
| 5252 |
} |
| 5253 |
|
| 5254 |
/***************************************************/ |
| 5255 |
// https://issues.dlang.org/show_bug.cgi?id=6927 |
| 5256 |
|
| 5257 |
@property int[] foo6927() |
| 5258 |
{ |
| 5259 |
return [1, 2]; |
| 5260 |
} |
| 5261 |
int[] bar6927(int[] a) |
| 5262 |
{ |
| 5263 |
return a; |
| 5264 |
} |
| 5265 |
void test6927() |
| 5266 |
{ |
| 5267 |
bar6927(foo6927); // OK |
| 5268 |
foo6927.bar6927(); // line 9, Error |
| 5269 |
} |
| 5270 |
|
| 5271 |
/***************************************************/ |
| 5272 |
|
| 5273 |
struct Foo6813(T) |
| 5274 |
{ |
| 5275 |
Foo6813 Bar() |
| 5276 |
{ |
| 5277 |
return Foo6813(_indices.abc()); |
| 5278 |
} |
| 5279 |
|
| 5280 |
T _indices; |
| 5281 |
} |
| 5282 |
|
| 5283 |
struct SortedRange(alias pred) |
| 5284 |
{ |
| 5285 |
SortedRange abc() |
| 5286 |
{ |
| 5287 |
return SortedRange(); |
| 5288 |
} |
| 5289 |
} |
| 5290 |
|
| 5291 |
void test6813() { |
| 5292 |
auto ind = SortedRange!({ })(); |
| 5293 |
auto a = Foo6813!(typeof(ind))(); |
| 5294 |
} |
| 5295 |
|
| 5296 |
/***************************************************/ |
| 5297 |
|
| 5298 |
struct Interval6753{ int a,b; } |
| 5299 |
@safe struct S6753 |
| 5300 |
{ |
| 5301 |
int[] arr; |
| 5302 |
@trusted @property auto byInterval() const |
| 5303 |
{ |
| 5304 |
return cast(const(Interval6753)[])arr; |
| 5305 |
} |
| 5306 |
} |
| 5307 |
|
| 5308 |
/***************************************************/ |
| 5309 |
// https://issues.dlang.org/show_bug.cgi?id=6859 |
| 5310 |
|
| 5311 |
class Parent6859 |
| 5312 |
{ |
| 5313 |
public: |
| 5314 |
bool isHage() const @property; |
| 5315 |
|
| 5316 |
public: |
| 5317 |
abstract void fuga() |
| 5318 |
out |
| 5319 |
{ |
| 5320 |
assert(isHage); |
| 5321 |
} |
| 5322 |
do { } |
| 5323 |
} |
| 5324 |
|
| 5325 |
class Child6859 : Parent6859 |
| 5326 |
{ |
| 5327 |
override bool isHage() const @property |
| 5328 |
{ |
| 5329 |
return true; |
| 5330 |
} |
| 5331 |
override void fuga() |
| 5332 |
{ |
| 5333 |
//nop |
| 5334 |
} |
| 5335 |
} |
| 5336 |
|
| 5337 |
void test6859() |
| 5338 |
{ |
| 5339 |
auto t = new Child6859; |
| 5340 |
t.fuga(); |
| 5341 |
printf("done.\n"); |
| 5342 |
} |
| 5343 |
|
| 5344 |
/***************************************************/ |
| 5345 |
// https://issues.dlang.org/show_bug.cgi?id=6910 |
| 5346 |
|
| 5347 |
template Test6910(alias i, B) |
| 5348 |
{ |
| 5349 |
void fn() |
| 5350 |
{ |
| 5351 |
foreach(t; B.Types) |
| 5352 |
{ |
| 5353 |
switch(i) |
| 5354 |
{ |
| 5355 |
case 0://IndexOf!(t, B.Types): |
| 5356 |
{ |
| 5357 |
pragma(msg, __traits(allMembers, t)); |
| 5358 |
pragma(msg, __traits(hasMember, t, "m")); |
| 5359 |
static assert(__traits(hasMember, t, "m")); // test |
| 5360 |
break; |
| 5361 |
} |
| 5362 |
default: {} |
| 5363 |
} |
| 5364 |
} |
| 5365 |
} |
| 5366 |
} |
| 5367 |
void test6910() |
| 5368 |
{ |
| 5369 |
static struct Bag(S...) |
| 5370 |
{ |
| 5371 |
alias S Types; |
| 5372 |
} |
| 5373 |
static struct A |
| 5374 |
{ |
| 5375 |
int m; |
| 5376 |
} |
| 5377 |
|
| 5378 |
int i; |
| 5379 |
alias Test6910!(i, Bag!(A)).fn func; |
| 5380 |
} |
| 5381 |
|
| 5382 |
/***************************************************/ |
| 5383 |
|
| 5384 |
void fun12503() |
| 5385 |
{ |
| 5386 |
string b = "abc"; |
| 5387 |
try |
| 5388 |
{ |
| 5389 |
try |
| 5390 |
{ |
| 5391 |
b = null; |
| 5392 |
return; |
| 5393 |
} |
| 5394 |
catch(Throwable) |
| 5395 |
{ |
| 5396 |
} |
| 5397 |
} |
| 5398 |
finally |
| 5399 |
{ |
| 5400 |
assert("abc" !is b); |
| 5401 |
} |
| 5402 |
} |
| 5403 |
|
| 5404 |
void test12503() |
| 5405 |
{ |
| 5406 |
fun12503(); |
| 5407 |
} |
| 5408 |
|
| 5409 |
/***************************************************/ |
| 5410 |
// https://issues.dlang.org/show_bug.cgi?id=6902 |
| 5411 |
|
| 5412 |
void test6902() |
| 5413 |
{ |
| 5414 |
static assert(is(typeof({ |
| 5415 |
return int.init; // int, long, real, etc. |
| 5416 |
}))); |
| 5417 |
|
| 5418 |
int f() pure nothrow { assert(0); } |
| 5419 |
alias int T() pure nothrow @safe @nogc; |
| 5420 |
static if(is(typeof(&f) DT == delegate)) |
| 5421 |
{ |
| 5422 |
static assert(is(DT* == T*)); // ok |
| 5423 |
|
| 5424 |
// Error: static assert (is(pure nothrow int() == pure nothrow int())) is false |
| 5425 |
static assert(is(DT == T)); |
| 5426 |
} |
| 5427 |
} |
| 5428 |
|
| 5429 |
/***************************************************/ |
| 5430 |
// https://issues.dlang.org/show_bug.cgi?id=6330 |
| 5431 |
|
| 5432 |
struct S6330 |
| 5433 |
{ |
| 5434 |
void opAssign(S6330 s) @disable |
| 5435 |
{ |
| 5436 |
assert(0); // This fails. |
| 5437 |
} |
| 5438 |
} |
| 5439 |
|
| 5440 |
void test6330() |
| 5441 |
{ |
| 5442 |
S6330 s; |
| 5443 |
S6330 s2; |
| 5444 |
static assert(!is(typeof({ s2 = s; }))); |
| 5445 |
} |
| 5446 |
|
| 5447 |
/***************************************************/ |
| 5448 |
|
| 5449 |
struct S8269 |
| 5450 |
{ |
| 5451 |
bool dtor = false; |
| 5452 |
~this() |
| 5453 |
{ |
| 5454 |
dtor = true; |
| 5455 |
} |
| 5456 |
} |
| 5457 |
|
| 5458 |
void test8269() |
| 5459 |
{ |
| 5460 |
with(S8269()) |
| 5461 |
{ |
| 5462 |
assert(!dtor); |
| 5463 |
} |
| 5464 |
} |
| 5465 |
|
| 5466 |
/***************************************************/ |
| 5467 |
// https://issues.dlang.org/show_bug.cgi?id=5311 |
| 5468 |
|
| 5469 |
class C5311 |
| 5470 |
{ |
| 5471 |
private static int globalData; |
| 5472 |
|
| 5473 |
void breaksPure() pure const |
| 5474 |
{ |
| 5475 |
static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR |
| 5476 |
static assert(!__traits(compiles, { C5311.globalData++; }));// SHOULD BE ERROR |
| 5477 |
static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR |
| 5478 |
|
| 5479 |
static assert(!__traits(compiles, { int a = this.globalData; })); |
| 5480 |
} |
| 5481 |
} |
| 5482 |
static void breaksPure5311a(C5311 x) pure |
| 5483 |
{ |
| 5484 |
static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR |
| 5485 |
|
| 5486 |
static assert(!__traits(compiles, { int a = x.globalData; })); |
| 5487 |
} |
| 5488 |
|
| 5489 |
struct S5311 |
| 5490 |
{ |
| 5491 |
private static int globalData; |
| 5492 |
|
| 5493 |
void breaksPure() pure const |
| 5494 |
{ |
| 5495 |
static assert(!__traits(compiles, { globalData++; })); // SHOULD BE ERROR |
| 5496 |
static assert(!__traits(compiles, { S5311.globalData++; }));// SHOULD BE ERROR |
| 5497 |
static assert(!__traits(compiles, { this.globalData++; })); // SHOULD BE ERROR |
| 5498 |
|
| 5499 |
static assert(!__traits(compiles, { int a = this.globalData; })); |
| 5500 |
} |
| 5501 |
} |
| 5502 |
static void breaksPure5311b(S5311 x) pure |
| 5503 |
{ |
| 5504 |
static assert(!__traits(compiles, { x.globalData++; })); // SHOULD BE ERROR |
| 5505 |
|
| 5506 |
static assert(!__traits(compiles, { int a = x.globalData; })); |
| 5507 |
} |
| 5508 |
|
| 5509 |
/***************************************************/ |
| 5510 |
// https://issues.dlang.org/show_bug.cgi?id=6868 |
| 5511 |
|
| 5512 |
@property bool empty6868(T)(in T[] a) @safe pure nothrow |
| 5513 |
{ |
| 5514 |
return !a.length; |
| 5515 |
} |
| 5516 |
|
| 5517 |
void test6868() |
| 5518 |
{ |
| 5519 |
alias int[] Range; |
| 5520 |
static if (is(char[1 + Range.empty6868])) // Line 9 |
| 5521 |
enum bool isInfinite = true; |
| 5522 |
|
| 5523 |
char[0] s; // need |
| 5524 |
} |
| 5525 |
|
| 5526 |
/***************************************************/ |
| 5527 |
// https://issues.dlang.org/show_bug.cgi?id=2856 |
| 5528 |
|
| 5529 |
struct foo2856 { static void opIndex(int i) { printf("foo\n"); } } |
| 5530 |
struct bar2856(T) { static void opIndex(int i) { printf("bar\n"); } } |
| 5531 |
|
| 5532 |
void test2856() |
| 5533 |
{ |
| 5534 |
foo2856[1]; |
| 5535 |
bar2856!(float)[1]; // Error (# = __LINE__) |
| 5536 |
alias bar2856!(float) B; |
| 5537 |
B[1]; // Okay |
| 5538 |
} |
| 5539 |
|
| 5540 |
/***************************************************/ |
| 5541 |
|
| 5542 |
void test13947() |
| 5543 |
{ |
| 5544 |
struct S {} |
| 5545 |
static assert(S.sizeof == 1); |
| 5546 |
|
| 5547 |
S a; |
| 5548 |
S b; |
| 5549 |
*cast(ubyte*)&a = 1; |
| 5550 |
*cast(ubyte*)&b = 2; |
| 5551 |
assert(a == b); |
| 5552 |
assert(a is b); |
| 5553 |
assert(!(a != b)); |
| 5554 |
assert(!(a !is b)); |
| 5555 |
static assert(S() == S()); |
| 5556 |
static assert(S() is S()); |
| 5557 |
static assert(!(S() != S())); |
| 5558 |
static assert(!(S() !is S())); |
| 5559 |
} |
| 5560 |
|
| 5561 |
/***************************************************/ |
| 5562 |
// https://issues.dlang.org/show_bug.cgi?id=3091 |
| 5563 |
|
| 5564 |
void test3091(inout int = 0) |
| 5565 |
{ |
| 5566 |
struct Foo {} |
| 5567 |
|
| 5568 |
auto pm = new Foo; static assert(is( typeof( pm) == Foo * )); |
| 5569 |
auto pc = new const Foo; static assert(is( typeof( pc) == const(Foo) * )); |
| 5570 |
auto pw = new inout Foo; static assert(is( typeof( pw) == inout(Foo) * )); |
| 5571 |
auto psm = new shared Foo; static assert(is( typeof(psm) == shared(Foo) * )); |
| 5572 |
auto psc = new shared const Foo; static assert(is( typeof(psc) == shared(const(Foo))* )); |
| 5573 |
auto psw = new shared inout Foo; static assert(is( typeof(psw) == shared(inout(Foo))* )); |
| 5574 |
auto pi = new immutable Foo; static assert(is( typeof( pi) == immutable(Foo) * )); |
| 5575 |
|
| 5576 |
auto m = Foo(); static assert(is( typeof( m) == Foo )); |
| 5577 |
auto c = const Foo(); static assert(is( typeof( c) == const(Foo) )); |
| 5578 |
auto w = inout Foo(); static assert(is( typeof( w) == inout(Foo) )); |
| 5579 |
auto sm = shared Foo(); static assert(is( typeof(sm) == shared(Foo) )); |
| 5580 |
auto sc = shared const Foo(); static assert(is( typeof(sc) == shared(const(Foo)) )); |
| 5581 |
auto sw = shared inout Foo(); static assert(is( typeof(sw) == shared(inout(Foo)) )); |
| 5582 |
auto i = immutable Foo(); static assert(is( typeof( i) == immutable(Foo) )); |
| 5583 |
} |
| 5584 |
|
| 5585 |
/***************************************************/ |
| 5586 |
// https://issues.dlang.org/show_bug.cgi?id=6837 |
| 5587 |
|
| 5588 |
template Id6837(T) |
| 5589 |
{ |
| 5590 |
alias T Id6837; |
| 5591 |
} |
| 5592 |
static assert(is(Id6837!(shared const int) == shared const int)); |
| 5593 |
static assert(is(Id6837!(shared inout int) == shared inout int)); |
| 5594 |
|
| 5595 |
/***************************************************/ |
| 5596 |
// https://issues.dlang.org/show_bug.cgi?id=6056 fixup |
| 5597 |
|
| 5598 |
template ParameterTypeTuple6056(func) |
| 5599 |
{ |
| 5600 |
static if (is(func Fptr : Fptr*) && is(Fptr P == function)) |
| 5601 |
alias P ParameterTypeTuple6056; |
| 5602 |
else |
| 5603 |
static assert(0, "argument has no parameters"); |
| 5604 |
} |
| 5605 |
|
| 5606 |
extern(C) alias void function() fpw_t; |
| 5607 |
|
| 5608 |
alias void function(fpw_t fp) cb_t; |
| 5609 |
|
| 5610 |
void bar6056(ParameterTypeTuple6056!(cb_t) args) { |
| 5611 |
pragma (msg, "TFunction1: " ~ typeof(args[0]).stringof); |
| 5612 |
} |
| 5613 |
|
| 5614 |
extern(C) void foo6056() { } |
| 5615 |
|
| 5616 |
void test6056() |
| 5617 |
{ |
| 5618 |
bar6056(&foo6056); |
| 5619 |
} |
| 5620 |
|
| 5621 |
/***************************************************/ |
| 5622 |
// https://issues.dlang.org/show_bug.cgi?id=6356 |
| 5623 |
|
| 5624 |
int f6356()(int a) |
| 5625 |
{ |
| 5626 |
return a*a; |
| 5627 |
} |
| 5628 |
|
| 5629 |
alias f6356!() g6356; // comment this out to eliminate the errors |
| 5630 |
|
| 5631 |
pure nothrow @safe int i6356() |
| 5632 |
{ |
| 5633 |
return f6356(1); |
| 5634 |
} |
| 5635 |
|
| 5636 |
void test6356() |
| 5637 |
{ |
| 5638 |
assert(i6356() == 1); |
| 5639 |
} |
| 5640 |
|
| 5641 |
/***************************************************/ |
| 5642 |
// https://issues.dlang.org/show_bug.cgi?id=7108 |
| 5643 |
|
| 5644 |
static assert(!__traits(hasMember, int, "x")); |
| 5645 |
static assert( __traits(hasMember, int, "init")); |
| 5646 |
|
| 5647 |
/***************************************************/ |
| 5648 |
// https://issues.dlang.org/show_bug.cgi?id=7073 |
| 5649 |
|
| 5650 |
void test7073() |
| 5651 |
{ |
| 5652 |
string f(int[] arr...) |
| 5653 |
{ |
| 5654 |
return ""; |
| 5655 |
} |
| 5656 |
} |
| 5657 |
|
| 5658 |
/***************************************************/ |
| 5659 |
// https://issues.dlang.org/show_bug.cgi?id=7104 |
| 5660 |
|
| 5661 |
void test7104() |
| 5662 |
{ |
| 5663 |
typeof(new class {}) c; |
| 5664 |
c = new typeof(c); |
| 5665 |
} |
| 5666 |
|
| 5667 |
/***************************************************/ |
| 5668 |
// https://issues.dlang.org/show_bug.cgi?id=7150 |
| 5669 |
|
| 5670 |
struct A7150 |
| 5671 |
{ |
| 5672 |
static int cnt; |
| 5673 |
|
| 5674 |
this(T)(T thing, int i) |
| 5675 |
{ |
| 5676 |
this(thing, i > 0); // Error: constructor call must be in a constructor |
| 5677 |
++cnt; |
| 5678 |
} |
| 5679 |
this(T)(T thing, bool b) |
| 5680 |
{ |
| 5681 |
++cnt; |
| 5682 |
} |
| 5683 |
} |
| 5684 |
|
| 5685 |
void test7150() |
| 5686 |
{ |
| 5687 |
auto a = A7150(5, 5); // Error: template instance constructtest.A.__ctor!(int) error instantiating |
| 5688 |
assert(A7150.cnt == 2); |
| 5689 |
} |
| 5690 |
|
| 5691 |
/***************************************************/ |
| 5692 |
// https://issues.dlang.org/show_bug.cgi?id=7159 |
| 5693 |
|
| 5694 |
alias void delegate() Void7159; |
| 5695 |
|
| 5696 |
class HomeController7159 { |
| 5697 |
Void7159 foo() { |
| 5698 |
return cast(Void7159)&HomeController7159.displayDefault; |
| 5699 |
} |
| 5700 |
auto displayDefault() { |
| 5701 |
return 1; |
| 5702 |
} |
| 5703 |
} |
| 5704 |
|
| 5705 |
/***************************************************/ |
| 5706 |
// https://issues.dlang.org/show_bug.cgi?id=7160 |
| 5707 |
|
| 5708 |
class HomeController { |
| 5709 |
static if (false) { |
| 5710 |
mixin(q{ int a; }); |
| 5711 |
} |
| 5712 |
void foo() { |
| 5713 |
foreach (m; __traits(derivedMembers, HomeController)) { |
| 5714 |
} |
| 5715 |
} |
| 5716 |
} |
| 5717 |
|
| 5718 |
void test7160() |
| 5719 |
{} |
| 5720 |
|
| 5721 |
/***************************************************/ |
| 5722 |
// https://issues.dlang.org/show_bug.cgi?id=7168 |
| 5723 |
|
| 5724 |
void test7168() |
| 5725 |
{ |
| 5726 |
static class X |
| 5727 |
{ |
| 5728 |
void foo(){} |
| 5729 |
} |
| 5730 |
static class Y : X |
| 5731 |
{ |
| 5732 |
void bar(){} |
| 5733 |
} |
| 5734 |
|
| 5735 |
enum ObjectMembers = ["toString","toHash","opCmp","opEquals","Monitor","factory"]; |
| 5736 |
|
| 5737 |
static assert([__traits(allMembers, X)] == ["foo"]~ObjectMembers); // pass |
| 5738 |
static assert([__traits(allMembers, Y)] == ["bar", "foo"]~ObjectMembers); // fail |
| 5739 |
static assert([__traits(allMembers, Y)] != ["bar", "foo"]); // fail |
| 5740 |
} |
| 5741 |
|
| 5742 |
/***************************************************/ |
| 5743 |
// https://issues.dlang.org/show_bug.cgi?id=7170 |
| 5744 |
|
| 5745 |
T to7170(T)(string x) { return 1; } |
| 5746 |
void test7170() |
| 5747 |
{ |
| 5748 |
// auto i = to7170!int("1"); // OK |
| 5749 |
auto j = "1".to7170!int(); // NG, Internal error: e2ir.c 683 |
| 5750 |
} |
| 5751 |
|
| 5752 |
/***************************************************/ |
| 5753 |
// https://issues.dlang.org/show_bug.cgi?id=7196 |
| 5754 |
|
| 5755 |
auto foo7196(int x){return x;} |
| 5756 |
auto foo7196(double x){return x;} |
| 5757 |
|
| 5758 |
void test7196() |
| 5759 |
{ |
| 5760 |
auto x = (&foo7196)(1); // ok |
| 5761 |
auto y = (&foo7196)(1.0); // fail |
| 5762 |
} |
| 5763 |
|
| 5764 |
/***************************************************/ |
| 5765 |
// https://issues.dlang.org/show_bug.cgi?id=7285 |
| 5766 |
|
| 5767 |
int[2] spam7285() |
| 5768 |
{ |
| 5769 |
int[2] ab; |
| 5770 |
if (true) |
| 5771 |
return (true) ? ab : [0, 0]; // Error |
| 5772 |
else |
| 5773 |
return (true) ? [0, 0] : ab; // OK |
| 5774 |
} |
| 5775 |
|
| 5776 |
void test7285() |
| 5777 |
{ |
| 5778 |
auto sa = spam7285(); |
| 5779 |
} |
| 5780 |
|
| 5781 |
/***************************************************/ |
| 5782 |
// https://issues.dlang.org/show_bug.cgi?id=14737 |
| 5783 |
|
| 5784 |
void test14737() |
| 5785 |
{ |
| 5786 |
// compile-time |
| 5787 |
enum string[2] a1 = ["d", "e"]; |
| 5788 |
enum b1x = ["a", "b", "c"] ~ a1; // Tarray vs Tsarray |
| 5789 |
enum b1y = a1 ~ ["a", "b", "c"]; // Tsarray vs Tarray |
| 5790 |
static assert(is(typeof(b1x) == string[])); |
| 5791 |
static assert(is(typeof(b1y) == string[])); |
| 5792 |
static assert(b1x == ["a", "b", "c", "d", "e"]); |
| 5793 |
static assert(b1y == ["d", "e", "a", "b", "c"]); |
| 5794 |
|
| 5795 |
// runtime |
| 5796 |
string[2] a2 = ["d", "e"]; |
| 5797 |
auto b2x = ["a", "b", "c"] ~ a2; // Tarray vs Tsarray |
| 5798 |
auto b2y = a2 ~ ["a", "b", "c"]; // Tsarray vs Tarray |
| 5799 |
static assert(is(typeof(b2x) == string[])); |
| 5800 |
static assert(is(typeof(b2y) == string[])); |
| 5801 |
assert(b2x == ["a", "b", "c", "d", "e"]); |
| 5802 |
assert(b2y == ["d", "e", "a", "b", "c"]); |
| 5803 |
} |
| 5804 |
|
| 5805 |
/***************************************************/ |
| 5806 |
// https://issues.dlang.org/show_bug.cgi?id=7321 |
| 5807 |
|
| 5808 |
void test7321() |
| 5809 |
{ |
| 5810 |
static assert(is(typeof((){})==void function()pure nothrow @nogc @safe)); // ok |
| 5811 |
static assert(is(typeof((){return;})==void function()pure nothrow @nogc @safe)); // fail |
| 5812 |
} |
| 5813 |
|
| 5814 |
/***************************************************/ |
| 5815 |
|
| 5816 |
class A158 |
| 5817 |
{ |
| 5818 |
pure void foo1() { } |
| 5819 |
const void foo2() { } |
| 5820 |
nothrow void foo3() { } |
| 5821 |
@safe void foo4() { } |
| 5822 |
} |
| 5823 |
|
| 5824 |
class B158 : A158 |
| 5825 |
{ |
| 5826 |
override void foo1() { } |
| 5827 |
override void foo2() const { } |
| 5828 |
override void foo3() { } |
| 5829 |
override void foo4() { } |
| 5830 |
} |
| 5831 |
|
| 5832 |
/***************************************************/ |
| 5833 |
// https://issues.dlang.org/show_bug.cgi?id=9231 |
| 5834 |
|
| 5835 |
class B9231 { void foo() inout pure {} } |
| 5836 |
class D9231 : B9231 { override void foo() inout {} } |
| 5837 |
|
| 5838 |
/***************************************************/ |
| 5839 |
// https://issues.dlang.org/show_bug.cgi?id=3282 |
| 5840 |
|
| 5841 |
class Base3282 |
| 5842 |
{ |
| 5843 |
string f() |
| 5844 |
{ |
| 5845 |
return "Base.f()"; |
| 5846 |
} |
| 5847 |
} |
| 5848 |
class Derived3282 : Base3282 |
| 5849 |
{ |
| 5850 |
override string f() |
| 5851 |
{ |
| 5852 |
return "Derived.f()"; |
| 5853 |
} |
| 5854 |
/*override*/ string f() const |
| 5855 |
{ |
| 5856 |
return "Derived.f() const"; |
| 5857 |
} |
| 5858 |
} |
| 5859 |
|
| 5860 |
void test3282() |
| 5861 |
{ |
| 5862 |
auto x = new Base3282; |
| 5863 |
assert(x.f() == "Base.f()"); |
| 5864 |
auto y = new Derived3282; |
| 5865 |
assert(y.f() == "Derived.f()");// calls "Derived.f() const", but it is expected that be called non-const. |
| 5866 |
auto z = new const(Derived3282); |
| 5867 |
assert(z.f() == "Derived.f() const"); |
| 5868 |
} |
| 5869 |
|
| 5870 |
/***************************************************/ |
| 5871 |
// https://issues.dlang.org/show_bug.cgi?id=7534 |
| 5872 |
|
| 5873 |
class C7534 |
| 5874 |
{ |
| 5875 |
int foo(){ return 1; } |
| 5876 |
} |
| 5877 |
class D7534 : C7534 |
| 5878 |
{ |
| 5879 |
override int foo(){ return 2; } |
| 5880 |
/*override*/ int foo() const { return 3; } |
| 5881 |
// Error: D.foo multiple overrides of same function |
| 5882 |
} |
| 5883 |
void test7534() |
| 5884 |
{ |
| 5885 |
C7534 mc = new C7534(); |
| 5886 |
assert(mc.foo() == 1); |
| 5887 |
|
| 5888 |
D7534 md = new D7534(); |
| 5889 |
assert(md.foo() == 2); |
| 5890 |
mc = md; |
| 5891 |
assert(mc.foo() == 2); |
| 5892 |
|
| 5893 |
const(D7534) cd = new const(D7534)(); |
| 5894 |
assert(cd.foo() == 3); |
| 5895 |
md = cast()cd; |
| 5896 |
assert(md.foo() == 2); |
| 5897 |
} |
| 5898 |
|
| 5899 |
/***************************************************/ |
| 5900 |
// https://issues.dlang.org/show_bug.cgi?id=7534 |
| 5901 |
// return type covariance |
| 5902 |
|
| 5903 |
class X7534 {} |
| 5904 |
class Y7534 : X7534 |
| 5905 |
{ |
| 5906 |
int value; this(int n){ value = n; } |
| 5907 |
} |
| 5908 |
|
| 5909 |
class V7534 |
| 5910 |
{ |
| 5911 |
X7534 foo(){ return new X7534(); } |
| 5912 |
} |
| 5913 |
class W7534 : V7534 |
| 5914 |
{ |
| 5915 |
override Y7534 foo(){ return new Y7534(1); } |
| 5916 |
/*override*/ Y7534 foo() const { return new Y7534(2); } |
| 5917 |
} |
| 5918 |
|
| 5919 |
void test7534cov() |
| 5920 |
{ |
| 5921 |
auto mv = new V7534(); |
| 5922 |
assert(typeid(mv.foo()) == typeid(X7534)); |
| 5923 |
|
| 5924 |
auto mw = new W7534(); |
| 5925 |
assert(typeid(mw.foo()) == typeid(Y7534)); |
| 5926 |
assert(mw.foo().value == 1); |
| 5927 |
mv = mw; |
| 5928 |
assert(typeid(mv.foo()) == typeid(Y7534)); |
| 5929 |
assert((cast(Y7534)mv.foo()).value == 1); |
| 5930 |
|
| 5931 |
auto cw = new const(W7534)(); |
| 5932 |
assert(typeid(cw.foo()) == typeid(Y7534)); |
| 5933 |
assert(cw.foo().value == 2); |
| 5934 |
} |
| 5935 |
|
| 5936 |
/***************************************************/ |
| 5937 |
// https://issues.dlang.org/show_bug.cgi?id=7562 |
| 5938 |
|
| 5939 |
static struct MyInt |
| 5940 |
{ |
| 5941 |
private int value; |
| 5942 |
mixin ProxyOf!value; |
| 5943 |
} |
| 5944 |
mixin template ProxyOf(alias a) |
| 5945 |
{ |
| 5946 |
template X1(){} |
| 5947 |
template X2(){} |
| 5948 |
template X3(){} |
| 5949 |
template X4(){} |
| 5950 |
template X5(){} |
| 5951 |
template X6(){} |
| 5952 |
template X7(){} |
| 5953 |
template X8(){} |
| 5954 |
template X9(){} |
| 5955 |
template X10(){} |
| 5956 |
|
| 5957 |
void test1(this X)(){} |
| 5958 |
void test2(this Y)(){} |
| 5959 |
} |
| 5960 |
|
| 5961 |
/***************************************************/ |
| 5962 |
|
| 5963 |
import core.stdc.stdlib; |
| 5964 |
|
| 5965 |
void test13427(void* buffer = alloca(100)) |
| 5966 |
{ |
| 5967 |
} |
| 5968 |
|
| 5969 |
/***************************************************/ |
| 5970 |
// https://issues.dlang.org/show_bug.cgi?id=7583 |
| 5971 |
|
| 5972 |
template Tup7583(E...) { alias E Tup7583; } |
| 5973 |
|
| 5974 |
struct S7583 |
| 5975 |
{ |
| 5976 |
Tup7583!(float, char) field; |
| 5977 |
alias field this; |
| 5978 |
this(int x) { } |
| 5979 |
} |
| 5980 |
|
| 5981 |
int bug7583() { |
| 5982 |
S7583[] arr; |
| 5983 |
arr ~= S7583(0); |
| 5984 |
return 1; |
| 5985 |
} |
| 5986 |
|
| 5987 |
static assert (bug7583()); |
| 5988 |
|
| 5989 |
/***************************************************/ |
| 5990 |
// https://issues.dlang.org/show_bug.cgi?id=7618 |
| 5991 |
|
| 5992 |
void test7618(const int x = 1) |
| 5993 |
{ |
| 5994 |
int func(ref int x) { return 1; } |
| 5995 |
static assert(!__traits(compiles, func(x))); |
| 5996 |
// Error: function test.foo.func (ref int __param_0) is not callable using argument types (const(int)) |
| 5997 |
|
| 5998 |
int delegate(ref int) dg = (ref int x) => 1; |
| 5999 |
static assert(!__traits(compiles, dg(x))); |
| 6000 |
// --> no error, bad! |
| 6001 |
|
| 6002 |
int function(ref int) fp = (ref int x) => 1; |
| 6003 |
static assert(!__traits(compiles, fp(x))); |
| 6004 |
// --> no error, bad! |
| 6005 |
} |
| 6006 |
|
| 6007 |
/***************************************************/ |
| 6008 |
// https://issues.dlang.org/show_bug.cgi?id=7621 |
| 6009 |
|
| 6010 |
void test7621() |
| 6011 |
{ |
| 6012 |
enum uint N = 4u; |
| 6013 |
char[] A = "hello".dup; |
| 6014 |
uint[immutable char[4u]] dict; |
| 6015 |
dict[*cast(immutable char[4]*)(A[0 .. N].ptr)] = 0; // OK |
| 6016 |
dict[*cast(immutable char[N]*)(A[0 .. N].ptr)] = 0; // line 6, error |
| 6017 |
} |
| 6018 |
|
| 6019 |
/***************************************************/ |
| 6020 |
// https://issues.dlang.org/show_bug.cgi?id=7682 |
| 6021 |
|
| 6022 |
template ConstOf7682(T) |
| 6023 |
{ |
| 6024 |
alias const(T) ConstOf7682; |
| 6025 |
} |
| 6026 |
bool pointsTo7682(S)(ref const S source) @trusted pure nothrow |
| 6027 |
{ |
| 6028 |
return true; |
| 6029 |
} |
| 6030 |
void test7682() |
| 6031 |
{ |
| 6032 |
shared(ConstOf7682!(int[])) x; // line A |
| 6033 |
|
| 6034 |
struct S3 { int[10] a; } |
| 6035 |
shared(S3) sh3; |
| 6036 |
shared(int[]) sh3sub = sh3.a[]; |
| 6037 |
assert(pointsTo7682(sh3sub)); // line B |
| 6038 |
} |
| 6039 |
|
| 6040 |
/***************************************************/ |
| 6041 |
// https://issues.dlang.org/show_bug.cgi?id=7735 |
| 6042 |
|
| 6043 |
void a7735(void[][] data...) |
| 6044 |
{ |
| 6045 |
//writeln(data); |
| 6046 |
assert(data.length == 1); |
| 6047 |
b7735(data); |
| 6048 |
} |
| 6049 |
|
| 6050 |
void b7735(void[][] data...) |
| 6051 |
{ |
| 6052 |
//writeln(data); |
| 6053 |
assert(data.length == 1); |
| 6054 |
c7735(data); |
| 6055 |
} |
| 6056 |
|
| 6057 |
void c7735(void[][] data...) |
| 6058 |
{ |
| 6059 |
//writeln(data); |
| 6060 |
assert(data.length == 1); |
| 6061 |
} |
| 6062 |
|
| 6063 |
void test7735() |
| 6064 |
{ |
| 6065 |
a7735([]); |
| 6066 |
a7735([]); |
| 6067 |
} |
| 6068 |
|
| 6069 |
/***************************************************/ |
| 6070 |
|
| 6071 |
struct A7823 { |
| 6072 |
long a; |
| 6073 |
enum A7823 b = {0}; |
| 6074 |
} |
| 6075 |
|
| 6076 |
void test7823(A7823 a = A7823.b) { } |
| 6077 |
|
| 6078 |
/***************************************************/ |
| 6079 |
// https://issues.dlang.org/show_bug.cgi?id=7871 |
| 6080 |
|
| 6081 |
struct Tuple7871 |
| 6082 |
{ |
| 6083 |
string field; |
| 6084 |
alias field this; |
| 6085 |
} |
| 6086 |
|
| 6087 |
//auto findSplitBefore(R1)(R1 haystack) |
| 6088 |
auto findSplitBefore7871(string haystack) |
| 6089 |
{ |
| 6090 |
return Tuple7871(haystack); |
| 6091 |
} |
| 6092 |
|
| 6093 |
void test7871() |
| 6094 |
{ |
| 6095 |
string line = `<bookmark href="https://stuff">`; |
| 6096 |
auto a = findSplitBefore7871(line[0 .. $])[0]; |
| 6097 |
} |
| 6098 |
|
| 6099 |
/***************************************************/ |
| 6100 |
// https://issues.dlang.org/show_bug.cgi?id=7906 |
| 6101 |
|
| 6102 |
void test7906() |
| 6103 |
{ |
| 6104 |
static assert(!__traits(compiles, { enum s = [string.min]; })); |
| 6105 |
} |
| 6106 |
|
| 6107 |
/***************************************************/ |
| 6108 |
// https://issues.dlang.org/show_bug.cgi?id=7907 |
| 6109 |
|
| 6110 |
template Id7907(E) |
| 6111 |
{ |
| 6112 |
alias E Id7907; |
| 6113 |
} |
| 6114 |
template Id7907(alias E) |
| 6115 |
{ |
| 6116 |
alias E Id7907; |
| 6117 |
} |
| 6118 |
|
| 6119 |
void test7907() |
| 6120 |
{ |
| 6121 |
static assert(!__traits(compiles, { alias Id7907!([string.min]) X; })); |
| 6122 |
} |
| 6123 |
|
| 6124 |
/***************************************************/ |
| 6125 |
// https://issues.dlang.org/show_bug.cgi?id=1175 |
| 6126 |
|
| 6127 |
class A1175 |
| 6128 |
{ |
| 6129 |
class I1 { } |
| 6130 |
} |
| 6131 |
|
| 6132 |
class B1175 : A1175 |
| 6133 |
{ |
| 6134 |
class I2 : I1 { } |
| 6135 |
|
| 6136 |
I1 getI() { return new I2; } |
| 6137 |
} |
| 6138 |
|
| 6139 |
/***************************************************/ |
| 6140 |
// https://issues.dlang.org/show_bug.cgi?id=8004 |
| 6141 |
|
| 6142 |
void test8004() |
| 6143 |
{ |
| 6144 |
auto n = (int n = 10){ return n; }(); |
| 6145 |
assert(n == 10); |
| 6146 |
} |
| 6147 |
|
| 6148 |
/***************************************************/ |
| 6149 |
// https://issues.dlang.org/show_bug.cgi?id=8064 |
| 6150 |
|
| 6151 |
void test8064() |
| 6152 |
{ |
| 6153 |
uint[5] arry; |
| 6154 |
ref uint acc(size_t i) { |
| 6155 |
return arry[i]; |
| 6156 |
} |
| 6157 |
auto arryacc = &acc; |
| 6158 |
arryacc(3) = 5; // same error |
| 6159 |
} |
| 6160 |
|
| 6161 |
/***************************************************/ |
| 6162 |
// https://issues.dlang.org/show_bug.cgi?id=8220 |
| 6163 |
|
| 6164 |
void foo8220(int){} |
| 6165 |
static assert(!__traits(compiles, foo8220(typeof(0)))); // fail |
| 6166 |
|
| 6167 |
/***************************************************/ |
| 6168 |
|
| 6169 |
template ParameterTypeTuple159(alias foo) |
| 6170 |
{ |
| 6171 |
static if (is(typeof(foo) P == __parameters)) |
| 6172 |
alias P ParameterTypeTuple159; |
| 6173 |
else |
| 6174 |
static assert(0, "argument has no parameters"); |
| 6175 |
} |
| 6176 |
|
| 6177 |
int func159(int i, long j = 7) { return 3; } |
| 6178 |
|
| 6179 |
alias ParameterTypeTuple159!func159 PT; |
| 6180 |
|
| 6181 |
int bar159(PT) { return 4; } |
| 6182 |
|
| 6183 |
pragma(msg, typeof(bar159)); |
| 6184 |
pragma(msg, PT[1]); |
| 6185 |
|
| 6186 |
PT[1] boo159(PT[1..2] a) { return a[0]; } |
| 6187 |
|
| 6188 |
void test159() |
| 6189 |
{ |
| 6190 |
assert(bar159(1) == 4); |
| 6191 |
assert(boo159() == 7); |
| 6192 |
} |
| 6193 |
|
| 6194 |
/***************************************************/ |
| 6195 |
// https://issues.dlang.org/show_bug.cgi?id=8283 |
| 6196 |
|
| 6197 |
struct Foo8283 { |
| 6198 |
this(long) { } |
| 6199 |
} |
| 6200 |
|
| 6201 |
struct FooContainer { |
| 6202 |
Foo8283 value; |
| 6203 |
} |
| 6204 |
|
| 6205 |
auto get8283() { |
| 6206 |
union Buf { FooContainer result; } |
| 6207 |
Buf buf = {}; |
| 6208 |
return buf.result; |
| 6209 |
} |
| 6210 |
|
| 6211 |
void test8283() { |
| 6212 |
auto a = get8283(); |
| 6213 |
} |
| 6214 |
|
| 6215 |
|
| 6216 |
/***************************************************/ |
| 6217 |
// https://issues.dlang.org/show_bug.cgi?id=8395 |
| 6218 |
|
| 6219 |
struct S8395 |
| 6220 |
{ |
| 6221 |
int v; |
| 6222 |
this(T : long)(T x) { v = x * 2; } |
| 6223 |
} |
| 6224 |
void test8395() |
| 6225 |
{ |
| 6226 |
S8395 ms = 6; |
| 6227 |
assert(ms.v == 12); |
| 6228 |
const S8395 cs = 7; |
| 6229 |
assert(cs.v == 14); |
| 6230 |
} |
| 6231 |
|
| 6232 |
/***************************************************/ |
| 6233 |
// https://issues.dlang.org/show_bug.cgi?id=5749 |
| 6234 |
|
| 6235 |
void test5749() |
| 6236 |
{ |
| 6237 |
static struct A |
| 6238 |
{ |
| 6239 |
A foo(int x, int i) |
| 6240 |
{ |
| 6241 |
//printf("this = %p, %d: i=%d\n", &this, x, i); |
| 6242 |
assert(i == x); |
| 6243 |
return this; |
| 6244 |
} |
| 6245 |
A bar(int x, ref int i) |
| 6246 |
{ |
| 6247 |
//printf("this = %p, %d: i=%d\n", &this, x, i); |
| 6248 |
assert(i == x); |
| 6249 |
return this; |
| 6250 |
} |
| 6251 |
} |
| 6252 |
|
| 6253 |
static int inc1(ref int i) { return ++i; } |
| 6254 |
static ref int inc2(ref int i) { return ++i; } |
| 6255 |
|
| 6256 |
int i; |
| 6257 |
A a; |
| 6258 |
//printf("&a = %p\n", &a); |
| 6259 |
|
| 6260 |
i = 0; a.foo(1, ++i).foo(2, ++i); // OK <-- 2 1 |
| 6261 |
i = 0; a.bar(1, ++i).bar(2, ++i); // OK <-- 2 2 |
| 6262 |
i = 0; a.foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1 |
| 6263 |
i = 0; a.bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2 |
| 6264 |
//printf("\n"); |
| 6265 |
|
| 6266 |
A getVal() { static A a; return a; } |
| 6267 |
i = 0; getVal().foo(1, ++i).foo(2, ++i); // OK <-- 2 1 |
| 6268 |
i = 0; getVal().bar(1, ++i).bar(2, ++i); // OK <-- 2 2 |
| 6269 |
i = 0; getVal().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1 |
| 6270 |
i = 0; getVal().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2 |
| 6271 |
//printf("\n"); |
| 6272 |
|
| 6273 |
ref A getRef() { static A a; return a; } |
| 6274 |
i = 0; getRef().foo(1, ++i).foo(2, ++i); // OK <-- 2 1 |
| 6275 |
i = 0; getRef().bar(1, ++i).bar(2, ++i); // OK <-- 2 2 |
| 6276 |
i = 0; getRef().foo(1, inc1(i)).foo(2, inc1(i)); // OK <-- 2 1 |
| 6277 |
i = 0; getRef().bar(1, inc2(i)).bar(2, inc2(i)); // OK <-- 2 2 |
| 6278 |
} |
| 6279 |
|
| 6280 |
/***************************************************/ |
| 6281 |
// https://issues.dlang.org/show_bug.cgi?id=8396 |
| 6282 |
|
| 6283 |
void test8396() |
| 6284 |
{ |
| 6285 |
static int g; |
| 6286 |
|
| 6287 |
static extern(C) int bar(int a, int b) |
| 6288 |
{ |
| 6289 |
//printf("a = %d, b = %d\n", a, b); |
| 6290 |
assert(b - a == 1); |
| 6291 |
return ++g; |
| 6292 |
} |
| 6293 |
static auto getFunc(int n) |
| 6294 |
{ |
| 6295 |
assert(++g == n); |
| 6296 |
return &bar; |
| 6297 |
} |
| 6298 |
|
| 6299 |
static struct Tuple { int _a, _b; } |
| 6300 |
static Tuple foo(int n) |
| 6301 |
{ |
| 6302 |
assert(++g == n); |
| 6303 |
return Tuple(1, 2); |
| 6304 |
} |
| 6305 |
|
| 6306 |
g = 0; |
| 6307 |
assert(bar(foo(1).tupleof) == 2); |
| 6308 |
|
| 6309 |
g = 0; |
| 6310 |
assert(getFunc(1)(foo(2).tupleof) == 3); |
| 6311 |
} |
| 6312 |
|
| 6313 |
/***************************************************/ |
| 6314 |
|
| 6315 |
enum E160 : ubyte { jan = 1 } |
| 6316 |
|
| 6317 |
struct D160 |
| 6318 |
{ |
| 6319 |
short _year = 1; |
| 6320 |
E160 _month = E160.jan; |
| 6321 |
ubyte _day = 1; |
| 6322 |
|
| 6323 |
this(int year, int month, int day) pure |
| 6324 |
{ |
| 6325 |
_year = cast(short)year; |
| 6326 |
_month = cast(E160)month; |
| 6327 |
_day = cast(ubyte)day; |
| 6328 |
} |
| 6329 |
} |
| 6330 |
|
| 6331 |
struct T160 |
| 6332 |
{ |
| 6333 |
ubyte _hour; |
| 6334 |
ubyte _minute; |
| 6335 |
ubyte _second; |
| 6336 |
|
| 6337 |
this(int hour, int minute, int second = 0) pure |
| 6338 |
{ |
| 6339 |
_hour = cast(ubyte)hour; |
| 6340 |
_minute = cast(ubyte)minute; |
| 6341 |
_second = cast(ubyte)second; |
| 6342 |
} |
| 6343 |
} |
| 6344 |
|
| 6345 |
struct DT160 |
| 6346 |
{ |
| 6347 |
D160 _date; |
| 6348 |
T160 _tod; |
| 6349 |
|
| 6350 |
this(int year, int month, int day, |
| 6351 |
int hour = 0, int minute = 0, int second = 0) pure |
| 6352 |
{ |
| 6353 |
_date = D160(year, month, day); |
| 6354 |
_tod = T160(hour, minute, second); |
| 6355 |
} |
| 6356 |
} |
| 6357 |
|
| 6358 |
void foo160(DT160 dateTime) |
| 6359 |
{ |
| 6360 |
printf("test7 year %d, day %d\n", dateTime._date._year, dateTime._date._day); |
| 6361 |
assert(dateTime._date._year == 1999); |
| 6362 |
assert(dateTime._date._day == 6); |
| 6363 |
} |
| 6364 |
|
| 6365 |
void test160() |
| 6366 |
{ |
| 6367 |
auto dateTime = DT160(1999, 7, 6, 12, 30, 33); |
| 6368 |
printf("test5 year %d, day %d\n", dateTime._date._year, dateTime._date._day); |
| 6369 |
assert(dateTime._date._year == 1999); |
| 6370 |
assert(dateTime._date._day == 6); |
| 6371 |
foo160(DT160(1999, 7, 6, 12, 30, 33)); |
| 6372 |
} |
| 6373 |
|
| 6374 |
/***************************************************/ |
| 6375 |
// https://issues.dlang.org/show_bug.cgi?id=8437 |
| 6376 |
|
| 6377 |
class Cgi8437 |
| 6378 |
{ |
| 6379 |
struct PostParserState { |
| 6380 |
UploadedFile piece; |
| 6381 |
} |
| 6382 |
|
| 6383 |
static struct UploadedFile { |
| 6384 |
string contentFilename; |
| 6385 |
} |
| 6386 |
} |
| 6387 |
|
| 6388 |
/***************************************************/ |
| 6389 |
// https://issues.dlang.org/show_bug.cgi?id=8665 |
| 6390 |
|
| 6391 |
auto foo8665a(bool val) |
| 6392 |
{ |
| 6393 |
if (val) |
| 6394 |
return 42; |
| 6395 |
else |
| 6396 |
return 1.5; |
| 6397 |
} |
| 6398 |
auto foo8665b(bool val) |
| 6399 |
{ |
| 6400 |
if (!val) |
| 6401 |
return 1.5; |
| 6402 |
else |
| 6403 |
return 42; |
| 6404 |
} |
| 6405 |
|
| 6406 |
void test8665() |
| 6407 |
{ |
| 6408 |
static assert(is(typeof(foo8665a(true)) == double)); |
| 6409 |
static assert(is(typeof(foo8665b(false)) == double)); |
| 6410 |
assert(foo8665a(true) == 42); // assertion failure |
| 6411 |
assert(foo8665b(true) == 42); // assertion failure |
| 6412 |
assert(foo8665a(false) == 1.5); |
| 6413 |
assert(foo8665b(false) == 1.5); |
| 6414 |
|
| 6415 |
static assert(foo8665a(true) == 42); |
| 6416 |
static assert(foo8665b(true) == 42); |
| 6417 |
static assert(foo8665a(false) == 1.5); |
| 6418 |
static assert(foo8665b(false) == 1.5); |
| 6419 |
} |
| 6420 |
|
| 6421 |
/***************************************************/ |
| 6422 |
|
| 6423 |
int foo8108(int, int); |
| 6424 |
|
| 6425 |
int foo8108(int a, int b) |
| 6426 |
{ |
| 6427 |
return a + b; |
| 6428 |
} |
| 6429 |
|
| 6430 |
void test8108() |
| 6431 |
{ |
| 6432 |
foo8108(1,2); |
| 6433 |
} |
| 6434 |
|
| 6435 |
/***************************************************/ |
| 6436 |
// https://issues.dlang.org/show_bug.cgi?id=8360 |
| 6437 |
|
| 6438 |
struct Foo8360 |
| 6439 |
{ |
| 6440 |
int value = 0; |
| 6441 |
int check = 1337; |
| 6442 |
|
| 6443 |
this(int value) |
| 6444 |
{ |
| 6445 |
assert(0); |
| 6446 |
this.value = value; |
| 6447 |
} |
| 6448 |
|
| 6449 |
~this() |
| 6450 |
{ |
| 6451 |
assert(0); |
| 6452 |
assert(check == 1337); |
| 6453 |
} |
| 6454 |
|
| 6455 |
string str() |
| 6456 |
{ |
| 6457 |
assert(0); |
| 6458 |
return "Foo"; |
| 6459 |
} |
| 6460 |
} |
| 6461 |
|
| 6462 |
Foo8360 makeFoo8360() |
| 6463 |
{ |
| 6464 |
assert(0); |
| 6465 |
return Foo8360(2); |
| 6466 |
} |
| 6467 |
|
| 6468 |
void test8360() |
| 6469 |
{ |
| 6470 |
size_t length = 0; |
| 6471 |
|
| 6472 |
// The message part 'makeFoo().str()' should not be evaluated at all. |
| 6473 |
assert(length < 5, makeFoo8360().str()); |
| 6474 |
} |
| 6475 |
|
| 6476 |
/***************************************************/ |
| 6477 |
// https://issues.dlang.org/show_bug.cgi?id=8361 |
| 6478 |
|
| 6479 |
struct Foo8361 |
| 6480 |
{ |
| 6481 |
string bar = "hello"; |
| 6482 |
~this() {} |
| 6483 |
} |
| 6484 |
|
| 6485 |
void test8361() |
| 6486 |
{ |
| 6487 |
assert(true, Foo8361().bar); |
| 6488 |
} |
| 6489 |
|
| 6490 |
/***************************************************/ |
| 6491 |
// https://issues.dlang.org/show_bug.cgi?id=6141 |
| 6492 |
// https://issues.dlang.org/show_bug.cgi?id=8526 |
| 6493 |
|
| 6494 |
void test6141() |
| 6495 |
{ |
| 6496 |
static void takeADelegate(void delegate()) {} |
| 6497 |
auto items = new int[1]; |
| 6498 |
items[0] = 17; |
| 6499 |
foreach (ref item; items) |
| 6500 |
{ |
| 6501 |
// both asserts fail |
| 6502 |
assert(item == 17); |
| 6503 |
assert(&item == items.ptr); |
| 6504 |
|
| 6505 |
takeADelegate({ auto x = &item; }); |
| 6506 |
} |
| 6507 |
|
| 6508 |
foreach(ref val; [3]) |
| 6509 |
{ |
| 6510 |
auto dg = { int j = val; }; |
| 6511 |
assert(&val != null); // Assertion failure |
| 6512 |
assert(val == 3); |
| 6513 |
} |
| 6514 |
|
| 6515 |
static void f(lazy int) {} |
| 6516 |
int i = 0; |
| 6517 |
auto dg = { int j = i; }; |
| 6518 |
foreach(ref val; [3]) |
| 6519 |
{ |
| 6520 |
f(val); |
| 6521 |
assert(&val != null); // Assertion failure |
| 6522 |
assert(val == 3); |
| 6523 |
} |
| 6524 |
} |
| 6525 |
|
| 6526 |
void test8526() |
| 6527 |
{ |
| 6528 |
static void call(void delegate() dg) { dg(); } |
| 6529 |
|
| 6530 |
foreach (i, j; [0]) |
| 6531 |
{ |
| 6532 |
call({ |
| 6533 |
assert(i == 0); // fails, i is corrupted |
| 6534 |
}); |
| 6535 |
} |
| 6536 |
|
| 6537 |
foreach (n; 0..1) |
| 6538 |
{ |
| 6539 |
call({ |
| 6540 |
assert(n == 0); // fails, n is corrupted |
| 6541 |
}); |
| 6542 |
} |
| 6543 |
} |
| 6544 |
|
| 6545 |
/***************************************************/ |
| 6546 |
|
| 6547 |
template ParameterTuple(alias func) |
| 6548 |
{ |
| 6549 |
static if(is(typeof(func) P == __parameters)) |
| 6550 |
alias P ParameterTuple; |
| 6551 |
else |
| 6552 |
static assert(0); |
| 6553 |
} |
| 6554 |
|
| 6555 |
int foo161(ref float y); |
| 6556 |
|
| 6557 |
void test161() |
| 6558 |
{ |
| 6559 |
alias PT = ParameterTuple!foo161; |
| 6560 |
auto x = __traits(identifier, PT); |
| 6561 |
assert(x == "y"); |
| 6562 |
} |
| 6563 |
|
| 6564 |
/***************************************************/ |
| 6565 |
// https://issues.dlang.org/show_bug.cgi?id=7175 |
| 6566 |
|
| 6567 |
void test7175() |
| 6568 |
{ |
| 6569 |
struct S { ubyte[0] arr; } |
| 6570 |
S s; |
| 6571 |
assert(s.arr.ptr !is null); |
| 6572 |
assert(cast(void*)s.arr.ptr is cast(void*)&s); |
| 6573 |
} |
| 6574 |
|
| 6575 |
/***************************************************/ |
| 6576 |
// https://issues.dlang.org/show_bug.cgi?id=8819 |
| 6577 |
|
| 6578 |
void test8819() |
| 6579 |
{ |
| 6580 |
void[1] sa1 = (void[1]).init; |
| 6581 |
assert((cast(ubyte*)sa1.ptr)[0] == 0); |
| 6582 |
|
| 6583 |
void[4] sa4 = [cast(ubyte)1,cast(ubyte)2,cast(ubyte)3,cast(ubyte)4]; |
| 6584 |
assert((cast(ubyte*)sa4.ptr)[0] == 1); |
| 6585 |
assert((cast(ubyte*)sa4.ptr)[1] == 2); |
| 6586 |
assert((cast(ubyte*)sa4.ptr)[2] == 3); |
| 6587 |
assert((cast(ubyte*)sa4.ptr)[3] == 4); |
| 6588 |
|
| 6589 |
auto sa22 = (void[2][2]).init; |
| 6590 |
static assert(sa22.sizeof == ubyte.sizeof * 2 * 2); |
| 6591 |
ubyte[4]* psa22 = cast(ubyte[4]*)sa22.ptr; |
| 6592 |
assert((*psa22)[0] == 0); |
| 6593 |
assert((*psa22)[1] == 0); |
| 6594 |
assert((*psa22)[2] == 0); |
| 6595 |
assert((*psa22)[3] == 0); |
| 6596 |
} |
| 6597 |
|
| 6598 |
/***************************************************/ |
| 6599 |
// https://issues.dlang.org/show_bug.cgi?id=8897 |
| 6600 |
|
| 6601 |
class C8897 |
| 6602 |
{ |
| 6603 |
static mixin M8897!(int); |
| 6604 |
static class causesAnError {} |
| 6605 |
} |
| 6606 |
|
| 6607 |
template M8897 ( E ) { } |
| 6608 |
|
| 6609 |
/***************************************************/ |
| 6610 |
// https://issues.dlang.org/show_bug.cgi?id=8917 |
| 6611 |
|
| 6612 |
void test8917() |
| 6613 |
{ |
| 6614 |
int[3] a; |
| 6615 |
int[3] a2; |
| 6616 |
int[3] b = a[] + a2[]; |
| 6617 |
} |
| 6618 |
|
| 6619 |
/***************************************************/ |
| 6620 |
// https://issues.dlang.org/show_bug.cgi?id=8945 |
| 6621 |
|
| 6622 |
struct S8945 // or `class`, or `union` |
| 6623 |
{ |
| 6624 |
struct S0(T) { int i; } |
| 6625 |
struct S1(T) { this(int){} } |
| 6626 |
} |
| 6627 |
|
| 6628 |
void test8945() |
| 6629 |
{ |
| 6630 |
auto cs0a = const S8945.S0!int(); // ok |
| 6631 |
auto cs0b = const S8945.S0!int(1); // ok |
| 6632 |
auto cs1 = const S8945.S1!int(1); // ok |
| 6633 |
|
| 6634 |
auto s0a = S8945.S0!int(); // Error: struct S0 does not overload () |
| 6635 |
auto s0b = S8945.S0!int(1); // Error: struct S0 does not overload () |
| 6636 |
auto s1 = S8945.S1!int(1); // Error: struct S1 does not overload () |
| 6637 |
} |
| 6638 |
|
| 6639 |
/***************************************************/ |
| 6640 |
|
| 6641 |
struct S162 |
| 6642 |
{ |
| 6643 |
static int generateMethodStubs( Class )() |
| 6644 |
{ |
| 6645 |
int text; |
| 6646 |
|
| 6647 |
foreach( m; __traits( allMembers, Class ) ) |
| 6648 |
{ |
| 6649 |
static if( is( typeof( mixin( m ) ) ) && is( typeof( mixin( m ) ) == function ) ) |
| 6650 |
{ |
| 6651 |
pragma(msg, __traits( getOverloads, Class, m )); |
| 6652 |
} |
| 6653 |
} |
| 6654 |
|
| 6655 |
return text; |
| 6656 |
} |
| 6657 |
|
| 6658 |
enum int ttt = generateMethodStubs!( S162 )(); |
| 6659 |
|
| 6660 |
float height(); |
| 6661 |
int get( int ); |
| 6662 |
int get( long ); |
| 6663 |
void clear(); |
| 6664 |
|
| 6665 |
void draw( int ); |
| 6666 |
void draw( long ); |
| 6667 |
} |
| 6668 |
|
| 6669 |
/***************************************************/ |
| 6670 |
|
| 6671 |
void test163() { |
| 6672 |
static class C { int x; int y; } |
| 6673 |
|
| 6674 |
immutable C c = new C(); |
| 6675 |
shared C c2 = new C(); |
| 6676 |
shared const C c3 = new C(); |
| 6677 |
|
| 6678 |
class D { int x; int y; } |
| 6679 |
immutable D d; |
| 6680 |
assert(!__traits(compiles, d = new D())); |
| 6681 |
|
| 6682 |
static struct S { int x; int y; } |
| 6683 |
|
| 6684 |
immutable S* s = new S(); |
| 6685 |
shared S* s2 = new S(); |
| 6686 |
shared const S* s3 = new S(); |
| 6687 |
|
| 6688 |
shared S* s4; |
| 6689 |
assert(__traits(compiles, s4 = new immutable(S)())); |
| 6690 |
|
| 6691 |
struct T { int x; int y; } |
| 6692 |
immutable T* t; |
| 6693 |
assert(!__traits(compiles, t = new T())); |
| 6694 |
|
| 6695 |
immutable int* pi = new int(); |
| 6696 |
immutable void* pv = new int(); |
| 6697 |
|
| 6698 |
immutable int[] ai = new int[1]; |
| 6699 |
immutable void[] av = new int[2]; |
| 6700 |
} |
| 6701 |
|
| 6702 |
/***************************************************/ |
| 6703 |
struct S9000 |
| 6704 |
{ ubyte i = ubyte.max; } |
| 6705 |
|
| 6706 |
enum E9000 = S9000.init; |
| 6707 |
|
| 6708 |
/***************************************************/ |
| 6709 |
|
| 6710 |
mixin template DefineCoreType(string type) |
| 6711 |
{ |
| 6712 |
struct Faulty |
| 6713 |
{ |
| 6714 |
static int x; |
| 6715 |
|
| 6716 |
static void instance() |
| 6717 |
{ |
| 6718 |
x = 3; |
| 6719 |
} |
| 6720 |
|
| 6721 |
X164!() xxx; |
| 6722 |
} |
| 6723 |
} |
| 6724 |
|
| 6725 |
mixin DefineCoreType!(""); |
| 6726 |
|
| 6727 |
|
| 6728 |
mixin template A164() |
| 6729 |
{ |
| 6730 |
static this() |
| 6731 |
{ |
| 6732 |
} |
| 6733 |
} |
| 6734 |
|
| 6735 |
struct X164() |
| 6736 |
{ |
| 6737 |
mixin A164!(); |
| 6738 |
} |
| 6739 |
|
| 6740 |
|
| 6741 |
/***************************************************/ |
| 6742 |
// https://issues.dlang.org/show_bug.cgi?id=9428 |
| 6743 |
|
| 6744 |
void test9428() |
| 6745 |
{ |
| 6746 |
int[2][] items = [[1, 2]]; |
| 6747 |
int[2] x = [3, 4]; |
| 6748 |
|
| 6749 |
auto r1 = items ~ [x]; |
| 6750 |
assert(r1.length == 2); |
| 6751 |
assert(r1[0][0] == 1); |
| 6752 |
assert(r1[0][1] == 2); |
| 6753 |
assert(r1[1][0] == 3); |
| 6754 |
assert(r1[1][1] == 4); |
| 6755 |
|
| 6756 |
auto r2 = items ~ x; |
| 6757 |
assert(r2.length == 2); |
| 6758 |
assert(r2[0][0] == 1); |
| 6759 |
assert(r2[0][1] == 2); |
| 6760 |
assert(r2[1][0] == 3); |
| 6761 |
assert(r2[1][1] == 4); |
| 6762 |
|
| 6763 |
auto r3 = [x] ~ items; |
| 6764 |
assert(r3.length == 2); |
| 6765 |
assert(r3[0][0] == 3); |
| 6766 |
assert(r3[0][1] == 4); |
| 6767 |
assert(r3[1][0] == 1); |
| 6768 |
assert(r3[1][1] == 2); |
| 6769 |
|
| 6770 |
auto r4 = x ~ items; |
| 6771 |
assert(r4.length == 2); |
| 6772 |
assert(r4[0][0] == 3); |
| 6773 |
assert(r4[0][1] == 4); |
| 6774 |
assert(r4[1][0] == 1); |
| 6775 |
assert(r4[1][1] == 2); |
| 6776 |
} |
| 6777 |
|
| 6778 |
/***************************************************/ |
| 6779 |
// https://issues.dlang.org/show_bug.cgi?id=9477 |
| 6780 |
|
| 6781 |
template Tuple9477(T...) { alias T Tuple9477; } |
| 6782 |
template Select9477(bool b, T, U) { static if (b) alias T Select9477; else alias U Select9477; } |
| 6783 |
|
| 6784 |
void test9477() |
| 6785 |
{ |
| 6786 |
static bool isEq (T1, T2)(T1 s1, T2 s2) { return s1 == s2; } |
| 6787 |
static bool isNeq(T1, T2)(T1 s1, T2 s2) { return s1 != s2; } |
| 6788 |
|
| 6789 |
// Must be outside the loop due to https://issues.dlang.org/show_bug.cgi?id=9748 |
| 6790 |
int order; |
| 6791 |
// Must be outside the loop due to https://issues.dlang.org/show_bug.cgi?id=9756 |
| 6792 |
auto checkOrder(bool dyn, uint expected)() |
| 6793 |
{ |
| 6794 |
assert(order==expected); |
| 6795 |
order++; |
| 6796 |
// Use temporary ("v") to work around https://issues.dlang.org/show_bug.cgi?id=9402 |
| 6797 |
auto v = cast(Select9477!(dyn, string, char[1]))"a"; |
| 6798 |
return v; |
| 6799 |
} |
| 6800 |
|
| 6801 |
foreach (b1; Tuple9477!(false, true)) |
| 6802 |
foreach (b2; Tuple9477!(false, true)) |
| 6803 |
{ |
| 6804 |
version (D_PIC) {} else version (D_PIE) {} else // Work around https://issues.dlang.org/show_bug.cgi?id=9754 |
| 6805 |
{ |
| 6806 |
assert( isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" )); |
| 6807 |
assert(!isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[0]))"" )); |
| 6808 |
|
| 6809 |
assert(!isEq (cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" )); |
| 6810 |
assert( isNeq(cast(Select9477!(b1, string, char[0]))"" , cast(Select9477!(b2, string, char[1]))"a" )); |
| 6811 |
} |
| 6812 |
|
| 6813 |
assert( isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" )); |
| 6814 |
assert(!isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"a" )); |
| 6815 |
|
| 6816 |
assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" )); |
| 6817 |
assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[1]))"b" )); |
| 6818 |
|
| 6819 |
assert(!isEq (cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa")); |
| 6820 |
assert( isNeq(cast(Select9477!(b1, string, char[1]))"a", cast(Select9477!(b2, string, char[2]))"aa")); |
| 6821 |
|
| 6822 |
// Note: order of evaluation was not followed before this patch |
| 6823 |
// (thus, the test below will fail without the patch). |
| 6824 |
// Although the specification mentions that as implementation-defined behavior, |
| 6825 |
// I understand that this isn't by design, but rather an inconvenient aspect of DMD |
| 6826 |
// that has been moved to the specification. |
| 6827 |
order = 0; |
| 6828 |
bool result = checkOrder!(b1, 0)() == checkOrder!(b2, 1)(); |
| 6829 |
assert(result); |
| 6830 |
assert(order == 2); |
| 6831 |
} |
| 6832 |
|
| 6833 |
// need largest natural alignment to avoid unaligned access on |
| 6834 |
// some architectures, double in this case. |
| 6835 |
align(8) ubyte[64] a1, a2; |
| 6836 |
foreach (T; Tuple9477!(void, ubyte, ushort, uint, ulong, char, wchar, dchar, float, double)) |
| 6837 |
{ |
| 6838 |
auto s1 = cast(T[])(a1[]); |
| 6839 |
auto s2 = cast(T[])(a2[]); |
| 6840 |
assert(s1 == s2); |
| 6841 |
a2[$-1]++; |
| 6842 |
assert(s1 != s2); |
| 6843 |
assert(s1[0..$-1]==s2[0..$-1]); |
| 6844 |
a2[$-1]--; |
| 6845 |
} |
| 6846 |
} |
| 6847 |
|
| 6848 |
/***************************************************/ |
| 6849 |
// https://issues.dlang.org/show_bug.cgi?id=9504 |
| 6850 |
|
| 6851 |
struct Bar9504 |
| 6852 |
{ |
| 6853 |
template Abc(T) |
| 6854 |
{ |
| 6855 |
T y; |
| 6856 |
} |
| 6857 |
|
| 6858 |
enum size_t num = 123; |
| 6859 |
|
| 6860 |
class Def {} |
| 6861 |
} |
| 6862 |
|
| 6863 |
template GetSym9504(alias sym) { static assert(__traits(isSame, sym, Bar9504.Abc)); } |
| 6864 |
template GetExp9504(size_t n) { static assert(n == Bar9504.num); } |
| 6865 |
template GetTyp9504(T) { static assert(is(T == Bar9504.Def)); } |
| 6866 |
|
| 6867 |
alias GetSym9504!(typeof(Bar9504.init).Abc) X9504; // NG |
| 6868 |
alias GetExp9504!(typeof(Bar9504.init).num) Y9504; // NG |
| 6869 |
alias GetTyp9504!(typeof(Bar9504.init).Def) Z9504; |
| 6870 |
|
| 6871 |
Bar9504 test9504() |
| 6872 |
{ |
| 6873 |
alias GetSym9504!(typeof(return).Abc) V9504; // NG |
| 6874 |
alias GetExp9504!(typeof(return).num) W9504; // NG |
| 6875 |
alias GetTyp9504!(typeof(return).Def) X9504; |
| 6876 |
return Bar9504(); |
| 6877 |
} |
| 6878 |
|
| 6879 |
/***************************************************/ |
| 6880 |
// https://issues.dlang.org/show_bug.cgi?id=9538 |
| 6881 |
|
| 6882 |
void test9538() |
| 6883 |
{ |
| 6884 |
void*[1] x; |
| 6885 |
auto ti = typeid(x.ptr); |
| 6886 |
} |
| 6887 |
|
| 6888 |
/***************************************************/ |
| 6889 |
// https://issues.dlang.org/show_bug.cgi?id=9539 |
| 6890 |
|
| 6891 |
void test9539() |
| 6892 |
{ |
| 6893 |
void f(int** ptr) |
| 6894 |
{ |
| 6895 |
assert(**ptr == 10); |
| 6896 |
} |
| 6897 |
int* p = new int; |
| 6898 |
*p = 10; |
| 6899 |
int*[1] x = [p]; |
| 6900 |
f(&x[0]); |
| 6901 |
|
| 6902 |
int*[] arr = [null]; |
| 6903 |
static assert(!__traits(compiles, p = arr)); // bad! |
| 6904 |
} |
| 6905 |
|
| 6906 |
/***************************************************/ |
| 6907 |
// https://issues.dlang.org/show_bug.cgi?id=9700 |
| 6908 |
|
| 6909 |
mixin template Proxy9700(alias a) |
| 6910 |
{ |
| 6911 |
auto ref opOpAssign(string op, V)(V v) { return a += v; } // NG |
| 6912 |
//auto ref opOpAssign(string op, V)(V v) { a += v; } // OK |
| 6913 |
} |
| 6914 |
struct MyInt9700 |
| 6915 |
{ |
| 6916 |
int value; |
| 6917 |
invariant() { assert(value >= 0); } |
| 6918 |
mixin Proxy9700!value; |
| 6919 |
} |
| 6920 |
void test9700() |
| 6921 |
{ |
| 6922 |
MyInt9700 a = { 2 }; |
| 6923 |
a *= 3; // object.Error: Access Violation |
| 6924 |
} |
| 6925 |
|
| 6926 |
/***************************************************/ |
| 6927 |
// https://issues.dlang.org/show_bug.cgi?id=9834 |
| 6928 |
|
| 6929 |
struct Event9834 |
| 6930 |
{ |
| 6931 |
void delegate() dg; |
| 6932 |
void set(void delegate() h) pure { dg = h; } // AV occurs |
| 6933 |
void call() { dg(); } |
| 6934 |
} |
| 6935 |
void test9834() |
| 6936 |
{ |
| 6937 |
Event9834 ev; |
| 6938 |
auto a = new class |
| 6939 |
{ |
| 6940 |
Object o; |
| 6941 |
this() |
| 6942 |
{ |
| 6943 |
o = new Object; |
| 6944 |
ev.set((){ o.toString(); }); |
| 6945 |
} |
| 6946 |
}; |
| 6947 |
ev.call(); |
| 6948 |
} |
| 6949 |
|
| 6950 |
/***************************************************/ |
| 6951 |
// https://issues.dlang.org/show_bug.cgi?id=9859 |
| 6952 |
|
| 6953 |
void test9859(inout int[] arr) |
| 6954 |
{ |
| 6955 |
auto dg1 = { foreach (i, e; arr) { } }; |
| 6956 |
dg1(); |
| 6957 |
|
| 6958 |
void foo() { auto v = arr; auto w = arr[0]; } |
| 6959 |
void bar(inout int i) { auto v = arr[i]; } |
| 6960 |
|
| 6961 |
auto dg2 = |
| 6962 |
{ |
| 6963 |
auto dg = |
| 6964 |
{ |
| 6965 |
void foo(T)() |
| 6966 |
{ |
| 6967 |
auto dg = |
| 6968 |
{ |
| 6969 |
auto dg = |
| 6970 |
{ |
| 6971 |
auto v = arr; |
| 6972 |
}; |
| 6973 |
}; |
| 6974 |
} |
| 6975 |
foo!int; |
| 6976 |
}; |
| 6977 |
}; |
| 6978 |
|
| 6979 |
void qux(T)() |
| 6980 |
{ |
| 6981 |
auto v = arr; |
| 6982 |
auto dg1 = { auto v = arr; }; |
| 6983 |
auto dg2 = |
| 6984 |
{ |
| 6985 |
auto dg = |
| 6986 |
{ |
| 6987 |
auto v = arr; |
| 6988 |
}; |
| 6989 |
}; |
| 6990 |
} |
| 6991 |
qux!int; |
| 6992 |
} |
| 6993 |
|
| 6994 |
/***************************************************/ |
| 6995 |
// https://issues.dlang.org/show_bug.cgi?id=9912 |
| 6996 |
|
| 6997 |
template TypeTuple9912(Stuff...) |
| 6998 |
{ |
| 6999 |
alias Stuff TypeTuple9912; |
| 7000 |
} |
| 7001 |
|
| 7002 |
struct S9912 |
| 7003 |
{ |
| 7004 |
int i; |
| 7005 |
alias TypeTuple9912!i t; |
| 7006 |
|
| 7007 |
void testA() { |
| 7008 |
auto x = t; |
| 7009 |
} |
| 7010 |
|
| 7011 |
void testB() { |
| 7012 |
auto x = t; |
| 7013 |
} |
| 7014 |
} |
| 7015 |
|
| 7016 |
/***************************************************/ |
| 7017 |
// https://issues.dlang.org/show_bug.cgi?id=9883 |
| 7018 |
|
| 7019 |
struct S9883 |
| 7020 |
{ |
| 7021 |
@property size_t p9883(T)() { return 0; } |
| 7022 |
} |
| 7023 |
|
| 7024 |
@property size_t p9883(T)() { return 0; } |
| 7025 |
|
| 7026 |
void test9883() |
| 7027 |
{ |
| 7028 |
S9883 s; |
| 7029 |
auto n1 = p9883!int; // OK |
| 7030 |
auto n2 = s.p9883!int; // OK |
| 7031 |
auto a1 = new int[p9883!int]; // Error: need size of rightmost array, not type p!(int) |
| 7032 |
auto a2 = new int[s.p9883!int]; // Error: no property 'p!(int)' for type 'S' |
| 7033 |
} |
| 7034 |
|
| 7035 |
|
| 7036 |
/***************************************************/ |
| 7037 |
// https://issues.dlang.org/show_bug.cgi?id=10091 |
| 7038 |
|
| 7039 |
struct S10091 |
| 7040 |
{ |
| 7041 |
enum e = "a"; |
| 7042 |
} |
| 7043 |
|
| 7044 |
void test10091() |
| 7045 |
{ |
| 7046 |
auto arr = cast(ubyte[1]) S10091.e; |
| 7047 |
} |
| 7048 |
|
| 7049 |
/***************************************************/ |
| 7050 |
|
| 7051 |
void test12824() |
| 7052 |
{ |
| 7053 |
label: |
| 7054 |
static if (0) |
| 7055 |
{ |
| 7056 |
} |
| 7057 |
} |
| 7058 |
|
| 7059 |
/***************************************************/ |
| 7060 |
// https://issues.dlang.org/show_bug.cgi?id=9130 |
| 7061 |
|
| 7062 |
class S9130 { void bar() { } } |
| 7063 |
|
| 7064 |
import core.stdc.stdio : printf; |
| 7065 |
|
| 7066 |
struct Function |
| 7067 |
{ |
| 7068 |
int[] ai = [1,2,3]; |
| 7069 |
} |
| 7070 |
|
| 7071 |
@property void meta(alias m)() |
| 7072 |
{ |
| 7073 |
static Function md; |
| 7074 |
printf("length = %zd\n", md.ai.length); |
| 7075 |
printf("ptr = %p\n", md.ai.ptr); |
| 7076 |
md.ai[0] = 0; |
| 7077 |
} |
| 7078 |
|
| 7079 |
void test9130() |
| 7080 |
{ |
| 7081 |
meta!(__traits(getOverloads, S9130, "bar")[0]); |
| 7082 |
meta!(S9130.bar); |
| 7083 |
} |
| 7084 |
|
| 7085 |
/***************************************************/ |
| 7086 |
// https://issues.dlang.org/show_bug.cgi?id=10390 |
| 7087 |
|
| 7088 |
class C10390 { this() { this.c = this; } C10390 c; } |
| 7089 |
const c10390 = new C10390(); |
| 7090 |
pragma(msg, c10390); |
| 7091 |
|
| 7092 |
/***************************************************/ |
| 7093 |
// https://issues.dlang.org/show_bug.cgi?id=10542 |
| 7094 |
|
| 7095 |
class B10542 |
| 7096 |
{ |
| 7097 |
this() nothrow pure @safe { } |
| 7098 |
} |
| 7099 |
|
| 7100 |
class D10542 : B10542 |
| 7101 |
{ |
| 7102 |
} |
| 7103 |
|
| 7104 |
void test10542() nothrow pure @safe |
| 7105 |
{ |
| 7106 |
new D10542; |
| 7107 |
} |
| 7108 |
|
| 7109 |
/***************************************************/ |
| 7110 |
// https://issues.dlang.org/show_bug.cgi?id=10539 |
| 7111 |
|
| 7112 |
void test10539() |
| 7113 |
{ |
| 7114 |
int[2][2] a; |
| 7115 |
int* p1 = a.ptr.ptr; // OK <- error |
| 7116 |
int* p2 = (*a.ptr).ptr; // OK |
| 7117 |
assert(p1 is p2); |
| 7118 |
} |
| 7119 |
|
| 7120 |
/***************************************************/ |
| 7121 |
|
| 7122 |
struct TimeOfDay |
| 7123 |
{ |
| 7124 |
ubyte h, m, s; |
| 7125 |
} |
| 7126 |
|
| 7127 |
__gshared byte glob; |
| 7128 |
|
| 7129 |
struct DateTime |
| 7130 |
{ |
| 7131 |
this(ubyte _d, ubyte _m, ubyte _y, TimeOfDay _tod = TimeOfDay.init) |
| 7132 |
{ |
| 7133 |
d = _d; |
| 7134 |
m = _m; |
| 7135 |
y = _y; |
| 7136 |
tod = _tod; |
| 7137 |
} |
| 7138 |
TimeOfDay tod; |
| 7139 |
ubyte d, m, y; |
| 7140 |
} |
| 7141 |
|
| 7142 |
|
| 7143 |
void test10634() |
| 7144 |
{ |
| 7145 |
glob = 123; |
| 7146 |
DateTime date1 = DateTime(0, 0, 0); |
| 7147 |
DateTime date2; |
| 7148 |
assert(date1 == date2); |
| 7149 |
} |
| 7150 |
|
| 7151 |
/***************************************************/ |
| 7152 |
|
| 7153 |
immutable(char)[4] bar7254(int i) |
| 7154 |
{ |
| 7155 |
if (i) |
| 7156 |
{ |
| 7157 |
immutable(char)[4] r; return r; |
| 7158 |
} |
| 7159 |
else |
| 7160 |
return "1234"; |
| 7161 |
} |
| 7162 |
|
| 7163 |
void test7254() |
| 7164 |
{ |
| 7165 |
assert(bar7254(0) == "1234"); |
| 7166 |
} |
| 7167 |
|
| 7168 |
/***************************************************/ |
| 7169 |
|
| 7170 |
struct S11075() { int x = undefined_expr; } |
| 7171 |
|
| 7172 |
class C11075() { int x = undefined_expr; } |
| 7173 |
|
| 7174 |
interface I11075() { enum int x = undefined_expr; } |
| 7175 |
|
| 7176 |
void test11075() |
| 7177 |
{ |
| 7178 |
static assert(!is(typeof(S11075!().x))); |
| 7179 |
static assert(!is(typeof(S11075!().x))); |
| 7180 |
|
| 7181 |
static assert(!is(typeof(C11075!().x))); |
| 7182 |
static assert(!is(typeof(C11075!().x))); |
| 7183 |
|
| 7184 |
static assert(!is(typeof(I11075!().x))); |
| 7185 |
static assert(!is(typeof(I11075!().x))); |
| 7186 |
} |
| 7187 |
|
| 7188 |
/***************************************************/ |
| 7189 |
// https://issues.dlang.org/show_bug.cgi?id=11181 |
| 7190 |
|
| 7191 |
void test11181() |
| 7192 |
{ |
| 7193 |
auto a = ["a", "b"]; |
| 7194 |
|
| 7195 |
static assert(!is(typeof([a, "x"]))); |
| 7196 |
static assert(!is(typeof(true ? a : "x"))); |
| 7197 |
|
| 7198 |
static assert(!is(typeof(true ? a[0 .. $] : "x"))); |
| 7199 |
static assert(!is(typeof([a[0 .. $], "x"]))); |
| 7200 |
} |
| 7201 |
|
| 7202 |
/***************************************************/ |
| 7203 |
// https://issues.dlang.org/show_bug.cgi?id=11317 |
| 7204 |
|
| 7205 |
void test11317() |
| 7206 |
{ |
| 7207 |
auto ref uint fun() |
| 7208 |
{ |
| 7209 |
return 0; |
| 7210 |
} |
| 7211 |
|
| 7212 |
void test(ref uint x) {} |
| 7213 |
static assert(__traits(compiles, test(fun()))); |
| 7214 |
|
| 7215 |
assert(fun() == 0); |
| 7216 |
} |
| 7217 |
|
| 7218 |
/***************************************************/ |
| 7219 |
// https://issues.dlang.org/show_bug.cgi?id=11888 |
| 7220 |
|
| 7221 |
void test11888() |
| 7222 |
{ |
| 7223 |
static long val; |
| 7224 |
|
| 7225 |
static ubyte* foo(size_t* len) |
| 7226 |
{ |
| 7227 |
*len = val.sizeof; |
| 7228 |
return cast(ubyte*)&val; |
| 7229 |
} |
| 7230 |
|
| 7231 |
size_t size; |
| 7232 |
ubyte[] t = foo(&size)[0..size]; |
| 7233 |
assert(t.ptr is cast(void*)&val); |
| 7234 |
assert(t.length == 8); |
| 7235 |
|
| 7236 |
// regression test |
| 7237 |
int[3] sa1 = [1,2,3]; |
| 7238 |
int[1] sa2 = sa1[1..2]; // convert slice to Tsarray |
| 7239 |
assert(sa2.length == 1); |
| 7240 |
assert(sa2[0] == 2); |
| 7241 |
} |
| 7242 |
|
| 7243 |
/***************************************************/ |
| 7244 |
// https://issues.dlang.org/show_bug.cgi?id=12036 |
| 7245 |
|
| 7246 |
template T12036(alias a) |
| 7247 |
{ |
| 7248 |
string value; |
| 7249 |
} |
| 7250 |
|
| 7251 |
struct S12036 |
| 7252 |
{ |
| 7253 |
auto fun() { } |
| 7254 |
mixin T12036!fun; |
| 7255 |
} |
| 7256 |
|
| 7257 |
void test12036() |
| 7258 |
{ |
| 7259 |
S12036 s; |
| 7260 |
assert(s.value == ""); |
| 7261 |
} |
| 7262 |
|
| 7263 |
/***************************************************/ |
| 7264 |
// https://issues.dlang.org/show_bug.cgi?id=12153 |
| 7265 |
|
| 7266 |
void test12153() |
| 7267 |
{ |
| 7268 |
int[1] i, j; |
| 7269 |
bool b = true; |
| 7270 |
(b ? i : j)[] = [4]; |
| 7271 |
assert(i == [4]); |
| 7272 |
|
| 7273 |
// regression test |
| 7274 |
int[1][1] k, l; |
| 7275 |
(b ? k : l)[0..1][0..1] = [4]; |
| 7276 |
assert(k == [[4]]); |
| 7277 |
} |
| 7278 |
|
| 7279 |
/***************************************************/ |
| 7280 |
// https://issues.dlang.org/show_bug.cgi?id=12498 |
| 7281 |
|
| 7282 |
string a12498() |
| 7283 |
{ |
| 7284 |
string b; |
| 7285 |
while (b) { } |
| 7286 |
for (; b; ) { } |
| 7287 |
return ""; |
| 7288 |
} |
| 7289 |
|
| 7290 |
void test12498() |
| 7291 |
{ |
| 7292 |
enum t = a12498(); |
| 7293 |
string x = t; |
| 7294 |
} |
| 7295 |
|
| 7296 |
/***************************************************/ |
| 7297 |
// https://issues.dlang.org/show_bug.cgi?id=12900 |
| 7298 |
|
| 7299 |
struct A12900 |
| 7300 |
{ |
| 7301 |
char[1] b; |
| 7302 |
} |
| 7303 |
|
| 7304 |
void test12900() |
| 7305 |
{ |
| 7306 |
A12900 c; |
| 7307 |
if (*c.b.ptr) |
| 7308 |
return; |
| 7309 |
} |
| 7310 |
|
| 7311 |
/***************************************************/ |
| 7312 |
// https://issues.dlang.org/show_bug.cgi?id=12929 |
| 7313 |
|
| 7314 |
struct Foo12929 |
| 7315 |
{ |
| 7316 |
union { } |
| 7317 |
int var; |
| 7318 |
} |
| 7319 |
|
| 7320 |
struct Bar12929 |
| 7321 |
{ |
| 7322 |
struct { } |
| 7323 |
int var; |
| 7324 |
} |
| 7325 |
|
| 7326 |
/***************************************************/ |
| 7327 |
// https://issues.dlang.org/show_bug.cgi?id=12937 |
| 7328 |
|
| 7329 |
void test12937() |
| 7330 |
{ |
| 7331 |
void[1] sa2 = cast(void[])[cast(ubyte)1]; // ICE! |
| 7332 |
assert((cast(ubyte[])sa2[])[0] == 1); |
| 7333 |
} |
| 7334 |
|
| 7335 |
/***************************************************/ |
| 7336 |
// https://issues.dlang.org/show_bug.cgi?id=13154 |
| 7337 |
|
| 7338 |
void test13154() |
| 7339 |
{ |
| 7340 |
int[3] ints = [2 , 1 , 0 , 1 ][0..3]; |
| 7341 |
float[3] floats0 = [2f , 1f , 0f , 1f ][0..3]; |
| 7342 |
float[3] floats1 = [2.0 , 1.0 , 0.0 , 1.0 ][0..3]; // fails! |
| 7343 |
float[3] floats2 = [2.0f, 1.0f, 0.0f, 1.0f][0..3]; |
| 7344 |
assert(ints == [2, 1, 0]); |
| 7345 |
assert(floats0 == [2, 1, 0]); |
| 7346 |
assert(floats1 == [2, 1, 0]); // fail! |
| 7347 |
assert(floats1 != [0, 0, 0]); // fail! |
| 7348 |
assert(floats2 == [2, 1, 0]); |
| 7349 |
} |
| 7350 |
|
| 7351 |
/***************************************************/ |
| 7352 |
// https://issues.dlang.org/show_bug.cgi?id=13437 |
| 7353 |
|
| 7354 |
ubyte[4] foo13437() { return [1,2,3,4]; } |
| 7355 |
|
| 7356 |
void test13437() |
| 7357 |
{ |
| 7358 |
auto n = cast(ubyte[4])foo13437()[]; // OK <- ICE: e2ir.c 4616 |
| 7359 |
static assert(is(typeof(n) == ubyte[4])); |
| 7360 |
assert(n == [1,2,3,4]); |
| 7361 |
} |
| 7362 |
|
| 7363 |
/***************************************************/ |
| 7364 |
// https://issues.dlang.org/show_bug.cgi?id=13472 |
| 7365 |
|
| 7366 |
class A13472 |
| 7367 |
{ |
| 7368 |
int a; |
| 7369 |
} |
| 7370 |
|
| 7371 |
void test13472() |
| 7372 |
{ |
| 7373 |
A13472[] test; |
| 7374 |
test.length = 4; |
| 7375 |
auto b = test[0..2] ~ null ~ test[2..$]; |
| 7376 |
assert(b.length == 5); |
| 7377 |
} |
| 7378 |
|
| 7379 |
/***************************************************/ |
| 7380 |
// https://issues.dlang.org/show_bug.cgi?id=13476 |
| 7381 |
|
| 7382 |
template ParameterTypeTuple13476(func...) |
| 7383 |
{ |
| 7384 |
static if (is(typeof(*func[0]) P == function)) |
| 7385 |
alias ParameterTypeTuple13476 = P; |
| 7386 |
else |
| 7387 |
static assert(0, "argument has no parameters"); |
| 7388 |
} |
| 7389 |
|
| 7390 |
int flag13476; |
| 7391 |
|
| 7392 |
__gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476; |
| 7393 |
|
| 7394 |
extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args) |
| 7395 |
{ |
| 7396 |
++flag13476; |
| 7397 |
extern(C) void function(int) nothrow impl = (i) { }; |
| 7398 |
return (func = impl)(args); |
| 7399 |
} |
| 7400 |
|
| 7401 |
__gshared extern(C) void function(int) nothrow someFunc13476Alt = &Stub13476Alt!someFunc13476AltP; |
| 7402 |
__gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt; |
| 7403 |
|
| 7404 |
extern(C) auto Stub13476Alt(alias func)(int args) nothrow |
| 7405 |
{ |
| 7406 |
++flag13476; |
| 7407 |
extern(C) void function(int) nothrow impl = (i) {}; |
| 7408 |
return (*func = impl)(args); |
| 7409 |
} |
| 7410 |
|
| 7411 |
void test13476() |
| 7412 |
{ |
| 7413 |
assert(flag13476 == 0); |
| 7414 |
|
| 7415 |
someFunc13476(42); |
| 7416 |
assert(flag13476 == 1); |
| 7417 |
someFunc13476(43); |
| 7418 |
assert(flag13476 == 1); |
| 7419 |
|
| 7420 |
someFunc13476Alt(42); |
| 7421 |
assert(flag13476 == 2); |
| 7422 |
someFunc13476Alt(43); |
| 7423 |
assert(flag13476 == 2); |
| 7424 |
} |
| 7425 |
|
| 7426 |
/***************************************************/ |
| 7427 |
// https://issues.dlang.org/show_bug.cgi?id=14038 |
| 7428 |
|
| 7429 |
static immutable ubyte[string] wordsAA14038; |
| 7430 |
shared static this() |
| 7431 |
{ |
| 7432 |
wordsAA14038["zero"] = 0; |
| 7433 |
} |
| 7434 |
|
| 7435 |
/***************************************************/ |
| 7436 |
// https://issues.dlang.org/show_bug.cgi?id=14192 |
| 7437 |
|
| 7438 |
void test14192() |
| 7439 |
{ |
| 7440 |
shared int[int] map; |
| 7441 |
map[1] = 1; |
| 7442 |
} |
| 7443 |
|
| 7444 |
/***************************************************/ |
| 7445 |
// https://issues.dlang.org/show_bug.cgi?id=13720 |
| 7446 |
|
| 7447 |
struct FracSec13720 |
| 7448 |
{ |
| 7449 |
this(int hnsecs) {} |
| 7450 |
} |
| 7451 |
|
| 7452 |
struct SysTime13720 |
| 7453 |
{ |
| 7454 |
this(TimeOfDay13720 dateTime, FracSec13720 fracSec) |
| 7455 |
{ |
| 7456 |
} |
| 7457 |
} |
| 7458 |
|
| 7459 |
struct TimeOfDay13720 |
| 7460 |
{ |
| 7461 |
~this() { } |
| 7462 |
} |
| 7463 |
|
| 7464 |
void assertThrown13720(T)(lazy T) {} |
| 7465 |
|
| 7466 |
void test13720() |
| 7467 |
{ |
| 7468 |
assertThrown13720(SysTime13720(TimeOfDay13720.init, FracSec13720(-1))); |
| 7469 |
} |
| 7470 |
|
| 7471 |
/***************************************************/ |
| 7472 |
// https://issues.dlang.org/show_bug.cgi?id=13952 |
| 7473 |
|
| 7474 |
struct Reg13952 |
| 7475 |
{ |
| 7476 |
ubyte type; |
| 7477 |
ubyte regNo; |
| 7478 |
ushort size; |
| 7479 |
} |
| 7480 |
|
| 7481 |
struct Imm13952 |
| 7482 |
{ |
| 7483 |
ulong imm; |
| 7484 |
} |
| 7485 |
|
| 7486 |
struct Opnd13952 |
| 7487 |
{ |
| 7488 |
union |
| 7489 |
{ |
| 7490 |
Reg13952 reg; // size == 4 |
| 7491 |
Imm13952 imm; // size == 8 |
| 7492 |
} |
| 7493 |
ubyte tag; |
| 7494 |
|
| 7495 |
this(Reg13952 r) { reg = r; } |
| 7496 |
} |
| 7497 |
|
| 7498 |
Opnd13952 opnd13952(Reg13952 reg) |
| 7499 |
{ |
| 7500 |
return Opnd13952(reg); |
| 7501 |
} |
| 7502 |
|
| 7503 |
void test13952() |
| 7504 |
{ |
| 7505 |
Reg13952 reg; |
| 7506 |
auto op = opnd13952(reg); |
| 7507 |
auto buf = (cast(ubyte*)&op)[0 .. op.sizeof]; |
| 7508 |
//debug |
| 7509 |
//{ |
| 7510 |
// import std.stdio; |
| 7511 |
// writefln("op.reg = [%(%02x %)]", (cast(ubyte*)&op.reg)[0 .. Reg13952.sizeof]); |
| 7512 |
// writefln("op.imm = [%(%02x %)]", (cast(ubyte*)&op.imm)[0 .. Imm13952.sizeof]); |
| 7513 |
//} |
| 7514 |
foreach (e; buf) assert(e == 0); |
| 7515 |
} |
| 7516 |
|
| 7517 |
/***************************************************/ |
| 7518 |
// https://issues.dlang.org/show_bug.cgi?id=14165 |
| 7519 |
|
| 7520 |
class Foo14165 |
| 7521 |
{ |
| 7522 |
@disable this(); |
| 7523 |
this(int i) {} |
| 7524 |
} |
| 7525 |
|
| 7526 |
/***************************************************/ |
| 7527 |
// https://issues.dlang.org/show_bug.cgi?id=13985 |
| 7528 |
|
| 7529 |
interface I13985 |
| 7530 |
{ |
| 7531 |
void m1(); |
| 7532 |
void m2(); |
| 7533 |
void m3(); |
| 7534 |
|
| 7535 |
final void mf() |
| 7536 |
{ |
| 7537 |
m3(); |
| 7538 |
} |
| 7539 |
} |
| 7540 |
|
| 7541 |
class C13985 : I13985 |
| 7542 |
{ |
| 7543 |
void m1() {} |
| 7544 |
void m2() {} |
| 7545 |
void m3() {} |
| 7546 |
} |
| 7547 |
|
| 7548 |
class D13985 : C13985 |
| 7549 |
{ |
| 7550 |
void ml() |
| 7551 |
{ |
| 7552 |
super.mf(); |
| 7553 |
} |
| 7554 |
} |
| 7555 |
|
| 7556 |
void test13985() |
| 7557 |
{ |
| 7558 |
auto d = new D13985(); |
| 7559 |
d.ml(); |
| 7560 |
} |
| 7561 |
|
| 7562 |
/***************************************************/ |
| 7563 |
// https://issues.dlang.org/show_bug.cgi?id=14211 |
| 7564 |
|
| 7565 |
extern(C++) // all derived classes won't have invariants |
| 7566 |
class B14211 |
| 7567 |
{ |
| 7568 |
void func() |
| 7569 |
{ |
| 7570 |
} |
| 7571 |
} |
| 7572 |
|
| 7573 |
final class C14211 : B14211 |
| 7574 |
{ |
| 7575 |
} |
| 7576 |
|
| 7577 |
void test14211() |
| 7578 |
{ |
| 7579 |
auto c = new C14211(); |
| 7580 |
*cast(void**)c = null; |
| 7581 |
c.func(); // called without vtbl access |
| 7582 |
} |
| 7583 |
|
| 7584 |
/***************************************************/ |
| 7585 |
// https://issues.dlang.org/show_bug.cgi?id=14552 |
| 7586 |
|
| 7587 |
template map14552(fun...) |
| 7588 |
{ |
| 7589 |
template AppliedReturnType(alias f) |
| 7590 |
{ |
| 7591 |
alias typeof(f(0)) AppliedReturnType; |
| 7592 |
} |
| 7593 |
|
| 7594 |
auto map14552(int[] r) |
| 7595 |
{ |
| 7596 |
assert(!is(AppliedReturnType!fun)); |
| 7597 |
return MapResult14552!fun(); |
| 7598 |
} |
| 7599 |
} |
| 7600 |
|
| 7601 |
struct MapResult14552(alias fun) |
| 7602 |
{ |
| 7603 |
@property front() |
| 7604 |
{ |
| 7605 |
fun(0); |
| 7606 |
} |
| 7607 |
} |
| 7608 |
|
| 7609 |
class Outer14552 |
| 7610 |
{ |
| 7611 |
auto test() |
| 7612 |
{ |
| 7613 |
[1].map14552!(j => new Inner); |
| 7614 |
} |
| 7615 |
class Inner {} |
| 7616 |
} |
| 7617 |
|
| 7618 |
/***************************************************/ |
| 7619 |
// https://issues.dlang.org/show_bug.cgi?id=14853 |
| 7620 |
|
| 7621 |
struct Queue14853(T) |
| 7622 |
{ |
| 7623 |
struct Node |
| 7624 |
{ |
| 7625 |
T mfPayload = T.init; |
| 7626 |
union |
| 7627 |
{ |
| 7628 |
typeof(this)* mfPrev; |
| 7629 |
shared(typeof(this)*) mfShPrev; |
| 7630 |
} |
| 7631 |
union |
| 7632 |
{ |
| 7633 |
typeof(this)* mfNext; |
| 7634 |
shared(typeof(this)*) mfShNext; |
| 7635 |
} |
| 7636 |
} |
| 7637 |
|
| 7638 |
Node root; |
| 7639 |
|
| 7640 |
void pfPut(T v, Node* r = null) |
| 7641 |
{ |
| 7642 |
shared n = new Node(v); // problem! |
| 7643 |
} |
| 7644 |
} |
| 7645 |
|
| 7646 |
void test14853() |
| 7647 |
{ |
| 7648 |
auto b1 = new Queue14853!uint; |
| 7649 |
} |
| 7650 |
|
| 7651 |
/********************************************************/ |
| 7652 |
// https://issues.dlang.org/show_bug.cgi?id=15045 |
| 7653 |
|
| 7654 |
void test15045() |
| 7655 |
{ |
| 7656 |
void testName(T, bool r, string name)() |
| 7657 |
{ |
| 7658 |
T t; |
| 7659 |
|
| 7660 |
static assert(r == is(typeof(mixin("T."~name)))); |
| 7661 |
static assert(r == is(typeof(mixin("t."~name)))); |
| 7662 |
static assert(r == __traits(compiles, mixin("T."~name))); |
| 7663 |
static assert(r == __traits(compiles, mixin("t."~name))); |
| 7664 |
static assert(r == mixin("__traits(compiles, T."~name~")")); |
| 7665 |
static assert(r == mixin("__traits(compiles, t."~name~")")); |
| 7666 |
|
| 7667 |
static assert(r == __traits(hasMember, T, name) ); |
| 7668 |
static assert(r == __traits(hasMember, t, name) ); |
| 7669 |
static assert(r == __traits(compiles, __traits(getMember, T, name) )); |
| 7670 |
static assert(r == __traits(compiles, __traits(getMember, t, name) )); |
| 7671 |
static assert(r == __traits(compiles, __traits(getOverloads, T, name) )); |
| 7672 |
static assert(r == __traits(compiles, __traits(getOverloads, t, name) )); |
| 7673 |
} |
| 7674 |
void test(T, bool r)() |
| 7675 |
{ |
| 7676 |
testName!(T, r, "__ctor")(); |
| 7677 |
testName!(T, r, "__dtor")(); |
| 7678 |
testName!(T, r, "__xdtor")(); |
| 7679 |
testName!(T, r, "__postblit")(); |
| 7680 |
testName!(T, r, "__xpostblit")(); |
| 7681 |
} |
| 7682 |
|
| 7683 |
static struct X |
| 7684 |
{ |
| 7685 |
this(int) {} |
| 7686 |
this(this) {} |
| 7687 |
~this() {} |
| 7688 |
} |
| 7689 |
|
| 7690 |
static struct S1 |
| 7691 |
{ |
| 7692 |
auto opDispatch(string name, A...)(A args) { } |
| 7693 |
} |
| 7694 |
static struct S2 |
| 7695 |
{ |
| 7696 |
X get() { return X(); }; |
| 7697 |
alias get this; |
| 7698 |
} |
| 7699 |
static struct S3 |
| 7700 |
{ |
| 7701 |
X opDot() { return X(); }; |
| 7702 |
} |
| 7703 |
|
| 7704 |
test!(X, true)(); |
| 7705 |
test!(S1, false)(); |
| 7706 |
test!(S2, false)(); |
| 7707 |
test!(S3, false)(); |
| 7708 |
} |
| 7709 |
|
| 7710 |
/***************************************************/ |
| 7711 |
// https://issues.dlang.org/show_bug.cgi?id=15116 |
| 7712 |
|
| 7713 |
alias TypeTuple15116(T...) = T; |
| 7714 |
|
| 7715 |
template Mix15116() |
| 7716 |
{ |
| 7717 |
TypeTuple15116!(int, int) tup; |
| 7718 |
} |
| 7719 |
|
| 7720 |
struct S15116 |
| 7721 |
{ |
| 7722 |
mixin Mix15116 mix; |
| 7723 |
} |
| 7724 |
|
| 7725 |
void test15116() |
| 7726 |
{ |
| 7727 |
S15116 s; |
| 7728 |
auto x1 = s.tup; // OK |
| 7729 |
auto x2 = s.mix.tup; // OK <- NG |
| 7730 |
} |
| 7731 |
|
| 7732 |
/***************************************************/ |
| 7733 |
// https://issues.dlang.org/show_bug.cgi?id=15117 |
| 7734 |
|
| 7735 |
template Mix15117() |
| 7736 |
{ |
| 7737 |
int y = { typeof(this)* s; return s ? s.mix.y : 0; }(); |
| 7738 |
} |
| 7739 |
|
| 7740 |
struct S15117 |
| 7741 |
{ |
| 7742 |
int x = { typeof(this)* s; return s ? s.x : 0; }(); // OK |
| 7743 |
|
| 7744 |
mixin Mix15117 mix; // OK <- NG |
| 7745 |
} |
| 7746 |
|
| 7747 |
/***************************************************/ |
| 7748 |
// https://issues.dlang.org/show_bug.cgi?id=15126 |
| 7749 |
|
| 7750 |
struct Json15126 |
| 7751 |
{ |
| 7752 |
ubyte[16] m_data; |
| 7753 |
int opDispatch(string prop)() const { return 0; } |
| 7754 |
int opDispatch(string prop)() { return 0; } |
| 7755 |
} |
| 7756 |
|
| 7757 |
template isCustomSerializable15126(T) |
| 7758 |
{ |
| 7759 |
enum isCustomSerializable15126 = T.init.toRepresentation(); |
| 7760 |
} |
| 7761 |
|
| 7762 |
alias bug15126 = isCustomSerializable15126!Json15126; |
| 7763 |
|
| 7764 |
/***************************************************/ |
| 7765 |
// https://issues.dlang.org/show_bug.cgi?id=15141 |
| 7766 |
|
| 7767 |
class A15141 |
| 7768 |
{ |
| 7769 |
abstract void method(); |
| 7770 |
} |
| 7771 |
|
| 7772 |
class B15141 : A15141 { } |
| 7773 |
|
| 7774 |
void test15141() |
| 7775 |
{ |
| 7776 |
auto a = Object.factory(__MODULE__ ~ ".A15141"); |
| 7777 |
assert(a is null); |
| 7778 |
auto b = Object.factory(__MODULE__ ~ ".B15141"); |
| 7779 |
assert(b is null); // OK <- oops |
| 7780 |
} |
| 7781 |
|
| 7782 |
/***************************************************/ |
| 7783 |
// https://issues.dlang.org/show_bug.cgi?id=15366 |
| 7784 |
|
| 7785 |
enum E15366 : bool { A, B }; |
| 7786 |
|
| 7787 |
struct S15366 |
| 7788 |
{ |
| 7789 |
void func1(E15366 e) {} |
| 7790 |
|
| 7791 |
void func2(E15366 a, E15366 b) |
| 7792 |
{ |
| 7793 |
func1(cast(E15366)(a && b)); |
| 7794 |
func1(cast(E15366)(a || b)); |
| 7795 |
|
| 7796 |
auto x1 = cast(E15366)(a && b); |
| 7797 |
auto x2 = cast(E15366)(a || b); |
| 7798 |
} |
| 7799 |
} |
| 7800 |
|
| 7801 |
/***************************************************/ |
| 7802 |
// https://issues.dlang.org/show_bug.cgi?id=15369 |
| 7803 |
|
| 7804 |
struct MsgTable15369 |
| 7805 |
{ |
| 7806 |
const(char)[] ident; |
| 7807 |
const(char)* name; |
| 7808 |
}; |
| 7809 |
|
| 7810 |
MsgTable15369[] msgTable15369 = |
| 7811 |
[ |
| 7812 |
{ "empty", "" }, |
| 7813 |
]; |
| 7814 |
|
| 7815 |
void test15369() |
| 7816 |
{ |
| 7817 |
auto id = msgTable15369[0].ident; |
| 7818 |
auto p = msgTable15369[0].name; |
| 7819 |
|
| 7820 |
// a string literal "" should be zero-terminated |
| 7821 |
assert(*p == '\0'); |
| 7822 |
} |
| 7823 |
|
| 7824 |
void test15638() |
| 7825 |
{ |
| 7826 |
class A {} |
| 7827 |
class B : A {} |
| 7828 |
class C : A {} |
| 7829 |
|
| 7830 |
B b; |
| 7831 |
C c; |
| 7832 |
const(B) cb; |
| 7833 |
const(C) cc; |
| 7834 |
immutable(B) ib; |
| 7835 |
immutable(C) ic; |
| 7836 |
|
| 7837 |
// Common type for const derived classes |
| 7838 |
auto constCommon = true ? cb : cc; |
| 7839 |
static assert(is(typeof(constCommon) == const(A))); |
| 7840 |
|
| 7841 |
// Common type for immutable derived classes |
| 7842 |
auto immutableCommon = true ? ib : ic; |
| 7843 |
static assert(is(typeof(immutableCommon) == immutable(A))); |
| 7844 |
|
| 7845 |
// Common type for mixed const/immutable derived classes |
| 7846 |
auto mixed1 = true ? cb : ic; |
| 7847 |
static assert(is(typeof(mixed1) == const(A))); |
| 7848 |
auto mixed2 = true ? ib : cc; |
| 7849 |
static assert(is(typeof(mixed2) == const(A))); |
| 7850 |
|
| 7851 |
// Common type for mixed mutable/immutable derived classes |
| 7852 |
auto mixed3 = true ? b : ic; |
| 7853 |
static assert(is(typeof(mixed3) == const(A))); |
| 7854 |
auto mixed4 = true ? ib : c; |
| 7855 |
static assert(is(typeof(mixed4) == const(A))); |
| 7856 |
|
| 7857 |
// Array literal type deduction |
| 7858 |
auto arr1 = [ new immutable(B), new C ]; |
| 7859 |
auto arr2 = [ new B, new const(C) ]; |
| 7860 |
auto arr3 = [ new immutable(B), new immutable(C) ]; |
| 7861 |
static assert(is(typeof(arr1) == const(A)[])); |
| 7862 |
static assert(is(typeof(arr2) == const(A)[])); |
| 7863 |
static assert(is(typeof(arr3) == immutable(A)[])); |
| 7864 |
} |
| 7865 |
|
| 7866 |
/***************************************************/ |
| 7867 |
// https://issues.dlang.org/show_bug.cgi?id=15961 |
| 7868 |
|
| 7869 |
struct SliceOverIndexed15961(T) |
| 7870 |
{ |
| 7871 |
enum assignableIndex = T.init; |
| 7872 |
} |
| 7873 |
|
| 7874 |
struct Grapheme15961 |
| 7875 |
{ |
| 7876 |
SliceOverIndexed15961!Grapheme15961 opSlice() |
| 7877 |
{ |
| 7878 |
assert(0); |
| 7879 |
} |
| 7880 |
|
| 7881 |
struct |
| 7882 |
{ |
| 7883 |
ubyte* ptr_; |
| 7884 |
} |
| 7885 |
} |
| 7886 |
|
| 7887 |
/***************************************************/ |
| 7888 |
// https://issues.dlang.org/show_bug.cgi?id=16022 |
| 7889 |
|
| 7890 |
bool test16022() |
| 7891 |
{ |
| 7892 |
enum Type { Colon, Comma } |
| 7893 |
Type type; |
| 7894 |
return type == Type.Comma; |
| 7895 |
} |
| 7896 |
|
| 7897 |
bool test16022_structs() |
| 7898 |
{ |
| 7899 |
struct A |
| 7900 |
{ |
| 7901 |
int i; |
| 7902 |
string s; |
| 7903 |
} |
| 7904 |
|
| 7905 |
enum Type { Colon = A(0, "zero"), Comma = A(1, "one") } |
| 7906 |
Type type; |
| 7907 |
return type == Type.Comma; |
| 7908 |
} |
| 7909 |
|
| 7910 |
/***************************************************/ |
| 7911 |
// https://issues.dlang.org/show_bug.cgi?id=16233 |
| 7912 |
|
| 7913 |
enum valueConvertible(T1, T2) = blah; |
| 7914 |
|
| 7915 |
struct Checked(T, Hook) |
| 7916 |
{ |
| 7917 |
bool opEquals(U)(Checked!(U, Hook) rhs) |
| 7918 |
{ |
| 7919 |
alias R = typeof(payload + rhs.payload); |
| 7920 |
static if (valueConvertible!(T, R)) |
| 7921 |
{ |
| 7922 |
} |
| 7923 |
return false; |
| 7924 |
} |
| 7925 |
} |
| 7926 |
|
| 7927 |
void test16233() |
| 7928 |
{ |
| 7929 |
Checked!(Checked!(int, void), void) x1; |
| 7930 |
} |
| 7931 |
|
| 7932 |
/***************************************************/ |
| 7933 |
// https://issues.dlang.org/show_bug.cgi?id=16466 |
| 7934 |
|
| 7935 |
void test16466() |
| 7936 |
{ |
| 7937 |
static struct S |
| 7938 |
{ |
| 7939 |
real r; |
| 7940 |
} |
| 7941 |
real r; |
| 7942 |
printf("S.alignof: %zx, r.alignof: %zx\n", S.alignof, r.alignof); |
| 7943 |
assert(S.alignof == r.alignof); |
| 7944 |
} |
| 7945 |
|
| 7946 |
/***************************************************/ |
| 7947 |
|
| 7948 |
// https://issues.dlang.org/show_bug.cgi?id=16408 |
| 7949 |
|
| 7950 |
char[1] SDL_GetKeyName_buffer; |
| 7951 |
|
| 7952 |
const(char)[] SDL_GetKeyName(char k) |
| 7953 |
{ |
| 7954 |
pragma(inline, false); |
| 7955 |
SDL_GetKeyName_buffer[0] = k; |
| 7956 |
return SDL_GetKeyName_buffer[]; |
| 7957 |
} |
| 7958 |
|
| 7959 |
void formattedWrite(const(char)[] strW, const(char)[] strA, const(char)[] strC) |
| 7960 |
{ |
| 7961 |
pragma(inline, false); |
| 7962 |
|
| 7963 |
assert(strW == "W"); |
| 7964 |
assert(strA == "A"); |
| 7965 |
assert(strC == "C"); |
| 7966 |
} |
| 7967 |
|
| 7968 |
void test16408() |
| 7969 |
{ |
| 7970 |
pragma(inline, false); |
| 7971 |
formattedWrite( |
| 7972 |
SDL_GetKeyName('W').idup, |
| 7973 |
SDL_GetKeyName('A').idup, |
| 7974 |
SDL_GetKeyName('C').idup |
| 7975 |
); |
| 7976 |
} |
| 7977 |
|
| 7978 |
/***************************************************/ |
| 7979 |
// https://issues.dlang.org/show_bug.cgi?id=17349 |
| 7980 |
|
| 7981 |
void test17349() |
| 7982 |
{ |
| 7983 |
static struct S |
| 7984 |
{ |
| 7985 |
// Specify attribute inferred for dg1/dg2 |
| 7986 |
int bar(void delegate(ref int*) pure nothrow @nogc @safe) { return 1; } |
| 7987 |
int bar(void delegate(ref const int*) pure nothrow @nogc @safe) const { return 2; } |
| 7988 |
} |
| 7989 |
|
| 7990 |
void dg1(ref int*) { } |
| 7991 |
void dg2(ref const int*) { } |
| 7992 |
S s; |
| 7993 |
int i; |
| 7994 |
i = s.bar(&dg1); |
| 7995 |
assert(i == 1); |
| 7996 |
i = s.bar(&dg2); |
| 7997 |
assert(i == 2); |
| 7998 |
} |
| 7999 |
|
| 8000 |
/***************************************************/ |
| 8001 |
// https://issues.dlang.org/show_bug.cgi?id=17915 |
| 8002 |
|
| 8003 |
void test17915() |
| 8004 |
{ |
| 8005 |
static class MyClass |
| 8006 |
{ |
| 8007 |
S17915!MyClass m_member; |
| 8008 |
} |
| 8009 |
} |
| 8010 |
|
| 8011 |
struct S17915(T) |
| 8012 |
{ |
| 8013 |
T owner; |
| 8014 |
} |
| 8015 |
|
| 8016 |
void test18232() |
| 8017 |
{ |
| 8018 |
static struct Canary |
| 8019 |
{ |
| 8020 |
int x = 0x900D_900D; |
| 8021 |
} |
| 8022 |
union U |
| 8023 |
{ |
| 8024 |
Canary method() |
| 8025 |
{ |
| 8026 |
Canary c; |
| 8027 |
return c; |
| 8028 |
} |
| 8029 |
} |
| 8030 |
U u; |
| 8031 |
assert(u.method() == Canary.init); |
| 8032 |
} |
| 8033 |
|
| 8034 |
/***************************************************/ |
| 8035 |
// https://issues.dlang.org/show_bug.cgi?id=24332 |
| 8036 |
|
| 8037 |
void test24332() |
| 8038 |
{ |
| 8039 |
class A {} |
| 8040 |
final class B : A {} |
| 8041 |
|
| 8042 |
auto foo(A a) { |
| 8043 |
return cast(B) a; |
| 8044 |
} |
| 8045 |
|
| 8046 |
auto a = new A(); |
| 8047 |
auto n = cast(B) a; |
| 8048 |
assert(n is null); |
| 8049 |
auto b = cast(A) new B(); |
| 8050 |
auto c = cast(B) b; |
| 8051 |
assert(c); |
| 8052 |
B e; |
| 8053 |
auto d = cast(B) cast(A) e; |
| 8054 |
assert(d is null); |
| 8055 |
} |
| 8056 |
|
| 8057 |
/***************************************************/ |
| 8058 |
|
| 8059 |
int main() |
| 8060 |
{ |
| 8061 |
test1(); |
| 8062 |
test2(); |
| 8063 |
test4(); |
| 8064 |
test5(); |
| 8065 |
test6(); |
| 8066 |
test7(); |
| 8067 |
test8(); |
| 8068 |
test9(); |
| 8069 |
test10(); |
| 8070 |
test11(); |
| 8071 |
test12(); |
| 8072 |
test13(); |
| 8073 |
test14(); |
| 8074 |
test15(); |
| 8075 |
test16(); |
| 8076 |
test17(); |
| 8077 |
test18(); |
| 8078 |
test19(); |
| 8079 |
test20(); |
| 8080 |
test21(); |
| 8081 |
test22(); |
| 8082 |
test23(); |
| 8083 |
test24(); |
| 8084 |
test25(); |
| 8085 |
test26(); |
| 8086 |
test27(); |
| 8087 |
test28(); |
| 8088 |
test29(); |
| 8089 |
test30(); |
| 8090 |
test31(); |
| 8091 |
test32(); |
| 8092 |
test33(); |
| 8093 |
test34(); |
| 8094 |
test35(); |
| 8095 |
test36(); |
| 8096 |
test37(); |
| 8097 |
test38(); |
| 8098 |
test39(); |
| 8099 |
test40(); |
| 8100 |
test41(); |
| 8101 |
test42(); |
| 8102 |
test43(); |
| 8103 |
test44(); |
| 8104 |
test45(); |
| 8105 |
test46(); |
| 8106 |
test47(); |
| 8107 |
test48(); |
| 8108 |
test49(); |
| 8109 |
test796(); |
| 8110 |
test50(); |
| 8111 |
test51(); |
| 8112 |
test52(); |
| 8113 |
test53(); |
| 8114 |
test54(); |
| 8115 |
test55(); |
| 8116 |
test56(); |
| 8117 |
test57(); |
| 8118 |
test58(); |
| 8119 |
|
| 8120 |
test60(); |
| 8121 |
test61(); |
| 8122 |
test62(); |
| 8123 |
test63(); |
| 8124 |
test64(); |
| 8125 |
test65(); |
| 8126 |
test66(); |
| 8127 |
test67(); |
| 8128 |
test68(); |
| 8129 |
test69(); |
| 8130 |
test70(); |
| 8131 |
|
| 8132 |
test5785(); |
| 8133 |
test72(); |
| 8134 |
test73(); |
| 8135 |
test74(); |
| 8136 |
test75(); |
| 8137 |
test76(); |
| 8138 |
test77(); |
| 8139 |
test78(); |
| 8140 |
test79(); |
| 8141 |
test80(); |
| 8142 |
test81(); |
| 8143 |
test82(); |
| 8144 |
test83(); |
| 8145 |
test3559(); |
| 8146 |
test84(); |
| 8147 |
test85(); |
| 8148 |
test2006(); |
| 8149 |
test8442(); |
| 8150 |
test86(); |
| 8151 |
test87(); |
| 8152 |
test2486(); |
| 8153 |
test5554(); |
| 8154 |
test88(); |
| 8155 |
test7545(); |
| 8156 |
test89(); |
| 8157 |
test90(); |
| 8158 |
test91(); |
| 8159 |
test92(); |
| 8160 |
test4536(); |
| 8161 |
test93(); |
| 8162 |
test94(); |
| 8163 |
test95(); |
| 8164 |
test5403(); |
| 8165 |
test96(); |
| 8166 |
test97(); |
| 8167 |
test98(); |
| 8168 |
test99(); |
| 8169 |
test100(); |
| 8170 |
test101(); |
| 8171 |
|
| 8172 |
test103(); |
| 8173 |
test104(); |
| 8174 |
test105(); |
| 8175 |
test3927(); |
| 8176 |
test107(); |
| 8177 |
|
| 8178 |
test109(); |
| 8179 |
|
| 8180 |
test111(); |
| 8181 |
|
| 8182 |
test113(); |
| 8183 |
|
| 8184 |
test115(); |
| 8185 |
test116(); |
| 8186 |
test117(); |
| 8187 |
test3822(); |
| 8188 |
test6545(); |
| 8189 |
test118(); |
| 8190 |
test5081(); |
| 8191 |
|
| 8192 |
test120(); |
| 8193 |
test10724(); |
| 8194 |
test122(); |
| 8195 |
test123(); |
| 8196 |
test124(); |
| 8197 |
test125(); |
| 8198 |
test6763(); |
| 8199 |
|
| 8200 |
test127(); |
| 8201 |
test128(); |
| 8202 |
test1891(); |
| 8203 |
test129(); |
| 8204 |
test130(); |
| 8205 |
test1064(); |
| 8206 |
test131(); |
| 8207 |
test132(); |
| 8208 |
test133(); |
| 8209 |
test134(); |
| 8210 |
test135(); |
| 8211 |
test136(); |
| 8212 |
test137(); |
| 8213 |
test138(); |
| 8214 |
test1962(); |
| 8215 |
test139(); |
| 8216 |
test140(); |
| 8217 |
test141(); |
| 8218 |
test6317(); |
| 8219 |
test142(); |
| 8220 |
test143(); |
| 8221 |
test144(); |
| 8222 |
test145(); |
| 8223 |
test146(); |
| 8224 |
test147(); |
| 8225 |
test6685(); |
| 8226 |
test148(); |
| 8227 |
test149(); |
| 8228 |
test2356(); |
| 8229 |
test13652(); |
| 8230 |
test11238(); |
| 8231 |
test2540(); |
| 8232 |
test14348(); |
| 8233 |
test150(); |
| 8234 |
test151(); |
| 8235 |
test152(); |
| 8236 |
test153(); |
| 8237 |
test154(); |
| 8238 |
test155(); |
| 8239 |
test156(); |
| 8240 |
test658(); |
| 8241 |
test3632(); |
| 8242 |
test4258(); |
| 8243 |
test4539(); |
| 8244 |
test4963(); |
| 8245 |
test4031(); |
| 8246 |
test5437(); |
| 8247 |
test6230(); |
| 8248 |
test6264(); |
| 8249 |
test6284(); |
| 8250 |
test6295(); |
| 8251 |
test6293(); |
| 8252 |
test5046(); |
| 8253 |
test1471(); |
| 8254 |
test6335(); |
| 8255 |
test1687(); |
| 8256 |
test6228(); |
| 8257 |
test3733(); |
| 8258 |
test4392(); |
| 8259 |
test7942(); |
| 8260 |
test6220(); |
| 8261 |
test5799(); |
| 8262 |
test157(); |
| 8263 |
test6473(); |
| 8264 |
test6630(); |
| 8265 |
test6690(); |
| 8266 |
test2953(); |
| 8267 |
test2997(); |
| 8268 |
test4423(); |
| 8269 |
test4647(); |
| 8270 |
test5696(); |
| 8271 |
test6084(); |
| 8272 |
test6488(); |
| 8273 |
test6565(); |
| 8274 |
test6836(); |
| 8275 |
test6837(); |
| 8276 |
test6927(); |
| 8277 |
test6733(); |
| 8278 |
test6813(); |
| 8279 |
test6859(); |
| 8280 |
|
| 8281 |
test6910(); |
| 8282 |
test6902(); |
| 8283 |
test6330(); |
| 8284 |
test6868(); |
| 8285 |
test2856(); |
| 8286 |
test3091(); |
| 8287 |
test6056(); |
| 8288 |
test6356(); |
| 8289 |
test7073(); |
| 8290 |
test7104(); |
| 8291 |
test7150(); |
| 8292 |
test7160(); |
| 8293 |
test7168(); |
| 8294 |
test7170(); |
| 8295 |
test7196(); |
| 8296 |
test7285(); |
| 8297 |
test14737(); |
| 8298 |
test7321(); |
| 8299 |
test3282(); |
| 8300 |
test7534(); |
| 8301 |
test7534cov(); |
| 8302 |
test7618(); |
| 8303 |
test7621(); |
| 8304 |
test11417(); |
| 8305 |
test7682(); |
| 8306 |
test7735(); |
| 8307 |
test7823(); |
| 8308 |
test7871(); |
| 8309 |
test7906(); |
| 8310 |
test7907(); |
| 8311 |
test12503(); |
| 8312 |
test8004(); |
| 8313 |
test8064(); |
| 8314 |
test159(); |
| 8315 |
test12824(); |
| 8316 |
test8283(); |
| 8317 |
test13182(); |
| 8318 |
test8269(); |
| 8319 |
test8395(); |
| 8320 |
test13427(); |
| 8321 |
test5749(); |
| 8322 |
test8396(); |
| 8323 |
test160(); |
| 8324 |
test8665(); |
| 8325 |
test8108(); |
| 8326 |
test8360(); |
| 8327 |
test9577(); |
| 8328 |
test6141(); |
| 8329 |
test199(); |
| 8330 |
test8526(); |
| 8331 |
test161(); |
| 8332 |
test7175(); |
| 8333 |
test8819(); |
| 8334 |
test8917(); |
| 8335 |
test8945(); |
| 8336 |
test11805(); |
| 8337 |
test14192(); |
| 8338 |
test163(); |
| 8339 |
test9428(); |
| 8340 |
test9477(); |
| 8341 |
test9538(); |
| 8342 |
test9700(); |
| 8343 |
test9834(); |
| 8344 |
test13947(); |
| 8345 |
test9883(); |
| 8346 |
test10091(); |
| 8347 |
test9130(); |
| 8348 |
test10542(); |
| 8349 |
test10539(); |
| 8350 |
test10634(); |
| 8351 |
test15080(); |
| 8352 |
test7254(); |
| 8353 |
test13468(); |
| 8354 |
test11075(); |
| 8355 |
test11181(); |
| 8356 |
test11317(); |
| 8357 |
test11888(); |
| 8358 |
test12036(); |
| 8359 |
test12153(); |
| 8360 |
test12937(); |
| 8361 |
test13154(); |
| 8362 |
test13437(); |
| 8363 |
test13472(); |
| 8364 |
test13476(); |
| 8365 |
test13720(); |
| 8366 |
test13952(); |
| 8367 |
test13985(); |
| 8368 |
test14211(); |
| 8369 |
test15141(); |
| 8370 |
test15369(); |
| 8371 |
test15638(); |
| 8372 |
test16233(); |
| 8373 |
test16466(); |
| 8374 |
test16408(); |
| 8375 |
test17349(); |
| 8376 |
test17915(); |
| 8377 |
test18232(); |
| 8378 |
test24332(); |
| 8379 |
|
| 8380 |
printf("Success\n"); |
| 8381 |
return 0; |
| 8382 |
} |