| 1 |
// PERMUTE_ARGS: -unittest -O -release -inline -fPIC -g |
| 2 |
// TRANSFORM_OUTPUT: remove_lines("warning: sprintf\(\) is often misused") |
| 3 |
|
| 4 |
extern(C) int printf(const char*, ...); |
| 5 |
extern(C) int sprintf(char*, const char*, ...); |
| 6 |
|
| 7 |
/**************************************/ |
| 8 |
|
| 9 |
void test1() |
| 10 |
{ |
| 11 |
bool x; |
| 12 |
int i; |
| 13 |
|
| 14 |
i = !("bar" == "bar"); |
| 15 |
assert(i == 0); |
| 16 |
|
| 17 |
i = "bar" != "bar"; |
| 18 |
assert(i == 0); |
| 19 |
|
| 20 |
i = "bar" == "bar"; |
| 21 |
assert(i == 1); |
| 22 |
|
| 23 |
x = "bar" != "bar"; |
| 24 |
assert(x == false); |
| 25 |
|
| 26 |
assert("bar" == "bar"); |
| 27 |
|
| 28 |
x = "bar" == "bar"; |
| 29 |
assert(x == true); |
| 30 |
|
| 31 |
/+ ---- +/ |
| 32 |
|
| 33 |
i = !("foo" == "bar"); |
| 34 |
assert(i == 1); |
| 35 |
|
| 36 |
i = "foo" != "bar"; |
| 37 |
assert(i == 1); |
| 38 |
|
| 39 |
i = "foo" == "bar"; |
| 40 |
assert(i == 0); |
| 41 |
|
| 42 |
x = "foo" != "bar"; |
| 43 |
assert(x == true); |
| 44 |
|
| 45 |
assert("foo" != "bar"); |
| 46 |
|
| 47 |
x = "foo" == "bar"; |
| 48 |
assert(x == false); |
| 49 |
|
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
/**************************************/ |
| 54 |
|
| 55 |
void test2() |
| 56 |
{ |
| 57 |
bool x; |
| 58 |
int i; |
| 59 |
|
| 60 |
i = !("bar" <= "bar"); |
| 61 |
assert(i <= 0); |
| 62 |
|
| 63 |
i = "bar" > "bar"; |
| 64 |
assert(i == 0); |
| 65 |
|
| 66 |
i = "bar" >= "bar"; |
| 67 |
assert(i == 1); |
| 68 |
|
| 69 |
x = "bar" < "bar"; |
| 70 |
assert(x == false); |
| 71 |
|
| 72 |
assert("bar" <= "bar"); |
| 73 |
|
| 74 |
x = "bar" <= "bar"; |
| 75 |
assert(x == true); |
| 76 |
|
| 77 |
/+ ---- +/ |
| 78 |
|
| 79 |
i = !("foo" < "bar"); |
| 80 |
assert(i == 1); |
| 81 |
|
| 82 |
i = "foo" > "bar"; |
| 83 |
assert(i == 1); |
| 84 |
|
| 85 |
i = "foo" < "bar"; |
| 86 |
assert(i == 0); |
| 87 |
|
| 88 |
x = "foo" >= "bar"; |
| 89 |
assert(x == true); |
| 90 |
|
| 91 |
assert("foo" >= "bar"); |
| 92 |
|
| 93 |
x = "foo" <= "bar"; |
| 94 |
assert(x == false); |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
/**************************************/ |
| 100 |
|
| 101 |
bool all(string array, bool function(char) predicate) { |
| 102 |
for (int i = 0; i < array.length; i++) { |
| 103 |
if (!predicate(array[i])) { |
| 104 |
return false; |
| 105 |
} |
| 106 |
} |
| 107 |
return true; |
| 108 |
} |
| 109 |
|
| 110 |
bool all(string array, bool delegate(char) predicate) { |
| 111 |
for (int i = 0; i < array.length; i++) { |
| 112 |
if (!predicate(array[i])) { |
| 113 |
return false; |
| 114 |
} |
| 115 |
} |
| 116 |
return true; |
| 117 |
} |
| 118 |
|
| 119 |
bool isVowel(char c) { |
| 120 |
return (c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u'); |
| 121 |
} |
| 122 |
|
| 123 |
class Character { |
| 124 |
private char letter; |
| 125 |
this(char c) { |
| 126 |
this.letter = c; |
| 127 |
} |
| 128 |
public bool isLetter(char c) { |
| 129 |
return this.letter == c; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
void test3() |
| 134 |
{ |
| 135 |
Character a = new Character('a'); |
| 136 |
bool delegate(char) isLetter; |
| 137 |
isLetter = &a.isLetter; |
| 138 |
bool i; |
| 139 |
|
| 140 |
i = all("aeiouoeieuiei", &isVowel); |
| 141 |
assert(i == true); |
| 142 |
|
| 143 |
i = all("aeiouoeieuiei", isLetter); |
| 144 |
assert(i == false); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
/**************************************/ |
| 149 |
|
| 150 |
int[] fun(int i) |
| 151 |
in |
| 152 |
{ |
| 153 |
assert(i > 0); |
| 154 |
} |
| 155 |
out (result) |
| 156 |
{ |
| 157 |
assert(result[0] == 2); |
| 158 |
} |
| 159 |
do |
| 160 |
{ |
| 161 |
char result; |
| 162 |
int[] res = new int[10]; |
| 163 |
res[] = i; |
| 164 |
int isZero = (result == 0xFF); |
| 165 |
assert(isZero); |
| 166 |
return res; |
| 167 |
} |
| 168 |
|
| 169 |
void test4() |
| 170 |
{ |
| 171 |
int[] values = fun(2); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
/**************************************/ |
| 176 |
|
| 177 |
|
| 178 |
const uint D3DSP_DSTMOD_SHIFT = 20; |
| 179 |
|
| 180 |
const uint D3DSP_DSTMOD_MASK = 0x00F00000; |
| 181 |
|
| 182 |
|
| 183 |
enum D3DSHADER_PARAM_DSTMOD_TYPE |
| 184 |
|
| 185 |
{ |
| 186 |
NONE = 0<<D3DSP_DSTMOD_SHIFT, |
| 187 |
SATURATE= 1<<D3DSP_DSTMOD_SHIFT, |
| 188 |
FORCE_DWORD = 0x7fffffff, |
| 189 |
} |
| 190 |
|
| 191 |
void test5() |
| 192 |
{ |
| 193 |
} |
| 194 |
|
| 195 |
/**************************************/ |
| 196 |
|
| 197 |
class foo6 |
| 198 |
{ |
| 199 |
union |
| 200 |
{ |
| 201 |
int i; |
| 202 |
char j; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
void test6() |
| 207 |
{ |
| 208 |
} |
| 209 |
|
| 210 |
/**************************************/ |
| 211 |
|
| 212 |
void test7() |
| 213 |
{ |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
/**************************************/ |
| 218 |
|
| 219 |
real x8 = 4; |
| 220 |
long y8; |
| 221 |
|
| 222 |
void test8() |
| 223 |
{ |
| 224 |
y8 = cast(long)x8; |
| 225 |
assert(y8 == 4); |
| 226 |
y8 = cast(long)cast(double)x8; |
| 227 |
assert(y8 == 4); |
| 228 |
printf ("%lld\n", y8); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
/**************************************/ |
| 233 |
|
| 234 |
void test9() |
| 235 |
{ |
| 236 |
struct B { } |
| 237 |
B bar (ref int p) |
| 238 |
{ |
| 239 |
B b; |
| 240 |
return b; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
/**************************************/ |
| 246 |
|
| 247 |
struct B10 |
| 248 |
{ |
| 249 |
uint member; |
| 250 |
} |
| 251 |
|
| 252 |
B10 func10() |
| 253 |
{ |
| 254 |
B10 b; |
| 255 |
b.member=7; |
| 256 |
return b; |
| 257 |
} |
| 258 |
|
| 259 |
void test10() |
| 260 |
{ |
| 261 |
uint i=func10().member; // Internal error: ..\ztc\cgcs.c 350 |
| 262 |
assert(i == 7); |
| 263 |
|
| 264 |
B10 b=func10(); //works |
| 265 |
i=b.member; |
| 266 |
assert(i == 7); |
| 267 |
} |
| 268 |
|
| 269 |
|
| 270 |
/**************************************/ |
| 271 |
|
| 272 |
void test11() |
| 273 |
{ |
| 274 |
const int notInitialized; |
| 275 |
const int i=notInitialized; // DMD crashes |
| 276 |
assert(notInitialized == 0); |
| 277 |
assert(i == 0); |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
/**************************************/ |
| 282 |
|
| 283 |
struct Array12 |
| 284 |
{ |
| 285 |
char len; |
| 286 |
void* p; |
| 287 |
} |
| 288 |
//Array12 f12(string a) |
| 289 |
//{ |
| 290 |
// return *cast(Array12*) &a[0..23]; //Internal error: ..\ztc\cgcs.c 350 |
| 291 |
//} |
| 292 |
|
| 293 |
Array12 g12(string a) |
| 294 |
{ |
| 295 |
return *cast(Array12*) &a; //works |
| 296 |
} |
| 297 |
|
| 298 |
void test12() |
| 299 |
{ |
| 300 |
string a = "12345678901234567890123"; |
| 301 |
Array12 b; |
| 302 |
|
| 303 |
//b = f12(a); |
| 304 |
//printf("b.len = %x\n", b.len); |
| 305 |
b = g12(a); |
| 306 |
printf("b.len = %x\n", b.len); |
| 307 |
} |
| 308 |
|
| 309 |
|
| 310 |
/**************************************/ |
| 311 |
|
| 312 |
|
| 313 |
class A13 |
| 314 |
{ |
| 315 |
int opBinary(string op : "<<")(char* v) { return 1; } |
| 316 |
int opBinary(string op : "<<")(string v) { return 2; } |
| 317 |
} |
| 318 |
|
| 319 |
void test13() |
| 320 |
{ |
| 321 |
A13 a = new A13(); |
| 322 |
int i; |
| 323 |
i = a << cast(string) ""; |
| 324 |
assert(i == 2); |
| 325 |
i = a << cast(string)""; |
| 326 |
assert(i == 2); |
| 327 |
} |
| 328 |
|
| 329 |
/**************************************/ |
| 330 |
|
| 331 |
union U1 |
| 332 |
{ |
| 333 |
struct { int a; } |
| 334 |
struct { int b; } |
| 335 |
} |
| 336 |
|
| 337 |
union U2 |
| 338 |
{ |
| 339 |
struct { int a; } |
| 340 |
struct { long b; } |
| 341 |
} |
| 342 |
|
| 343 |
union U3 |
| 344 |
{ |
| 345 |
struct { long a; } |
| 346 |
struct { int b; } |
| 347 |
} |
| 348 |
|
| 349 |
union U4 |
| 350 |
{ |
| 351 |
int a; |
| 352 |
int b; |
| 353 |
} |
| 354 |
|
| 355 |
union U5 |
| 356 |
{ |
| 357 |
int a; |
| 358 |
long b; |
| 359 |
} |
| 360 |
|
| 361 |
union U6 |
| 362 |
{ |
| 363 |
long a; |
| 364 |
int b; |
| 365 |
} |
| 366 |
|
| 367 |
void test14() |
| 368 |
{ |
| 369 |
printf("%zd %zd %zd\n", U1.a.offsetof, U1.b.offsetof, U1.sizeof); |
| 370 |
assert(U1.a.offsetof == 0); |
| 371 |
assert(U1.b.offsetof == 0); |
| 372 |
assert(U1.sizeof == 4); |
| 373 |
|
| 374 |
printf("%zd %zd %zd\n", U2.a.offsetof, U2.b.offsetof, U2.sizeof); |
| 375 |
assert(U2.a.offsetof == 0); |
| 376 |
assert(U2.b.offsetof == 0); |
| 377 |
assert(U2.sizeof == 8); |
| 378 |
|
| 379 |
printf("%zd %zd %zd\n", U3.a.offsetof, U3.b.offsetof, U3.sizeof); |
| 380 |
assert(U3.a.offsetof == 0); |
| 381 |
assert(U3.b.offsetof == 0); |
| 382 |
assert(U3.sizeof == 8); |
| 383 |
|
| 384 |
printf("%zd %zd %zd\n", U4.a.offsetof, U4.b.offsetof, U4.sizeof); |
| 385 |
assert(U4.a.offsetof == 0); |
| 386 |
assert(U4.b.offsetof == 0); |
| 387 |
assert(U4.sizeof == 4); |
| 388 |
|
| 389 |
printf("%zd %zd %zd\n", U5.a.offsetof, U5.b.offsetof, U5.sizeof); |
| 390 |
assert(U5.a.offsetof == 0); |
| 391 |
assert(U5.b.offsetof == 0); |
| 392 |
assert(U5.sizeof == 8); |
| 393 |
|
| 394 |
printf("%zd %zd %zd\n", U6.a.offsetof, U6.b.offsetof, U6.sizeof); |
| 395 |
assert(U6.a.offsetof == 0); |
| 396 |
assert(U6.b.offsetof == 0); |
| 397 |
assert(U6.sizeof == 8); |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
/**************************************/ |
| 402 |
|
| 403 |
void test15() |
| 404 |
{ |
| 405 |
const int[] array = [1,2,3]; |
| 406 |
|
| 407 |
assert(array.length == 3); |
| 408 |
assert(array[1] == 2); |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
/**************************************/ |
| 413 |
|
| 414 |
class Conversion(T) |
| 415 |
{ |
| 416 |
class Big {char[2] dummy;} |
| 417 |
static Big Test(...); |
| 418 |
|
| 419 |
enum { exists = Test().sizeof } |
| 420 |
} |
| 421 |
|
| 422 |
void test16() |
| 423 |
{ |
| 424 |
assert(Conversion!(double).exists == (void*).sizeof); |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
/**************************************/ |
| 429 |
|
| 430 |
class Cout17 |
| 431 |
{ |
| 432 |
Cout17 set(int x) |
| 433 |
{ |
| 434 |
printf("%d",x); |
| 435 |
return this; |
| 436 |
} |
| 437 |
alias opBinary(string op : "<<") = set; |
| 438 |
} |
| 439 |
|
| 440 |
void test17() |
| 441 |
{ |
| 442 |
Cout17 cout = new Cout17; |
| 443 |
cout << 5 << 4; |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
/**************************************/ |
| 449 |
|
| 450 |
void test18() |
| 451 |
{ |
| 452 |
bool[] x = new bool[100]; |
| 453 |
x[] = 1; |
| 454 |
bool[] y = x.dup; |
| 455 |
assert(y[99]); |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
/**************************************/ |
| 460 |
|
| 461 |
bool[32] x19 = 1; |
| 462 |
|
| 463 |
void test19() |
| 464 |
{ |
| 465 |
assert(x19[31]); |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
/**************************************/ |
| 470 |
|
| 471 |
bool[2] y20 = [ cast(bool) 3, cast(bool) 2 ]; |
| 472 |
|
| 473 |
void test20() |
| 474 |
{ |
| 475 |
assert(y20[0]); // ok |
| 476 |
assert(y20[1]); // fails |
| 477 |
} |
| 478 |
|
| 479 |
/**************************************/ |
| 480 |
|
| 481 |
bool isnan(float x) { return !( (x >= 0) || (x < 0)); } |
| 482 |
|
| 483 |
struct X21 { float f, g, h; } |
| 484 |
X21 x21_1; |
| 485 |
X21 x21_2 = { f: 1.0, h: 2.0 }; |
| 486 |
|
| 487 |
char[3] y21_1; |
| 488 |
char[3] y21_2 = [ 0: 'a', 2: 'b' ]; |
| 489 |
|
| 490 |
void test21() |
| 491 |
{ |
| 492 |
assert(isnan(x21_1.g)); |
| 493 |
assert(isnan(x21_2.g)); |
| 494 |
assert(y21_1[1] == '\xff'); |
| 495 |
assert(y21_2[1] == '\xff'); |
| 496 |
} |
| 497 |
|
| 498 |
|
| 499 |
/**************************************/ |
| 500 |
|
| 501 |
void test22() |
| 502 |
{ |
| 503 |
wstring a = cast(wstring)"一〇"; |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
/**************************************/ |
| 508 |
|
| 509 |
interface A23 { void x(); } |
| 510 |
class B23 : A23 { void x() { } } |
| 511 |
class C23 : B23 { uint y = 12345678; } |
| 512 |
|
| 513 |
void stest23(A23 a) |
| 514 |
{ |
| 515 |
synchronized (a) |
| 516 |
{ |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
void test23() |
| 521 |
{ |
| 522 |
C23 c = new C23; |
| 523 |
assert(c.y == 12345678 /*c.y.init*/); |
| 524 |
stest23(c); |
| 525 |
assert(c.y == 12345678 /*c.y.init*/); |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
/**************************************/ |
| 530 |
|
| 531 |
class A24 |
| 532 |
{ |
| 533 |
unittest |
| 534 |
{ |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
void test24() |
| 539 |
{ |
| 540 |
} |
| 541 |
|
| 542 |
/**************************************/ |
| 543 |
|
| 544 |
char rot13(char ret) |
| 545 |
{ |
| 546 |
if (ret > 'A'-1 && ret < 'N') |
| 547 |
{ ret += 13;} |
| 548 |
else if(ret > 'M' && ret < 'Z'+1) |
| 549 |
{ ret -= 13;} |
| 550 |
else if(ret > 'a'-1 && ret < 'n') |
| 551 |
{ ret += 13;} |
| 552 |
else if(ret > 'm' && ret < 'z'+1) |
| 553 |
{ ret -= 13;} |
| 554 |
|
| 555 |
return ret; |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
void test25() |
| 560 |
{ |
| 561 |
foreach (char c; "hello World\n") |
| 562 |
printf("%c %c\n", c, rot13(c)); |
| 563 |
assert(rot13('h') == 'u'); |
| 564 |
assert(rot13('o') == 'b'); |
| 565 |
assert(rot13('W') == 'J'); |
| 566 |
assert(rot13('H') == 'U'); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
/**************************************/ |
| 571 |
|
| 572 |
bool b26a = cast(bool)( cast(bool) 2 & cast(bool) 1 ); |
| 573 |
bool b26b = cast(bool) 2; |
| 574 |
|
| 575 |
void test26() |
| 576 |
{ |
| 577 |
assert( (* cast(byte *) & b26a) == 1 ); |
| 578 |
assert( (* cast(byte *) & b26b) == 1 ); |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
/**************************************/ |
| 583 |
|
| 584 |
int c27; |
| 585 |
|
| 586 |
struct X27 |
| 587 |
{ |
| 588 |
int x; |
| 589 |
struct |
| 590 |
{ |
| 591 |
int a; |
| 592 |
int b; |
| 593 |
static this() { c27 = 3; } |
| 594 |
} |
| 595 |
} |
| 596 |
|
| 597 |
void test27() |
| 598 |
{ |
| 599 |
assert(c27 == 3); |
| 600 |
} |
| 601 |
|
| 602 |
/**************************************/ |
| 603 |
|
| 604 |
void test28() |
| 605 |
{ |
| 606 |
void bar() |
| 607 |
{ |
| 608 |
throw new Foo28(); |
| 609 |
} |
| 610 |
} |
| 611 |
|
| 612 |
class Foo28 : Throwable |
| 613 |
{ |
| 614 |
private: |
| 615 |
this() { super(""); } |
| 616 |
} |
| 617 |
|
| 618 |
/**************************************/ |
| 619 |
|
| 620 |
struct S29 { |
| 621 |
ubyte a, b, c, d; |
| 622 |
} |
| 623 |
|
| 624 |
int hoge(S29 s) { |
| 625 |
char[10] b; |
| 626 |
printf("%x\n", *cast(int*)&s); |
| 627 |
sprintf(b.ptr, "%x", *cast(int*)&s); |
| 628 |
version (LittleEndian) |
| 629 |
assert(b[0 .. 7] == "4030201"); |
| 630 |
version (BigEndian) |
| 631 |
assert(b[0 .. 7] == "1020304"); |
| 632 |
return 0; |
| 633 |
} |
| 634 |
|
| 635 |
void test29() |
| 636 |
{ |
| 637 |
for (int i = 0; i < 1; i++) { |
| 638 |
S29 s; |
| 639 |
s.a = 1; |
| 640 |
s.b = 2; |
| 641 |
s.c = 3; |
| 642 |
s.d = 4; |
| 643 |
hoge(s); |
| 644 |
} |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
/**************************************/ |
| 649 |
|
| 650 |
class Qwert { |
| 651 |
static { |
| 652 |
deprecated int yuiop() { |
| 653 |
return 42; |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
static deprecated int asdfg() { |
| 658 |
return yuiop() + 105; |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
void test30() |
| 663 |
{ |
| 664 |
} |
| 665 |
|
| 666 |
/**************************************/ |
| 667 |
|
| 668 |
void test31() |
| 669 |
{ |
| 670 |
string foo = "hello"; |
| 671 |
|
| 672 |
printf("%s\n", foo.ptr); |
| 673 |
auto s = typeid(typeof(foo.ptr)).toString(); |
| 674 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 675 |
s = typeid(char*).toString(); |
| 676 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 677 |
assert(typeid(typeof(foo.ptr)) == typeid(immutable(char)*)); |
| 678 |
} |
| 679 |
|
| 680 |
/**************************************/ |
| 681 |
|
| 682 |
class Qwert32 |
| 683 |
{ |
| 684 |
struct |
| 685 |
{ |
| 686 |
int yuiop = 13; |
| 687 |
} |
| 688 |
int asdfg = 42; |
| 689 |
|
| 690 |
void foo() |
| 691 |
{ |
| 692 |
printf("yuiop = %zd, asdfg = %zd\n", Qwert32.yuiop.offsetof, Qwert32.asdfg.offsetof); |
| 693 |
version(D_LP64) |
| 694 |
{ |
| 695 |
assert(Qwert32.yuiop.offsetof == 16); |
| 696 |
assert(Qwert32.asdfg.offsetof == 20); |
| 697 |
} |
| 698 |
else |
| 699 |
{ |
| 700 |
assert(Qwert32.yuiop.offsetof == 8); |
| 701 |
assert(Qwert32.asdfg.offsetof == 12); |
| 702 |
} |
| 703 |
} |
| 704 |
} |
| 705 |
|
| 706 |
void test32() |
| 707 |
{ |
| 708 |
Qwert32 q = new Qwert32; |
| 709 |
|
| 710 |
q.foo(); |
| 711 |
} |
| 712 |
|
| 713 |
|
| 714 |
/**************************************/ |
| 715 |
|
| 716 |
int x33; |
| 717 |
int y33; |
| 718 |
|
| 719 |
size_t os_query() |
| 720 |
{ |
| 721 |
return cast(uint)(cast(char *)&x33 - cast(char *)&y33); |
| 722 |
} |
| 723 |
|
| 724 |
void test33() |
| 725 |
{ |
| 726 |
os_query(); |
| 727 |
} |
| 728 |
|
| 729 |
/**************************************/ |
| 730 |
|
| 731 |
uint x34 = ~(16u-1u); |
| 732 |
uint y34 = ~(16u-1); |
| 733 |
|
| 734 |
void test34() |
| 735 |
{ |
| 736 |
assert(x34 == 0xFFFFFFF0); |
| 737 |
assert(y34 == 0xFFFFFFF0); |
| 738 |
} |
| 739 |
|
| 740 |
/**************************************/ |
| 741 |
|
| 742 |
private static extern (C) |
| 743 |
{ |
| 744 |
shared char* function () uloc_getDefault; |
| 745 |
} |
| 746 |
|
| 747 |
|
| 748 |
static shared void**[] targets = |
| 749 |
[ |
| 750 |
cast(shared(void*)*) &uloc_getDefault, |
| 751 |
]; |
| 752 |
|
| 753 |
void test35() |
| 754 |
{ |
| 755 |
} |
| 756 |
|
| 757 |
/**************************************/ |
| 758 |
|
| 759 |
class S36 |
| 760 |
{ |
| 761 |
int s = 1; |
| 762 |
|
| 763 |
this() |
| 764 |
{ |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
class A36 : S36 |
| 770 |
{ |
| 771 |
int a = 2; |
| 772 |
int b = 3; |
| 773 |
int c = 4; |
| 774 |
int d = 5; |
| 775 |
} |
| 776 |
|
| 777 |
void test36() |
| 778 |
{ |
| 779 |
A36 a = new A36; |
| 780 |
|
| 781 |
printf("A36.sizeof = %zd\n", a.classinfo.initializer.length); |
| 782 |
printf("%d\n", a.s); |
| 783 |
printf("%d\n", a.a); |
| 784 |
printf("%d\n", a.b); |
| 785 |
printf("%d\n", a.c); |
| 786 |
printf("%d\n", a.d); |
| 787 |
|
| 788 |
version(D_LP64) |
| 789 |
assert(a.classinfo.initializer.length == 36); |
| 790 |
else |
| 791 |
assert(a.classinfo.initializer.length == 28); |
| 792 |
assert(a.s == 1); |
| 793 |
assert(a.a == 2); |
| 794 |
assert(a.b == 3); |
| 795 |
assert(a.c == 4); |
| 796 |
assert(a.d == 5); |
| 797 |
} |
| 798 |
|
| 799 |
|
| 800 |
/**************************************/ |
| 801 |
|
| 802 |
struct MyStruct |
| 803 |
{ |
| 804 |
StructAlias* MyStruct() |
| 805 |
{ |
| 806 |
return null; |
| 807 |
} |
| 808 |
} |
| 809 |
|
| 810 |
alias MyStruct StructAlias; |
| 811 |
|
| 812 |
void test37() |
| 813 |
{ |
| 814 |
} |
| 815 |
|
| 816 |
/**************************************/ |
| 817 |
|
| 818 |
class Foo38 |
| 819 |
{ |
| 820 |
static void display_name() |
| 821 |
{ |
| 822 |
printf("%.*s\n", cast(int)Object.classinfo.name.length, Object.classinfo.name.ptr); |
| 823 |
assert(Object.classinfo.name == "object.Object"); |
| 824 |
assert(super.classinfo.name == "object.Object"); |
| 825 |
assert(this.classinfo.name == "test12.Foo38"); |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
void test38() |
| 830 |
{ |
| 831 |
Foo38.display_name(); |
| 832 |
} |
| 833 |
|
| 834 |
|
| 835 |
/**************************************/ |
| 836 |
// https://www.digitalmars.com/d/archives/digitalmars/D/bugs/2409.html |
| 837 |
|
| 838 |
class C39 |
| 839 |
{ |
| 840 |
C39 c; |
| 841 |
this() { c = this; } |
| 842 |
C39 lock() { return c; } |
| 843 |
} |
| 844 |
|
| 845 |
void test39() |
| 846 |
{ |
| 847 |
C39 c = new C39(); |
| 848 |
synchronized( c.lock() ) {} |
| 849 |
synchronized( c.lock ) {} |
| 850 |
} |
| 851 |
|
| 852 |
|
| 853 |
/**************************************/ |
| 854 |
|
| 855 |
class C40 |
| 856 |
{ |
| 857 |
static int x = 4; |
| 858 |
|
| 859 |
static int foo() |
| 860 |
{ |
| 861 |
return this.x; |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
void test40() |
| 866 |
{ |
| 867 |
C40 c = new C40(); |
| 868 |
assert(C40.foo() == 4); |
| 869 |
} |
| 870 |
|
| 871 |
|
| 872 |
/**************************************/ |
| 873 |
|
| 874 |
struct Foo42 |
| 875 |
{ |
| 876 |
Bar42 b; |
| 877 |
} |
| 878 |
|
| 879 |
struct Bar42 |
| 880 |
{ |
| 881 |
long a; |
| 882 |
} |
| 883 |
|
| 884 |
void test42() |
| 885 |
{ |
| 886 |
assert(Bar42.sizeof == long.sizeof); |
| 887 |
assert(Foo42.sizeof == long.sizeof); |
| 888 |
} |
| 889 |
|
| 890 |
|
| 891 |
/**************************************/ |
| 892 |
|
| 893 |
class Foo43 |
| 894 |
{ |
| 895 |
Bar43 b; |
| 896 |
} |
| 897 |
|
| 898 |
struct Bar43 |
| 899 |
{ |
| 900 |
long a; |
| 901 |
} |
| 902 |
|
| 903 |
void test43() |
| 904 |
{ |
| 905 |
assert(Bar43.sizeof == long.sizeof); |
| 906 |
assert(Foo43.sizeof == (void*).sizeof); |
| 907 |
} |
| 908 |
|
| 909 |
|
| 910 |
/**************************************/ |
| 911 |
|
| 912 |
struct Property |
| 913 |
{ |
| 914 |
uint attributes; |
| 915 |
|
| 916 |
Value value; |
| 917 |
} |
| 918 |
|
| 919 |
struct Value |
| 920 |
{ |
| 921 |
int a,b,c,d; |
| 922 |
} |
| 923 |
|
| 924 |
struct PropTable |
| 925 |
{ |
| 926 |
Property[Value] table; |
| 927 |
PropTable* previous; |
| 928 |
|
| 929 |
Value* get(Value* key) |
| 930 |
{ |
| 931 |
Property *p; |
| 932 |
|
| 933 |
p = *key in table; |
| 934 |
p = &table[*key]; |
| 935 |
table.remove(*key); |
| 936 |
return null; |
| 937 |
} |
| 938 |
|
| 939 |
} |
| 940 |
|
| 941 |
void test44() |
| 942 |
{ |
| 943 |
} |
| 944 |
|
| 945 |
|
| 946 |
/**************************************/ |
| 947 |
|
| 948 |
struct Shell |
| 949 |
{ |
| 950 |
string str; |
| 951 |
|
| 952 |
const int opCmp(ref const Shell s) |
| 953 |
{ |
| 954 |
// Obviously not Unicode-aware... |
| 955 |
foreach (const i, const a; this.str) |
| 956 |
{ |
| 957 |
const b = s.str[i]; |
| 958 |
if (a < b) return -1; |
| 959 |
if (a > b) return 1; |
| 960 |
} |
| 961 |
|
| 962 |
if (this.str.length < s.str.length) return -1; |
| 963 |
if (this.str.length > s.str.length) return 1; |
| 964 |
return 0; |
| 965 |
} |
| 966 |
} |
| 967 |
|
| 968 |
void test45() |
| 969 |
{ |
| 970 |
Shell a = Shell("hello"); |
| 971 |
Shell b = Shell("betty"); |
| 972 |
Shell c = Shell("fred"); |
| 973 |
|
| 974 |
assert(a > b); |
| 975 |
assert(b < c); |
| 976 |
} |
| 977 |
|
| 978 |
/**************************************/ |
| 979 |
|
| 980 |
class A46 |
| 981 |
{ |
| 982 |
char foo() { return 'a'; } |
| 983 |
} |
| 984 |
|
| 985 |
class B46 : A46 |
| 986 |
{ |
| 987 |
} |
| 988 |
|
| 989 |
class C46 : B46 |
| 990 |
{ |
| 991 |
override char foo() { return 'c'; } |
| 992 |
char bar() |
| 993 |
{ |
| 994 |
return B46.foo(); |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
void test46() |
| 999 |
{ |
| 1000 |
C46 c = new C46(); |
| 1001 |
|
| 1002 |
assert(c.bar() == 'a'); |
| 1003 |
printf("%c\n", c.bar()); |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
/**************************************/ |
| 1008 |
|
| 1009 |
class Foo47 |
| 1010 |
{ |
| 1011 |
static bool prop() { return false; } |
| 1012 |
static string charprop() { return null; } |
| 1013 |
} |
| 1014 |
|
| 1015 |
void test47() |
| 1016 |
{ |
| 1017 |
if (0 || Foo47.prop) { } |
| 1018 |
if (1 && Foo47.prop) { } |
| 1019 |
switch (Foo47.prop) { default: break; } |
| 1020 |
foreach (char ch; Foo47.charprop) { } |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
/**************************************/ |
| 1025 |
|
| 1026 |
struct foo48 |
| 1027 |
{ |
| 1028 |
int x, y, z; |
| 1029 |
} |
| 1030 |
|
| 1031 |
void bar48() {} |
| 1032 |
|
| 1033 |
void test48() |
| 1034 |
{ |
| 1035 |
foo48[] arr; |
| 1036 |
foreach(foo48 a; arr) |
| 1037 |
{ |
| 1038 |
bar48(); |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
|
| 1043 |
/**************************************/ |
| 1044 |
|
| 1045 |
enum E49; |
| 1046 |
|
| 1047 |
void test49() |
| 1048 |
{ |
| 1049 |
} |
| 1050 |
|
| 1051 |
/**************************************/ |
| 1052 |
|
| 1053 |
void test50() |
| 1054 |
{ |
| 1055 |
S50!() s; |
| 1056 |
assert(s.i == int.sizeof); |
| 1057 |
} |
| 1058 |
|
| 1059 |
struct S50() |
| 1060 |
{ |
| 1061 |
int i=f50(0).sizeof; |
| 1062 |
} |
| 1063 |
|
| 1064 |
int f50(...); |
| 1065 |
|
| 1066 |
/**************************************/ |
| 1067 |
|
| 1068 |
enum Enum51 |
| 1069 |
{ |
| 1070 |
A, |
| 1071 |
B, |
| 1072 |
C |
| 1073 |
} |
| 1074 |
|
| 1075 |
struct Struct51 |
| 1076 |
{ |
| 1077 |
Enum51 e; |
| 1078 |
} |
| 1079 |
|
| 1080 |
void test51() |
| 1081 |
{ |
| 1082 |
Struct51 s; |
| 1083 |
assert(s.e == Enum51.A); |
| 1084 |
assert(s.e == 0); |
| 1085 |
} |
| 1086 |
|
| 1087 |
/**************************************/ |
| 1088 |
|
| 1089 |
bool foo52() |
| 1090 |
{ |
| 1091 |
int x; |
| 1092 |
for (;;) { |
| 1093 |
if (x == 0) |
| 1094 |
return true; |
| 1095 |
x = 1; |
| 1096 |
} |
| 1097 |
return false; |
| 1098 |
} |
| 1099 |
|
| 1100 |
void test52() |
| 1101 |
{ |
| 1102 |
foo52(); |
| 1103 |
} |
| 1104 |
|
| 1105 |
/**************************************/ |
| 1106 |
|
| 1107 |
void foo53() |
| 1108 |
{ |
| 1109 |
ret:{} |
| 1110 |
goto ret; |
| 1111 |
} |
| 1112 |
|
| 1113 |
void test53() |
| 1114 |
{ |
| 1115 |
} |
| 1116 |
|
| 1117 |
/**************************************/ |
| 1118 |
|
| 1119 |
struct V54 |
| 1120 |
{ |
| 1121 |
int x = 3; |
| 1122 |
} |
| 1123 |
|
| 1124 |
class Foo54 |
| 1125 |
{ |
| 1126 |
static int y; |
| 1127 |
static V54 prop() { V54 val; return val; } |
| 1128 |
static void prop(V54 val) { y = val.x * 2; } |
| 1129 |
} |
| 1130 |
|
| 1131 |
void test54() |
| 1132 |
{ |
| 1133 |
(new Foo54).prop = true ? Foo54.prop : Foo54.prop; |
| 1134 |
assert(Foo54.y == 6); |
| 1135 |
} |
| 1136 |
|
| 1137 |
/**************************************/ |
| 1138 |
|
| 1139 |
void test55() |
| 1140 |
{ |
| 1141 |
dchar c; |
| 1142 |
|
| 1143 |
c = 'x'; |
| 1144 |
//writefln("c = '%s', c.init = '%s'", c, c.init); |
| 1145 |
assert(c == 'x'); |
| 1146 |
assert(c.init == dchar.init); |
| 1147 |
} |
| 1148 |
|
| 1149 |
/**************************************/ |
| 1150 |
|
| 1151 |
void writefln(string s) |
| 1152 |
{ |
| 1153 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 1154 |
} |
| 1155 |
|
| 1156 |
void test58() |
| 1157 |
{ |
| 1158 |
int label=1; |
| 1159 |
if (0) |
| 1160 |
{ |
| 1161 |
label: |
| 1162 |
int label2=2; |
| 1163 |
assert(label2==2); |
| 1164 |
} |
| 1165 |
else |
| 1166 |
{ |
| 1167 |
assert(label==1); |
| 1168 |
goto label; |
| 1169 |
} |
| 1170 |
assert(label==1); |
| 1171 |
} |
| 1172 |
|
| 1173 |
/**************************************/ |
| 1174 |
|
| 1175 |
void test59() |
| 1176 |
{ |
| 1177 |
if(0){ |
| 1178 |
label: |
| 1179 |
return; |
| 1180 |
}else{ |
| 1181 |
goto label; |
| 1182 |
} |
| 1183 |
assert(0); |
| 1184 |
} |
| 1185 |
|
| 1186 |
/**************************************/ |
| 1187 |
|
| 1188 |
int main(string[] argv) |
| 1189 |
{ |
| 1190 |
test1(); |
| 1191 |
test2(); |
| 1192 |
test3(); |
| 1193 |
test4(); |
| 1194 |
test5(); |
| 1195 |
test6(); |
| 1196 |
test7(); |
| 1197 |
test8(); |
| 1198 |
test9(); |
| 1199 |
test10(); |
| 1200 |
test11(); |
| 1201 |
test12(); |
| 1202 |
test13(); |
| 1203 |
test14(); |
| 1204 |
test15(); |
| 1205 |
test16(); |
| 1206 |
test17(); |
| 1207 |
test18(); |
| 1208 |
test19(); |
| 1209 |
test20(); |
| 1210 |
test21(); |
| 1211 |
test22(); |
| 1212 |
test23(); |
| 1213 |
test24(); |
| 1214 |
test25(); |
| 1215 |
test26(); |
| 1216 |
test27(); |
| 1217 |
test28(); |
| 1218 |
test29(); |
| 1219 |
test30(); |
| 1220 |
test31(); |
| 1221 |
test32(); |
| 1222 |
test33(); |
| 1223 |
test34(); |
| 1224 |
test35(); |
| 1225 |
test36(); |
| 1226 |
test37(); |
| 1227 |
test38(); |
| 1228 |
test39(); |
| 1229 |
test40(); |
| 1230 |
test42(); |
| 1231 |
test43(); |
| 1232 |
test44(); |
| 1233 |
test45(); |
| 1234 |
test46(); |
| 1235 |
test47(); |
| 1236 |
test48(); |
| 1237 |
test49(); |
| 1238 |
test50(); |
| 1239 |
test51(); |
| 1240 |
test52(); |
| 1241 |
test53(); |
| 1242 |
test54(); |
| 1243 |
test55(); |
| 1244 |
test58(); |
| 1245 |
test59(); |
| 1246 |
|
| 1247 |
printf("Success\n"); |
| 1248 |
return 0; |
| 1249 |
} |