1 /** 2 Github issues. 3 */ 4 module it.issues; 5 6 import it; 7 8 @Tags("issue") 9 @("3") 10 @safe unittest { 11 shouldCompile( 12 C( 13 ` 14 #include <signal.h> 15 ` 16 ), 17 D( 18 q{ 19 siginfo_t si; 20 si._sifields._timer.si_tid = 2; 21 static assert(is(typeof(si.si_signo) == int)); 22 static assert(is(typeof(si._sifields._timer.si_tid) == int), 23 typeof(si._sifields._timer.si_tid).stringof); 24 } 25 ), 26 ); 27 } 28 29 30 @Tags("issue") 31 @("4") 32 @safe unittest { 33 with(immutable IncludeSandbox()) { 34 writeFile("issue4.h", 35 q{ 36 extern char *arr[9]; 37 }); 38 writeFile("issue4.dpp", 39 ` 40 #include "issue4.h" 41 `); 42 runPreprocessOnly("issue4.dpp"); 43 fileShouldContain("issue4.d", q{extern __gshared char*[9] arr;}); 44 } 45 } 46 47 @Tags("issue") 48 @("5") 49 @safe unittest { 50 shouldCompile( 51 C( 52 q{ 53 typedef enum zfs_error { 54 EZFS_SUCCESS = 0, 55 EZFS_NOMEM = 2000, 56 }; 57 58 typedef struct zfs_perm_node { 59 char z_pname[4096]; 60 } zfs_perm_node_t; 61 62 typedef struct libzfs_handle libzfs_handle_t; 63 } 64 ), 65 D( 66 q{ 67 zfs_error e1 = EZFS_SUCCESS; 68 zfs_error e2 = zfs_error.EZFS_SUCCESS; 69 zfs_perm_node_t node; 70 static assert(node.z_pname.sizeof == 4096); 71 static assert(is(typeof(node.z_pname[0]) == char), (typeof(node.z_pname[0]).stringof)); 72 libzfs_handle_t* ptr; 73 } 74 ), 75 ); 76 } 77 78 @Tags("issue") 79 @("6") 80 @safe unittest { 81 with(immutable IncludeSandbox()) { 82 writeFile("issue6.h", 83 q{ 84 char *getMessage(); 85 }); 86 writeFile("issue6.dpp", 87 ` 88 #include "issue6.h" 89 `); 90 runPreprocessOnly("issue6.dpp"); 91 fileShouldContain("issue6.d", q{char* getMessage() @nogc nothrow;}); 92 } 93 } 94 95 96 @Tags("issue", "bitfield") 97 @("7") 98 @safe unittest { 99 shouldCompile( 100 C( 101 q{ 102 struct splitflags { 103 int dryrun : 1; 104 int import : 2; 105 int name_flags; 106 int foo: 3; 107 int bar: 4; 108 int suffix; 109 }; 110 111 struct other { 112 int quux: 2; 113 int toto: 3; 114 }; 115 } 116 ), 117 D( 118 q{ 119 static assert(splitflags.sizeof == 16); 120 static assert(other.sizeof == 4); 121 } 122 ), 123 ); 124 } 125 126 @Tags("issue") 127 @("10") 128 @safe unittest { 129 shouldCompile( 130 C( 131 q{ 132 enum silly_name { 133 FOO, 134 BAR, 135 BAZ, 136 }; 137 138 extern void silly_name(enum silly_name thingie); 139 } 140 ), 141 D( 142 q{ 143 silly_name_(silly_name.FOO); 144 } 145 ), 146 ); 147 } 148 149 @Tags("issue") 150 @("11") 151 @safe unittest { 152 shouldCompile( 153 C( 154 q{ 155 struct Foo; 156 typedef struct Foo* FooPtr; 157 } 158 ), 159 D( 160 q{ 161 FooPtr f = null; 162 static assert(!__traits(compiles, Foo())); 163 } 164 ), 165 ); 166 } 167 168 @Tags("issue") 169 @("14") 170 @safe unittest { 171 import dpp.runtime.options: Options; 172 with(immutable IncludeSandbox()) { 173 174 writeFile("foo.h", 175 q{ 176 typedef int foo; 177 }); 178 179 runPreprocessOnly("foo.h").shouldThrowWithMessage( 180 "No .dpp input file specified\n" ~ Options.usage); 181 } 182 } 183 184 @Tags("issue", "preprocessor") 185 @("22.0") 186 @safe unittest { 187 shouldCompile( 188 C( 189 ` 190 typedef struct { 191 #ifdef __USE_XOPEN 192 int fds_bits[42]; 193 #define __FDS_BITS(set) ((set)->fds_bits) 194 #else 195 int __fds_bits[42]; 196 #define __FDS_BITS(set) ((set)->__fds_bits) 197 #endif 198 } fd_set; 199 ` 200 ), 201 D( 202 q{ 203 fd_set set; 204 __FDS_BITS(set)[0] = 42; 205 } 206 ), 207 ); 208 } 209 210 @Tags("issue", "preprocessor") 211 @("22.1") 212 @safe unittest { 213 shouldCompile( 214 C( 215 ` 216 #define SIZEOF(x) (sizeof(x)) 217 ` 218 ), 219 D( 220 q{ 221 int i; 222 static assert(SIZEOF(i) == 4); 223 } 224 ), 225 ); 226 } 227 228 @Tags("issue", "preprocessor") 229 @("22.3") 230 @safe unittest { 231 shouldCompile( 232 C( 233 ` 234 typedef long int __fd_mask; 235 #define __NFDBITS (8 * (int) sizeof (__fd_mask)) 236 ` 237 ), 238 D( 239 q{ 240 import std.conv; 241 static assert(__NFDBITS == 8 * c_long.sizeof, 242 text("expected ", 8 * c_long.sizeof, ", got: ", __NFDBITS)); 243 } 244 ), 245 ); 246 } 247 248 @Tags("issue", "preprocessor") 249 @("22.4") 250 @safe unittest { 251 shouldCompile( 252 C( 253 ` 254 typedef struct clist { struct list* next; }; 255 #define clist_next(iter) (iter ? (iter)->next : NULL) 256 ` 257 ), 258 D( 259 q{ 260 clist l; 261 auto next = clist_next(&l); 262 } 263 ), 264 ); 265 } 266 267 268 269 @Tags("issue", "collision", "issue24") 270 @("24.0") 271 @safe unittest { 272 shouldCompile( 273 C( 274 q{ 275 struct Bar { 276 void (*Foo)(void); // this should get renamed as Foo_ 277 struct Foo* (*whatever)(void); 278 }; 279 } 280 ), 281 D( 282 q{ 283 } 284 ), 285 ); 286 } 287 288 @Tags("issue", "collision", "issue24") 289 @("24.1") 290 @safe unittest { 291 shouldCompile( 292 C( 293 q{ 294 int foo(int, struct foo_data**); 295 struct foo { int dummy; }; 296 struct foo_data { int dummy; }; 297 } 298 ), 299 D( 300 q{ 301 foo_data** data; 302 int ret = foo_(42, data); 303 foo s; 304 s.dummy = 33; 305 foo_data fd; 306 fd.dummy = 77; 307 } 308 ), 309 ); 310 } 311 312 313 @Tags("issue") 314 @("29.0") 315 @safe unittest { 316 shouldCompile( 317 C( 318 q{ 319 typedef struct { 320 union { 321 struct { 322 double x; 323 double y; 324 double z; 325 }; 326 double raw[3]; 327 }; 328 } vec3d_t; 329 } 330 ), 331 D( 332 q{ 333 vec3d_t v; 334 static assert(v.sizeof == 24); 335 v.raw[1] = 3.0; 336 v.y = 4.0; 337 } 338 ), 339 ); 340 } 341 342 @Tags("issue") 343 @("29.1") 344 @safe unittest { 345 shouldCompile( 346 C( 347 q{ 348 typedef struct { 349 struct { 350 int x; 351 int y; 352 }; 353 354 struct { 355 int z; 356 }; 357 } Struct; 358 } 359 ), 360 D( 361 q{ 362 Struct s; 363 s.x = 2; 364 s.y = 3; 365 s.z = 4; 366 } 367 ), 368 ); 369 } 370 371 @Tags("issue") 372 @("29.2") 373 @safe unittest { 374 shouldCompile( 375 C( 376 q{ 377 struct Struct { 378 union { 379 unsigned long long int foo; 380 struct { 381 unsigned int low; 382 unsigned int high; 383 } foo32; 384 }; 385 }; 386 } 387 ), 388 D( 389 q{ 390 Struct s; 391 s.foo = 42; 392 s.foo32.low = 33; 393 s.foo32.high = 77; 394 } 395 ), 396 ); 397 } 398 399 400 @Tags("issue") 401 @("29.3") 402 @safe unittest { 403 shouldCompile( 404 C( 405 q{ 406 struct Struct { 407 union { 408 unsigned long long int foo; 409 void *bar; 410 }; 411 }; 412 } 413 ), 414 D( 415 q{ 416 Struct s; 417 s.foo = 42; 418 s.bar = null; 419 } 420 ), 421 ); 422 } 423 424 425 @Tags("issue") 426 @("33.0") 427 @safe unittest { 428 shouldCompile( 429 C( 430 q{ 431 void (*f)(); 432 } 433 ), 434 D( 435 q{ 436 static extern(C) void printHello() { } 437 f = &printHello; 438 f(); 439 } 440 ), 441 ); 442 } 443 444 @Tags("issue") 445 @("33.1") 446 @safe unittest { 447 shouldCompile( 448 C( 449 q{ 450 int (*f)(); 451 } 452 ), 453 D( 454 q{ 455 static extern(C) int func() { return 42; } 456 f = &func; 457 int i = f(); 458 } 459 ), 460 ); 461 } 462 463 464 @Tags("issue", "bitfield") 465 @("35") 466 @safe unittest { 467 shouldCompile( 468 C( 469 q{ 470 struct Struct { 471 int foo; 472 int bar; 473 int :32; 474 int :31; 475 int :3; 476 int :27; 477 }; 478 } 479 ), 480 D( 481 q{ 482 Struct s; 483 static assert(s.sizeof == 20); 484 } 485 ), 486 ); 487 } 488 489 @Tags("issue") 490 @("37") 491 @safe unittest { 492 shouldCompile( 493 C( 494 ` 495 #include "mmintrin.h" 496 ` 497 ), 498 D( 499 q{ 500 } 501 ), 502 ); 503 } 504 505 506 @Tags("issue", "preprocessor") 507 @("39.0") 508 @safe unittest { 509 shouldCompile( 510 C( 511 ` 512 typedef long value; 513 typedef long intnat; 514 typedef unsigned long uintnat; 515 #define Val_long(x) ((intnat) (((uintnat)(x) << 1)) + 1) 516 #define Long_val(x) ((x) >> 1) 517 #define Val_int(x) Val_long(x) 518 #define Int_val(x) ((int) Long_val(x)) 519 #define Bp_val(v) ((char *) (v)) 520 #define String_val(x) ((const char *) Bp_val(x)) 521 value caml_callback(value, value); 522 char* strdup(const char* val); 523 ` 524 ), 525 D( 526 q{ 527 static value* fib_closure = null; 528 int n; 529 auto val = Int_val(caml_callback(*fib_closure, Val_int(n))); 530 char* str = strdup(String_val(caml_callback(*fib_closure, Val_int(n)))); 531 } 532 ), 533 ); 534 } 535 536 @Tags("issue", "preprocessor") 537 @("39.1") 538 @safe unittest { 539 shouldCompile( 540 C( 541 ` 542 #define VOID_PTR(x) ( void* )(x) 543 ` 544 ), 545 D( 546 q{ 547 auto val = VOID_PTR(42); 548 static assert(is(typeof(val) == void*)); 549 } 550 ), 551 ); 552 } 553 554 @Tags("issue", "preprocessor") 555 @("39.2") 556 @safe unittest { 557 shouldCompile( 558 C( 559 ` 560 typedef int myint; 561 #define CAST(x) ( myint* )(x) 562 ` 563 ), 564 D( 565 q{ 566 auto val = CAST(42); 567 static assert(is(typeof(val) == int*)); 568 } 569 ), 570 ); 571 } 572 573 @Tags("issue", "preprocessor") 574 @("40") 575 @safe unittest { 576 with(immutable IncludeSandbox()) { 577 writeFile("hdr1.h", 578 q{ 579 typedef int myint; 580 }); 581 writeFile("hdr2.h", 582 q{ 583 myint myfunc(void); 584 }); 585 writeFile("src.dpp", 586 ` 587 #include "hdr1.h" 588 #include "hdr2.h" 589 void func() { 590 myint _ = myfunc(); 591 } 592 `); 593 runPreprocessOnly("src.dpp"); 594 shouldCompile("src.d"); 595 } 596 } 597 598 @Tags("issue") 599 @("43") 600 @safe unittest { 601 shouldCompile( 602 C( 603 q{ 604 int binOp(int (f)(int x, int y), int a, int b); 605 int thef(int x, int y); 606 } 607 ), 608 D( 609 q{ 610 binOp(&thef, 2, 3); 611 } 612 ), 613 ); 614 } 615 616 617 @Tags("issue") 618 @("44.1") 619 @safe unittest { 620 shouldCompile( 621 C( 622 ` 623 #define macro(x) (x) + 42 624 ` 625 ), 626 D( 627 q{ 628 static assert(macro_(0) == 42); 629 static assert(macro_(1) == 43); 630 } 631 ), 632 ); 633 } 634 635 @Tags("issue") 636 @("44.2") 637 @safe unittest { 638 shouldCompile( 639 C( 640 ` 641 struct macro { int i }; 642 ` 643 ), 644 D( 645 q{ 646 } 647 ), 648 ); 649 } 650 651 652 @Tags("issue") 653 @("48") 654 @safe unittest { 655 shouldCompile( 656 C( 657 ` 658 #include <stddef.h> 659 struct Struct { 660 volatile int x; 661 volatile size_t y; 662 }; 663 ` 664 ), 665 D( 666 q{ 667 668 } 669 ), 670 ); 671 } 672 673 @Tags("issue", "preprocessor") 674 @("49") 675 @safe unittest { 676 shouldCompile( 677 C( 678 ` 679 #define func() ((void)0) 680 void (func)(void); 681 ` 682 ), 683 D( 684 q{ 685 // it gets renamed 686 func_(); 687 } 688 ), 689 ); 690 } 691 692 @Tags("issue") 693 @("53") 694 @safe unittest { 695 shouldCompile( 696 C( 697 q{ 698 typedef int bool; 699 } 700 ), 701 D( 702 q{ 703 704 } 705 ), 706 ); 707 } 708 709 @Tags("issue", "enum") 710 @("54") 711 @safe unittest { 712 shouldCompile( 713 C( 714 q{ 715 enum { 716 SUCCESS, 717 }; 718 typedef int boolean; 719 } 720 ), 721 D( 722 q{ 723 static assert(SUCCESS == 0); 724 } 725 ), 726 ); 727 } 728 729 730 @Tags("issue") 731 @("66") 732 @safe unittest { 733 shouldCompile( 734 C( 735 ` 736 #include <linux/ethtool.h> 737 ` 738 ), 739 D( 740 q{ 741 } 742 ), 743 ); 744 } 745 746 @Tags("issue") 747 @("77") 748 @safe unittest { 749 with(immutable IncludeSandbox()) { 750 writeFile("hdr.h", ""); 751 writeFile("app.dpp", 752 ` 753 module mymodule; 754 #include "hdr.h" 755 void main() { 756 static assert(__MODULE__ == "mymodule"); 757 } 758 `); 759 runPreprocessOnly("app.dpp"); 760 shouldCompile("app.d"); 761 } 762 } 763 764 @Tags("issue") 765 @("79") 766 unittest { 767 with(const IncludeSandbox()) { 768 writeHeaderAndApp("1st.h", 769 ` 770 #include "2nd.h" 771 #define BAR 33 772 `, 773 D(""), // no need for .dpp source code 774 ); 775 writeFile("2nd.h", 776 ` 777 // these empty lines are important, since they push the enum 778 // declaration down to have a higher line number than the BAR macro. 779 enum TheEnum { BAR = 42 }; 780 `); 781 run("-c", inSandboxPath("app.dpp")); 782 } 783 }