1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908
|
// PERMUTE_ARGS: -inline
/*
TEST_OUTPUT:
---
compilable/interpret3.d(6350): Deprecation: identity comparison of static arrays implicitly coerces them to slices, which are compared by reference
---
*/
template compiles(int T)
{
bool compiles = true;
}
alias TypeTuple(T...) = T;
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=3901
// Arbitrary struct assignment, ref return
struct ArrayRet
{
int x;
}
int arrayRetTest(int z)
{
ArrayRet[6] w;
int q = (w[3].x = z);
return q;
}
static assert(arrayRetTest(51) == 51);
// https://issues.dlang.org/show_bug.cgi?id=3842 -- must not segfault
int ice3842(int z)
{
ArrayRet w;
return arrayRetTest((*(&w)).x);
}
static assert(true || is(typeof(compiles!(ice3842(51)))));
int arrayret2()
{
int[5] a;
int[3] b;
b[] = a[1 .. $-1] = 5;
return b[1];
}
static assert(arrayret2() == 5);
struct DotVarTest
{
ArrayRet z;
}
struct DotVarTest2
{
ArrayRet z;
DotVarTest p;
}
int dotvar1()
{
DotVarTest w;
w.z.x = 3;
return w.z.x;
}
static assert(dotvar1() == 3);
int dotvar2()
{
DotVarTest2[4] m;
m[2].z.x = 3;
m[1].p.z.x = 5;
return m[2].z.x + 7;
}
static assert(dotvar2() == 10);
struct RetRefStruct
{
int x;
char c;
}
// Return value reference tests, for D2 only.
ref RetRefStruct reffunc1(return ref RetRefStruct a)
{
int y = a.x;
return a;
}
ref RetRefStruct reffunc2(return ref RetRefStruct a)
{
RetRefStruct z = a;
return reffunc1(a);
}
ref int reffunc7(return ref RetRefStruct aa)
{
return reffunc1(aa).x;
}
ref int reffunc3(return ref int a)
{
return a;
}
struct RefTestStruct
{
RetRefStruct r;
ref RefTestStruct reffunc4(ref RetRefStruct[3] a) return
{
return this;
}
ref int reffunc6() return
{
return this.r.x;
}
}
ref RetRefStruct reffunc5(return ref RetRefStruct[3] a)
{
int t = 1;
for (int i = 0; i < 10; ++i)
{
if (i == 7)
++t;
}
return a[reffunc3(t)];
}
int retRefTest1()
{
RetRefStruct b = RetRefStruct(0, 'a');
reffunc1(b).x = 3;
return b.x - 1;
}
int retRefTest2()
{
RetRefStruct b = RetRefStruct(0, 'a');
reffunc2(b).x = 3;
RetRefStruct[3] z;
RefTestStruct w;
w.reffunc4(z).reffunc4(z).r.x = 4;
assert(w.r.x == 4);
w.reffunc6() = 218;
assert(w.r.x == 218);
z[2].x = 3;
int q = 4;
int u = reffunc5(z).x + reffunc3(q);
assert(u == 7);
reffunc5(z).x += 7;
assert(z[2].x == 10);
RetRefStruct m = RetRefStruct(7, 'c');
m.x = 6;
reffunc7(m) += 3;
assert(m.x == 9);
return b.x - 1;
}
int retRefTest3()
{
RetRefStruct b = RetRefStruct(0, 'a');
auto deleg = function (RetRefStruct a){ return a; };
typeof(deleg)[3] z;
z[] = deleg;
auto y = deleg(b).x + 27;
b.x = 5;
assert(y == 27);
y = z[1](b).x + 22;
return y - 1;
}
int retRefTest4()
{
RetRefStruct b = RetRefStruct(0, 'a');
reffunc3(b.x) = 218;
assert(b.x == 218);
return b.x;
}
static assert(retRefTest1() == 2);
static assert(retRefTest2() == 2);
static assert(retRefTest3() == 26);
static assert(retRefTest4() == 218);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7887
// assign to returned reference
bool test7887()
{
ref int f(ref int x) { return x; }
int a;
f(a) = 42;
return (a == 42);
}
static assert(test7887());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7473
// struct non-ref
struct S7473
{
int i;
}
static assert({
S7473 s = S7473(1);
assert(s.i == 1);
bug7473(s);
assert(s.i == 1);
return true;
}());
void bug7473(S7473 s)
{
s.i = 2;
}
struct S7473b
{
S7473 m;
}
static assert({
S7473b s = S7473b(S7473(7));
assert(s.m.i == 7);
bug7473b(s);
assert(s.m.i == 7);
return true;
}());
void bug7473b(S7473b s)
{
s.m.i = 2;
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4389
int bug4389()
{
string s;
dchar c = '\u2348';
s ~= c;
assert(s.length == 3);
dchar d = 'D';
s ~= d;
assert(s.length == 4);
s = "";
s ~= c;
assert(s.length == 3);
s ~= d;
assert(s.length == 4);
string z;
wchar w = '\u0300';
z ~= w;
assert(z.length == 2);
z = "";
z ~= w;
assert(z.length == 2);
return 1;
}
static assert(bug4389());
// ICE(constfold.c)
int ice4389()
{
string s;
dchar c = '\u2348';
s ~= c;
s = s ~ "xxx";
return 1;
}
static assert(ice4389());
// ICE(expression.c)
string ice4390()
{
string s;
dchar c = '`';
s ~= c;
s ~= c;
return s;
}
static assert(mixin(ice4390()) == ``);
// https://issues.dlang.org/show_bug.cgi?id=5248
// (D1 + D2)
struct Leaf5248
{
string Compile_not_ovloaded()
{
return "expression";
}
}
struct Matrix5248
{
Leaf5248 Right;
string Compile()
{
return Right.Compile_not_ovloaded();
}
};
static assert(Matrix5248().Compile());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4837
// >>>=
bool bug4837()
{
ushort x = 0x89AB;
x >>>= 4;
assert(x == 0x89A);
byte y = 0x7C;
y >>>= 2;
assert(y == 0x1F);
return true;
}
static assert(bug4837());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10252
// shift out of range
int lshr10252(int shift)
{
int a = 5;
return a << shift;
}
int rshr10252(int shift)
{
int a = 5;
return a >> shift;
}
int ushr10252(int shift)
{
int a = 5;
return a >>> shift;
}
static assert( is(typeof(compiles!(lshr10252( 4)))));
static assert(!is(typeof(compiles!(lshr10252(60)))));
static assert( is(typeof(compiles!(rshr10252( 4)))));
static assert(!is(typeof(compiles!(rshr10252(80)))));
static assert( is(typeof(compiles!(ushr10252( 2)))));
static assert(!is(typeof(compiles!(ushr10252(60)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=1982
// CTFE null problems
enum a1982 = [1, 2, 3];
static assert(a1982 !is null);
string foo1982() { return null; }
static assert(foo1982() is null);
static assert(!foo1982().length);
static assert(null is null);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7988
// CTFE return values should be allowed in compile-time expressions
class X7988 { int y; this() { y = 2; } }
static assert((new X7988).y == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8253
// ICE: calling of member function of non-CTFE class variable
class Bug8253
{
bool j()
{
return true;
}
}
Bug8253 m8253;
static assert(!is(typeof(compiles!(m8253.j()))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8285
// Issue with slice returned from CTFE function
string foo8285()
{
string s = "ab";
return s[0 .. $];
}
template T8285b(string s) { }
template T8285a()
{
enum s = foo8285();
alias T8285b!(s) t2;
}
int bar8285()
{
alias T8285a!() t1;
return 0;
}
int baz8285(int x)
{
return 0;
}
static assert(baz8285(bar8285()) == 0);
// test case 2
string xbar8285()
{
string s = "ab";
return s[0 .. $];
}
template xT8285a()
{
enum xT8285a = xbar8285()[0 .. $];
}
string xbaz8285()
{
return xT8285a!();
}
string xfoo8285(string s)
{
return s;
}
static assert(xfoo8285(xbaz8285()) == "ab");
/**************************************************
'this' parameter bug revealed during refactoring
**************************************************/
int thisbug1(int x) { return x; }
struct ThisBug1
{
int m = 1;
int wut()
{
return thisbug1(m);
}
}
int thisbug2()
{
ThisBug1 spec;
return spec.wut();
}
static assert(thisbug2());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6972
// ICE with cast()cast()assign
int bug6972()
{
ubyte n = 6;
n /= 2u;
return n;
}
static assert(bug6972() == 3);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6164
size_t bug6164()
{
int[] ctfe2(int n)
{
int[] r = [];
if (n != 0)
r ~= [1] ~ ctfe2(n - 1);
return r;
}
return ctfe2(2).length;
}
static assert(bug6164() == 2);
/**************************************************
Interpreter code coverage tests
**************************************************/
int cov1(int a)
{
a %= 15382;
a /= 5;
a = ~ a;
bool c = (a == 0);
bool b = true && c;
assert(b == 0);
b = false && c;
assert(b == 0);
b = false || c;
assert(b == 0);
a ^= 0x45349;
a = ~ a;
a &= 0xFF3F;
a >>>= 1;
a = a ^ 0x7393;
a = a >> 1;
a = a >>> 1;
a = a | 0x010101;
return a;
}
static assert(cov1(534564) == 71589);
int cov2()
{
int i = 0;
do
{
goto DOLABEL;
DOLABEL:
if (i != 0)
{
goto IFLABEL;
IFLABEL:
switch(i)
{
case 3:
break;
case 6:
goto SWITCHLABEL;
SWITCHLABEL:
i = 27;
goto case 3;
default:
assert(0);
}
return i;
}
i = 6;
} while(true);
return 88; // unreachable
}
static assert(cov2() == 27);
template CovTuple(T...)
{
alias T CovTuple;
}
alias CovTuple!(int, long) TCov3;
int cov3(TCov3 t)
{
TCov3 s;
s = t;
assert(s[0] == 1);
assert(s[1] == 2);
return 7;
}
static assert(cov3(1, 2) == 7);
int badassert1(int z)
{
assert(z == 5, "xyz");
return 1;
}
size_t badslice1(int[] z)
{
return z[0 .. 3].length;
}
size_t badslice2(int[] z)
{
return z[0 .. badassert1(1)].length;
}
size_t badslice3(int[] z)
{
return z[badassert1(1) .. 2].length;
}
static assert(!is(typeof(compiles!(badassert1(67)))));
static assert( is(typeof(compiles!(badassert1(5)))));
static assert(!is(typeof(compiles!(badslice1([1,2])))));
static assert(!is(typeof(compiles!(badslice2([1,2])))));
static assert(!is(typeof(compiles!(badslice3([1,2,3])))));
/*******************************************/
int bug7894()
{
for (int k = 0; k < 2; ++k)
{
goto Lagain;
Lagain:
;
}
int m = 1;
do
{
++m;
goto Ldo;
Ldo: ;
} while (m < 3);
assert(m == 3);
return 1;
}
static assert(bug7894());
/*******************************************/
size_t bug5524(int x, int[] more...)
{
int[0] zz;
assert(zz.length == 0);
return 7 + more.length + x;
}
static assert(bug5524(3) == 10);
// https://issues.dlang.org/show_bug.cgi?id=5722
static assert(("" ~ "\©"[0]).length == 1);
const char[] null5722 = null;
static assert((null5722 ~ "\©"[0]).length == 1);
static assert(("\©"[0] ~ null5722).length == 1);
/*******************************************
* Tests for CTFE Array support.
* https://issues.dlang.org/show_bug.cgi?id=1330
* https://issues.dlang.org/show_bug.cgi?id=3801
* https://issues.dlang.org/show_bug.cgi?id=3835
* https://issues.dlang.org/show_bug.cgi?id=4050
* https://issues.dlang.org/show_bug.cgi?id=4051
* https://issues.dlang.org/show_bug.cgi?id=5147
* and major functionality
*******************************************/
char[] bug1330StringIndex()
{
char[] blah = "foo".dup;
assert(blah == "foo");
char[] s = blah[0 .. 2];
blah[0] = 'h';
assert(s == "ho");
s[0] = 'm';
return blah;
}
static assert(bug1330StringIndex() == "moo");
static assert(bug1330StringIndex() == "moo"); // check we haven't clobbered any string literals
int[] bug1330ArrayIndex()
{
int[] blah = [1,2,3];
int[] s = blah;
s = blah[0 .. 2];
int z = blah[0] = 6;
assert(z == 6);
assert(blah[0] == 6);
assert(s[0] == 6);
assert(s == [6, 2]);
s[1] = 4;
assert(z == 6);
return blah;
}
static assert(bug1330ArrayIndex() == [6, 4, 3]);
static assert(bug1330ArrayIndex() == [6, 4, 3]); // check we haven't clobbered any literals
char[] bug1330StringSliceAssign()
{
char[] blah = "food".dup;
assert(blah == "food");
char[] s = blah[1 .. 4];
blah[0 .. 2] = "hc";
assert(s == "cod");
s[0 .. 2] = ['a', 'b']; // Mix string + array literal
assert(blah == "habd");
s[0 .. 2] = "mq";
return blah;
}
static assert(bug1330StringSliceAssign() == "hmqd");
static assert(bug1330StringSliceAssign() == "hmqd");
int[] bug1330ArraySliceAssign()
{
int[] blah = [1, 2, 3, 4];
int[] s = blah[1 .. 4];
blah[0 .. 2] = [7, 9];
assert(s == [9, 3, 4]);
s[0 .. 2] = [8, 15];
return blah;
}
static assert(bug1330ArraySliceAssign() == [7, 8, 15, 4]);
int[] bug1330ArrayBlockAssign()
{
int[] blah = [1, 2, 3, 4, 5];
int[] s = blah[1 .. 4];
blah[0 .. 2] = 17;
assert(s == [17, 3, 4]);
s[0 .. 2] = 9;
return blah;
}
static assert(bug1330ArrayBlockAssign() == [17, 9, 9, 4, 5]);
char[] bug1330StringBlockAssign()
{
char[] blah = "abcde".dup;
char[] s = blah[1 .. 4];
blah[0 .. 2] = 'x';
assert(s == "xcd");
s[0 .. 2] = 'y';
return blah;
}
static assert(bug1330StringBlockAssign() == "xyyde");
int assignAA(int x)
{
int[int] aa;
int[int] cc = aa;
assert(cc.values.length == 0);
assert(cc.keys.length == 0);
aa[1] = 2;
aa[x] = 6;
int[int] bb = aa;
assert(bb.keys.length == 2);
assert(cc.keys.length == 0); // cc is not affected to aa, because it is null
aa[500] = 65;
assert(bb.keys.length == 3); // but bb is affected by changes to aa
return aa[1] + aa[x];
}
static assert(assignAA(12) == 8);
template Compileable(int z) { bool OK; }
int arraybounds(int j, int k)
{
int[] xxx = [1, 2, 3, 4, 5];
int[] s = xxx[1 .. $];
s = s[j .. k]; // slice of slice
return s[$ - 1];
}
static assert(!is(typeof(Compileable!(arraybounds(1, 14)))));
static assert(!is(typeof(Compileable!(arraybounds(15, 3)))));
static assert(arraybounds(2, 4) == 5);
int arraybounds2(int j, int k)
{
int[] xxx = [1, 2, 3, 4, 5];
int[] s = xxx[j .. k]; // direct slice
return 1;
}
static assert(!is(typeof(Compileable!(arraybounds2(1, 14)))));
static assert(!is(typeof(Compileable!(arraybounds2(15, 3)))));
static assert(arraybounds2(2, 4) == 1);
int bug5147a()
{
int[1][2] a = 37;
return a[0][0];
}
static assert(bug5147a() == 37);
int bug5147b()
{
int[4][2][3][17] a = 37;
return a[0][0][0][0];
}
static assert(bug5147b() == 37);
int setlen()
{
int[][] zzz;
zzz.length = 2;
zzz[0].length = 10;
assert(zzz.length == 2);
assert(zzz[0].length == 10);
assert(zzz[1].length == 0);
return 2;
}
static assert(setlen() == 2);
int[1][1] bug5147()
{
int[1][1] a = 1;
return a;
}
static assert(bug5147() == [[1]]);
enum int[1][1] enum5147 = bug5147();
static assert(enum5147 == [[1]]);
immutable int[1][1] bug5147imm = bug5147();
// Index referencing
int[2][2] indexref1()
{
int[2][2] a = 2;
a[0] = 7;
int[][] b = [null, null];
b[0 .. $] = a[0][0 .. 2];
assert(b[0][0] == 7);
assert(b[0][1] == 7);
int[] w;
w = a[0];
assert(w[0] == 7);
w[0 .. $] = 5;
assert(a[0] != [7, 7]);
assert(a[0] == [5, 5]);
assert(b[0] == [5, 5]);
return a;
}
int[2][2] indexref2()
{
int[2][2] a = 2;
a[0] = 7;
int[][2] b = null;
b[0 .. $] = a[0];
assert(b[0][0] == 7);
assert(b[0][1] == 7);
assert(b == [[7, 7], [7, 7]]);
int[] w;
w = a[0];
assert(w[0] == 7);
w[0 .. $] = 5;
assert(a[0] != [7, 7]);
assert(a[0] == [5, 5]);
assert(b[0] == [5, 5]);
return a;
}
int[2][2] indexref3()
{
int[2][2] a = 2;
a[0]=7;
int[][2] b = [null, null];
b[0 .. $] = a[0];
assert(b[0][0] == 7);
assert(b[0][1] == 7);
int[] w;
w = a[0];
assert(w[0] == 7);
w[0 .. $] = 5;
assert(a[0] != [7, 7]);
assert(a[0] == [5, 5]);
assert(b[0] == [5, 5]);
return a;
}
int[2][2] indexref4()
{
int[2][2] a = 2;
a[0] = 7;
int[][2] b =[[1, 2, 3], [1, 2, 3]]; // wrong code
b[0] = a[0];
assert(b[0][0] == 7);
assert(b[0][1] == 7);
int[] w;
w = a[0]; //[0 .. $];
assert(w[0] == 7);
w[0 .. $] = 5;
assert(a[0] != [7, 7]);
assert(a[0] == [5, 5]);
assert(b[0] == [5, 5]);
return a;
}
static assert(indexref1() == [[5, 5], [2, 2]]);
static assert(indexref2() == [[5, 5], [2, 2]]);
static assert(indexref3() == [[5, 5], [2, 2]]);
static assert(indexref4() == [[5, 5], [2, 2]]);
int staticdynamic()
{
int[2][1] a = 2;
assert(a == [[2, 2]]);
int[][1] b = a[0][0 .. 1];
assert(b[0] == [2]);
auto k = b[0];
auto m = a[0][0 .. 1];
assert(k == [2]);
assert(m == k);
return 0;
}
static assert(staticdynamic() == 0);
int chainassign()
{
int[4] x = 6;
int[] y = new int[4];
auto k = (y[] = (x[] = 2));
return k[0];
}
static assert(chainassign() == 2);
// index assignment
struct S3801
{
char c;
int[3] arr;
this(int x, int y)
{
c = 'x';
arr[0] = x;
arr[1] = y;
}
}
int bug3801()
{
S3801 xxx = S3801(17, 67);
int[] w = xxx.arr;
xxx.arr[1] = 89;
assert(xxx.arr[0] == 17);
assert(w[1] == 89);
assert(w == [17, 89, 0]);
return xxx.arr[1];
}
enum : S3801 { bug3801e = S3801(17, 18) }
static assert(bug3801e.arr == [17, 18, 0]);
immutable S3801 bug3801u = S3801(17, 18);
static assert(bug3801u.arr == [17, 18, 0]);
static assert(bug3801() == 89);
int bug3835()
{
int[4] arr;
arr[] = 19;
arr[0] = 4;
int kk;
foreach (ref el; arr)
{
el += 10;
kk = el;
}
assert(arr[2] == 29);
arr[0] += 3;
return arr[0];
}
static assert(bug3835() == 17);
auto bug5852(const(string) s)
{
string[] r;
r ~= s;
assert(r.length == 1);
return r[0].length;
}
static assert(bug5852("abc") == 3);
// https://issues.dlang.org/show_bug.cgi?id=7217
struct S7217 { int[] arr; }
bool f7217()
{
auto s = S7217();
auto t = s.arr;
return true;
}
static assert(f7217());
/*******************************************
Set array length
*******************************************/
static assert(
{
struct W { int[] z; }
W w;
w.z.length = 2;
assert(w.z.length == 2);
w.z.length = 6;
assert(w.z.length == 6);
return true;
}());
// https://issues.dlang.org/show_bug.cgi?id=7185
// char[].length = n
bool bug7185()
{
auto arr = new char[2];
auto arr2 = new char[2];
arr2[] = "ab";
arr.length = 1;
arr2.length = 7;
assert(arr.length == 1);
assert(arr2.length == 7);
assert(arr2[0 .. 2] == "ab");
return true;
}
static assert(bug7185());
bool bug9908()
{
static const int[3] sa = 1;
return sa == [1, 1, 1];
}
static assert(bug9908());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6934
struct Struct6934
{
int[] x = [1, 2];
}
void bar6934(ref int[] p)
{
p[0] = 12;
assert(p[0] == 12);
p[0 .. 1] = 17;
assert(p[0] == 17);
p = p[1 .. $];
}
int bug6934()
{
Struct6934 q;
bar6934(q.x);
int[][] y = [[2, 5], [3, 6, 8]];
bar6934(y[0]);
return 1;
}
static assert(bug6934());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5671
static assert(['a', 'b'] ~ "c" == "abc");
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8624
int evil8624()
{
long m = 0x1_0000_0000L;
assert(m != 0);
long[] a = [0x1_0000_0000L];
long[] b = [0x4_0000_0000L];
assert(a[] != b[]);
return 1;
}
static assert(evil8624());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8644
// array literal >,<
int bug8644()
{
auto m = "a";
auto z = ['b'];
auto c = "b7";
auto d = ['b', '6'];
assert(m < z);
assert(z > m);
assert(z <= c);
assert(c > z);
assert(c > d);
assert(d >= d);
return true;
}
static assert(bug8644());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6159
struct A6159 {}
static assert({ return A6159.init is A6159.init; }());
static assert({ return [1] is [1]; }());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5685
string bug5685()
{
return "xxx";
}
struct Bug5865
{
void test1()
{
enum file2 = (bug5685())[0 .. $];
}
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6235
// Regression ICE on $ in template
struct Bug6235(R)
{
enum XXX = is(typeof(R.init[0 .. $]) : const ubyte[]);
}
Bug6235!(ubyte[]) bug6235;
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8673
// ICE
enum dollar8673 = [0][(() => $ - 1)()];
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5840
struct Bug5840
{
string g;
int w;
}
int bug5840(int u)
{
// check for clobbering
Bug5840 x = void;
x.w = 4;
x.g = "3gs";
if (u == 1)
bug5840(2);
if (u == 2)
{
x.g = "abc";
x.w = 3465;
}
else
{
assert(x.g == "3gs");
assert(x.w == 4);
}
return 56;
}
static assert(bug5840(1) == 56);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7810
int bug7810()
{
int[1][3] x = void;
x[0] = [2];
x[1] = [7];
assert(x[0][0] == 2);
char[1][3] y = void;
y[0] = "a";
y[1] = "b";
assert(y[0][0] == 'a');
return 1;
}
static assert(bug7810());
struct Bug7810
{
int w;
}
int bug7810b(T)(T[] items...)
{
assert(items[0] == Bug7810(20));
return 42;
}
static assert(bug7810b(Bug7810(20), Bug7810(10)) == 42);
/*******************************************
std.datetime ICE (30 April 2011)
*******************************************/
struct TimeOfDayZ
{
public:
this(int hour) { }
invariant() { }
}
const testTODsThrownZ = TimeOfDayZ(0);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5954
struct Bug5954
{
int x;
this(int xx)
{
this.x = xx;
}
}
void bug5954()
{
enum f = Bug5954(10);
static assert(f.x == 10);
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5972
int bug5972()
{
char[] z = "abc".dup;
char[][] a = [null, null];
a[0] = z[0 .. 2];
char[] b = a[0];
assert(b == "ab");
a[0][1] = 'q';
assert(a[0] == "aq");
assert(b == "aq");
assert(b[1] == 'q');
//a[0][0 .. $ - 1][0 .. $] = a[0][0 .. $ - 1][0 .. $]; // overlap
return 56;
}
static assert(bug5972() == 56);
/*******************************************
2.053beta [CTFE]ICE 'global errors'
*******************************************/
int wconcat(wstring replace)
{
wstring value;
value = "A"w;
value = value ~ replace;
return 1;
}
static assert(wconcat("X"w));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10397
// string concat
static assert(!is(typeof(compiles!("abc" ~ undefined))));
static assert(!is(typeof(compiles!(otherundefined ~ "abc"))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9634
// struct concat
struct Bug9634
{
int raw;
}
bool bug9634()
{
Bug9634[] jr = [Bug9634(42)];
Bug9634[] ir = null ~ jr;
Bug9634[] kr = jr ~ null;
Bug9634[] mr = jr ~ jr;
jr[0].raw = 6;
assert(ir[0].raw == 42);
assert(kr[0].raw == 42);
assert(jr[0].raw == 6);
assert(&mr[0] != &mr[1]);
return true;
}
static assert(bug9634());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4001: A Space Oddity
int space() { return 4001; }
void oddity4001(int q)
{
const int bowie = space();
static assert(space() == 4001);
static assert(bowie == 4001);
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=3779
static const bug3779 = ["123"][0][$ - 1];
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8893
// ICE with bad struct literal
struct Foo8893
{
char[3] data;
}
int bar8893(Foo8893 f)
{
return f.data[0];
}
static assert(!is(typeof(compiles!(bar8893(Foo8893(['a','b']))))));
/*******************************************
non-Cow struct literals
*******************************************/
struct Zadok
{
int[3] z;
char[4] s = void;
ref int[] fog(return ref int[] q) { return q; }
int bfg()
{
z[0] = 56;
auto zs = z[];
fog(zs) = [56, 6, 8];
assert(z[0] == 56);
assert(z[1] == 61);
assert(z[2] == 61);
assert(zs[0] == 56);
assert(zs[1] == 6);
return zs[2];
}
}
struct Vug
{
Zadok p;
int[] other;
}
int quop()
{
int[] heap = new int[5];
heap[] = 738;
Zadok pong;
pong.z = 3;
int[] w = pong.z;
assert(w[0] == 3);
Zadok phong;
phong.z = 61;
pong = phong;
assert(w[0] == 61);
Vug b = Vug(Zadok(17, "abcd"));
b = Vug(Zadok(17, "abcd"), heap);
b.other[2] = 78;
assert(heap[2] == 78);
char[] y = b.p.s;
assert(y[2] == 'c');
phong.s = ['z','x','f', 'g'];
w = b.p.z;
assert(y[2] == 'c');
assert(w[0] == 17);
b.p = phong;
assert(y[2] == 'f');
Zadok wok = Zadok(6, "xyzw");
b.p = wok;
assert(y[2] == 'z');
b.p = phong;
assert(w[0] == 61);
Vug q;
q.p = pong;
return pong.bfg();
}
static assert(quop() == 8);
static assert(quop() == 8); // check for clobbering
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5676
// tuple assign of struct that has void opAssign
struct S5676
{
int x;
void opAssign(S5676 rhs) { x = rhs.x; }
}
struct Tup5676(E...)
{
E g;
void foo(E values) { g = values; }
}
bool ice5676()
{
Tup5676!(S5676) q;
q.foo(S5676(3));
assert(q.g[0].x == 3);
return true;
}
static assert(ice5676());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5682
// Wrong CTFE with operator overloading
struct A
{
int n;
auto opBinary(string op : "*")(A rhs)
{
return A(n * rhs.n);
}
}
A foo(A[] lhs, A[] rhs)
{
A current;
for (size_t k = 0; k < rhs.length; ++k)
{
current = lhs[k] * rhs[k];
}
return current;
}
auto test()
{
return foo([A(1), A(2)], [A(3), A(4)]);
}
static assert(test().n == 8);
/**************************************************
Attempt to modify a read-only string literal
**************************************************/
struct Xarg
{
char[] s;
}
int zfs(int n)
{
char[] m = "exy".dup;
if (n == 1)
{
// it's OK to cast to const, then cast back
string ss = cast(string)m;
m = cast(char[])ss;
m[2]='q';
return 56;
}
auto q = Xarg(cast(char[])"abc");
assert(q.s[1] == 'b');
if (n == 2)
q.s[1] = 'p';
else if (n == 3)
q.s[0 .. $] = 'p';
char* w = &q.s[2];
if (n == 4)
*w = 'z';
return 76;
}
static assert(!is(typeof(compiles!(zfs(2)))));
static assert(!is(typeof(compiles!(zfs(3)))));
static assert(!is(typeof(compiles!(zfs(4)))));
static assert( is(typeof(compiles!(zfs(1)))));
static assert( is(typeof(compiles!(zfs(5)))));
/**************************************************
.dup must protect string literals
**************************************************/
string mutateTheImmutable(immutable string _s)
{
char[] s = _s.dup;
foreach (ref c; s)
c = 'x';
return s.idup;
}
string doharm(immutable string _name)
{
return mutateTheImmutable(_name[2 .. $].idup);
}
enum victimLiteral = "CL_INVALID_CONTEXT";
enum thug = doharm(victimLiteral);
static assert(victimLiteral == "CL_INVALID_CONTEXT");
/**************************************************
Use $ in a slice of a dotvar slice
**************************************************/
int sliceDollar()
{
Xarg z;
z.s = new char[20];
z.s[] = 'b';
z.s = z.s[2 .. $ - 2];
z.s[$ - 2] = 'c';
return z.s[$ - 2];
}
static assert(sliceDollar() == 'c');
/**************************************************
Variation of 5972 which caused segfault
**************************************************/
int bug5972crash()
{
char[] z = "abc".dup;
char[][] a = [null, null];
a[0] = z[0 .. 2];
a[0][1] = 'q';
return 56;
}
static assert(bug5972crash() == 56);
/**************************************************
String slice assignment through ref parameter
**************************************************/
void popft(A)(ref A a)
{
a = a[1 .. $];
}
int sdfgasf()
{
auto scp = "abc".dup;
popft(scp);
return 1;
}
static assert(sdfgasf() == 1);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8830
// slice of slice.ptr
string bug8830(string s)
{
auto ss = s[1 .. $];
return ss.ptr[0 .. 2];
}
static assert(bug8830("hello") == "el");
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8608
// ICE
void bug8608(ref int m) {}
void test8608()
{
int z;
int foo(bool b)
{
if (b)
bug8608(z);
return 1;
}
static assert( is(typeof(compiles!(foo(false)))));
static assert(!is(typeof(compiles!(foo(true) ))));
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7770
immutable char[] foo7770 = "abcde";
int bug7770a(string a)
{
return 1;
}
bool bug7770b(char c)
{
return true;
}
static assert(bug7770a(foo7770[0 .. $]));
static assert(bug7770b(foo7770[$ - 2]));
void baz7770()
{
static assert(bug7770a(foo7770[0 .. $]));
static assert(bug7770b(foo7770[$ - 2]));
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8601
// ICE
dchar bug8601(dstring s)
{
dstring w = s[1 .. $];
return w[0];
}
enum dstring e8601 = [cast(dchar)'o', 'n'];
static assert(bug8601(e8601) == 'n');
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6015
struct Foo6015
{
string field;
}
bool func6015(string input)
{
Foo6015 foo;
foo.field = input[0 .. $];
assert(foo.field == "test");
foo.field = "test2";
assert(foo.field != "test");
assert(foo.field == "test2");
return true;
}
static assert(func6015("test"));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6001
void bug6001e(ref int[] s)
{
int[] r = s;
s ~= 0;
}
bool bug6001f()
{
int[] s;
bug6001e(s);
return true;
}
static assert(bug6001f());
// Assignment to AAs
void blah(int[char] as)
{
auto k = [6: as];
as = k[6];
}
int blaz()
{
int[char] q;
blah(q);
return 67;
}
static assert(blaz() == 67);
void bug6001g(ref int[] w)
{
w = [88];
bug6001e(w);
w[0] = 23;
}
bool bug6001h()
{
int[] s;
bug6001g(s);
assert(s.length == 2);
assert(s[1] == 0);
assert(s[0] == 23);
return true;
}
static assert(bug6001h());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10243
// wrong code *&arr as ref parameter
// https://issues.dlang.org/show_bug.cgi?id=10551
// wrong code (&arr)[0] as ref parameter
void bug10243(ref int n)
{
n = 3;
}
void bug10551(int* p)
{
bug10243(p[0]);
}
bool test10243()
{
int[1] arr;
bug10243(*arr.ptr);
assert(arr[0] == 3);
int[1] arr2;
bug10551(arr2.ptr);
assert(arr2[0] == 3);
int v;
bug10551(&v);
assert(v == 3);
return true;
}
static assert(test10243());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4910
int bug4910(int a)
{
return a;
}
static int var4910;
static assert(!is(typeof(Compiles!(bug4910(var4910)))));
static assert(bug4910(123));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5845
// Regression(2.041)
void test5845(ulong cols) {}
uint solve(bool niv, ref ulong cols)
{
if (niv)
solve(false, cols);
else
test5845(cols);
return 65;
}
ulong nqueen(int n)
{
ulong cols = 0;
return solve(true, cols);
}
static assert(nqueen(2) == 65);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5258
struct Foo5258 { int x; }
void bar5258(int n, ref Foo5258 fong)
{
if (n)
bar5258(n - 1, fong);
else
fong.x++;
}
int bug5258()
{
Foo5258 foo5258 = Foo5258();
bar5258(1, foo5258);
return 45;
}
static assert(bug5258() == 45);
struct Foo5258b { int[2] r; }
void baqopY(int n, ref int[2] fongo)
{
if (n)
baqopY(n - 1, fongo);
else
fongo[0]++;
}
int bug5258b()
{
Foo5258b qq;
baqopY(1, qq.r);
return 618;
}
static assert(bug5258b() == 618);
// Notice that this case involving reassigning the dynamic array
struct Foo5258c { int[] r; }
void baqop(int n, ref int[] fongo)
{
if (n)
baqop(n - 1, fongo);
else
{
fongo = new int[20];
fongo[0]++;
}
}
size_t bug5258c()
{
Foo5258c qq;
qq.r = new int[30];
baqop(1, qq.r);
return qq.r.length;
}
static assert(bug5258c() == 20);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6049
struct Bug6049
{
int m;
this(int x) { m = x; }
invariant() { }
}
const Bug6049[] foo6049 = [Bug6049(6), Bug6049(17)];
static assert(foo6049[0].m == 6);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6052
struct Bug6052
{
int a;
}
bool bug6052()
{
Bug6052[2] arr;
for (int i = 0; i < 2; ++ i)
{
Bug6052 el = {i};
Bug6052 ek = el;
arr[i] = el;
el.a = i + 2;
assert(ek.a == i); // ok
assert(arr[i].a == i); // fail
}
assert(arr[1].a == 1); // ok
assert(arr[0].a == 0); // fail
return true;
}
static assert(bug6052());
bool bug6052b()
{
int[][1] arr;
int[1] z = [7];
arr[0] = z;
assert(arr[0][0] == 7);
arr[0] = z;
z[0] = 3;
assert(arr[0][0] == 3);
return true;
}
static assert(bug6052b());
struct Bug6052c
{
int x;
this(int a) { x = a; }
}
int bug6052c()
{
Bug6052c[] pieces = [];
for (int c = 0; c < 2; ++ c)
pieces ~= Bug6052c(c);
assert(pieces[1].x == 1);
assert(pieces[0].x == 0);
return 1;
}
static assert(bug6052c() == 1);
static assert(bug6052c() == 1);
static assert({
Bug6052c[] pieces = [];
pieces.length = 2;
int c = 0;
pieces[0] = Bug6052c(c);
++c;
pieces[1] = Bug6052c(c);
assert(pieces[0].x == 0);
return true;
}());
static assert({
int[1][] pieces = [];
pieces.length = 2;
for (int c = 0; c < 2; ++ c)
pieces[c][0] = c;
assert(pieces[1][0] == 1);
assert(pieces[0][0] == 0);
return true;
}());
static assert({
Bug6052c[] pieces = [];
for (int c = 0; c < 2; ++ c)
pieces ~= Bug6052c(c);
assert(pieces[1].x == 1);
assert(pieces[0].x == 0);
return true;
}());
static assert({
int[1] z = 7;
int[1][] pieces = [z,z];
pieces[1][0]=3;
assert(pieces[0][0] == 7);
pieces = pieces ~ [z,z];
pieces[3][0] = 16;
assert(pieces[2][0] == 7);
pieces = [z,z] ~ pieces;
pieces[5][0] = 16;
assert(pieces[4][0] == 7);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6749
struct CtState
{
string code;
}
CtState bug6749()
{
CtState[] pieces;
CtState r = CtState("correct");
pieces ~= r;
r = CtState("clobbered");
return pieces[0];
}
static assert(bug6749().code == "correct");
/**************************************************
Index + slice assign to function returns
**************************************************/
int[] funcRetArr(int[] a)
{
return a;
}
int testFuncRetAssign()
{
int[] x = new int[20];
funcRetArr(x)[2] = 4;
assert(x[2] == 4);
funcRetArr(x)[] = 27;
assert(x[15] == 27);
return 5;
}
static assert(testFuncRetAssign() == 5);
int keyAssign()
{
int[int] pieces;
pieces[3] = 1;
pieces.keys[0] = 4;
pieces.values[0] = 27;
assert(pieces[3] == 1);
return 5;
}
static assert(keyAssign() == 5);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6054
// AA literals
enum x6054 = {
auto p = {
int[string] pieces;
pieces[['a'].idup] = 1;
return pieces;
}();
return p;
}();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6077
enum bug6077 = {
string s;
string t;
return s ~ t;
}();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6078
// Pass null array by ref
struct Foo6078
{
int[] bar;
}
static assert({
Foo6078 f;
int i;
foreach (ref e; f.bar)
{
i += e;
}
return i;
}() == 0);
int bug6078(ref int[] z)
{
int[] q = z;
return 2;
}
static assert({
Foo6078 f;
return bug6078(f.bar);
}() == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6079
// Array bounds checking
static assert(!is(typeof(compiles!({
int[] x = [1, 2, 3, 4];
x[4] = 1;
return true;
}()
))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6100
struct S6100
{
int a;
}
S6100 init6100(int x)
{
S6100 s = S6100(x);
return s;
}
static const S6100[2] s6100a = [init6100(1), init6100(2)];
static assert(s6100a[0].a == 1);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4825
// failed with -inline
int a4825()
{
int r;
return r;
}
int b4825()
{
return a4825();
}
void c4825()
{
void d()
{
auto e = b4825();
}
static const int f = b4825();
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5708
// failed with -inline
string b5708(string s) { return s; }
string a5708(string s) { return b5708(s); }
void bug5708()
{
void m() { a5708("lit"); }
static assert(a5708("foo") == "foo");
static assert(a5708("bar") == "bar");
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6120
// failed with -inline
struct Bug6120(T)
{
this(int x) { }
}
static assert({
auto s = Bug6120!int(0);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6123
// failed with -inline
struct Bug6123(T)
{
void f() {}
// can also trigger if the struct is normal but f is template
}
static assert({
auto piece = Bug6123!int();
piece.f();
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6053
// ICE involving pointers
static assert({
int* a = null;
assert(a is null);
assert(a == null);
return true;
}());
static assert({
int b;
int* a = &b;
assert(a !is null);
*a = 7;
assert(b == 7);
assert(*a == 7);
return true;
}());
int dontbreak6053()
{
auto q = &dontbreak6053;
void caz() {}
auto tr = &caz;
return 5;
}
static assert(dontbreak6053());
static assert({
int a;
*(&a) = 15;
assert(a == 15);
assert(*(&a) == 15);
return true;
}());
static assert({
int a = 5, b = 6, c = 2;
assert(*(c ? &a : &b) == 5);
assert(*(!c ? &a : &b) == 6);
return true;
}());
static assert({
int a, b, c;
(c ? a : b) = 1;
return true;
}());
static assert({
int a, b, c = 1;
int* p = &a;
(c ? *p : b) = 51;
assert(a == 51);
return true;
}());
/**************************************************
Pointer arithmetic, dereference, and comparison
**************************************************/
// dereference null pointer
static assert(!is(typeof(compiles!({
int a, b, c = 1;
int* p;
(c ? *p : b) = 51;
return 6;
}()
))));
static assert(!is(typeof(compiles!({
int* a = null;
assert(*a != 6);
return 72;
}()
))));
// cannot <, > compare pointers to different arrays
static assert(!is(typeof(compiles!({
int[5] a, b;
bool c = (&a[0] > &b[0]);
return 72;
}()
))));
// can ==, is, !is, != compare pointers for different arrays
static assert({
int[5] a;
int[5] b;
assert(!(&a[0] == &b[0]));
assert(&a[0] != &b[0]);
assert(!(&a[0] is &b[0]));
assert(&a[0] !is &b[0]);
return 72;
}());
static assert({
int[5] a;
a[0] = 25;
a[1] = 5;
int* b = &a[1];
assert(*b == 5);
*b = 34;
int c = *b;
*b += 6;
assert(b == &a[1]);
assert(b != &a[0]);
assert(&a[0] < &a[1]);
assert(&a[0] <= &a[1]);
assert(!(&a[0] >= &a[1]));
assert(&a[4] > &a[0]);
assert(c == 34);
assert(*b == 40);
assert(a[1] == 40);
return true;
}());
static assert({
int[12] x;
int* p = &x[10];
int* q = &x[4];
return p - q;
}() == 6);
static assert({
int[12] x;
int* p = &x[10];
int* q = &x[4];
q = p;
assert(p == q);
q = &x[4];
assert(p != q);
q = q + 6;
assert(q is p);
return 6;
}() == 6);
static assert({
int[12] x;
int[] y = x[2 .. 8];
int* p = &y[4];
int* q = &x[6];
assert(p == q);
p = &y[5];
assert(p > q);
p = p + 5; // OK, as long as we don't dereference
assert(p > q);
return 6;
}() == 6);
static assert({
char[12] x;
const(char)* p = "abcdef";
const (char)* q = p;
q = q + 2;
assert(*q == 'c');
assert(q > p);
assert(q - p == 2);
assert(p - q == -2);
q = &x[7];
p = &x[1];
assert(q>p);
return 6;
}() == 6);
// Relations involving null pointers
bool nullptrcmp()
{
// null tests
void* null1 = null, null2 = null;
int x = 2;
void* p = &x;
assert(null1 == null2);
assert(null1 is null2);
assert(null1 <= null2);
assert(null1 >= null2);
assert(!(null1 > null2));
assert(!(null2 > null1));
assert(null1 != p);
assert(null1 !is p);
assert(p != null1);
assert(p !is null1);
assert(null1 <= p);
assert(p >= null2);
assert(p > null1);
assert(!(null1 > p));
return true;
}
static assert(nullptrcmp());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10840
// null pointer in dotvar
struct Data10840
{
bool xxx;
}
struct Bug10840
{
Data10840* _data;
}
enum bug10840 = (int n)
{
Bug10840 stack;
if (n == 1)
{
// detect deref through null pointer
return stack._data.xxx;
}
// Wrong-code for ?:
return stack._data ? false : true;
};
static assert(bug10840(0));
static assert(!is(typeof(Compileable!(bug10840(1)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8216
// ptr inside a pointer range
// Four-pointer relations. Return true if [p1 .. p2] points inside [q1 .. q2]
// (where the end points don't coincide).
bool ptr4cmp(void* p1, void* p2, void* q1, void* q2)
{
// Each compare can be written with <, <=, >, or >=.
// Either && or || can be used, giving 32 permutations.
// Additionally each compare can be negated with !, yielding 128 in total.
bool b1 = (p1 > q1 && p2 <= q2);
bool b2 = (p1 > q1 && p2 < q2);
bool b3 = (p1 >= q1 && p2 <= q2);
bool b4 = (p1 >= q1 && p2 < q2);
bool b5 = (q1 <= p1 && q2 > p2);
bool b6 = (q1 <= p1 && q2 >= p2);
bool b7 = (p2 <= q2 && p1 > q1);
bool b8 = (!(p1 <= q1) && p2 <= q2);
bool b9 = (!(p1 <= q1) && !(p2 > q2));
bool b10 = (!!!(p1 <= q1) && !(p2 > q2));
assert(b1 == b2 && b1 == b3 && b1 == b4 && b1 == b5 && b1 == b6);
assert(b1 == b7 && b1 == b8 && b1 == b9 && b1 == b10);
bool c1 = (p1 <= q1 || p2 > q2);
assert(c1 == !b1);
bool c2 = (p1 < q1 || p2 >= q2);
bool c3 = (!(q1 <= p1) || !(q2 >= p2));
assert(c1 == c2 && c1 == c3);
return b1;
}
bool bug8216()
{
int[4] a;
int[13] b;
int v;
int* p = &v;
assert(!ptr4cmp(&a[0], &a[3], p, p));
assert(!ptr4cmp(&b[2], &b[9], &a[1], &a[2]));
assert(!ptr4cmp(&b[1], &b[9], &b[2], &b[8]));
assert( ptr4cmp(&b[2], &b[8], &b[1], &b[9]));
return 1;
}
static assert(bug8216());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6517
// ptr++, ptr--
int bug6517()
{
int[] arr = [1, 2, 3];
auto startp = arr.ptr;
auto endp = arr.ptr + arr.length;
for (; startp < endp; startp++) {}
startp = arr.ptr;
assert(startp++ == arr.ptr);
assert(startp != arr.ptr);
assert(startp-- != arr.ptr);
assert(startp == arr.ptr);
return 84;
}
static assert(bug6517() == 84);
/**************************************************
Out-of-bounds pointer assignment and deference
**************************************************/
int ptrDeref(int ofs, bool wantDeref)
{
int[5] a;
int* b = &a[0];
b = b + ofs; // OK
if (wantDeref)
return *b; // out of bounds
return 72;
}
static assert(!is(typeof(compiles!(ptrDeref(-1, true)))));
static assert( is(typeof(compiles!(ptrDeref(4, true)))));
static assert( is(typeof(compiles!(ptrDeref(5, false)))));
static assert(!is(typeof(compiles!(ptrDeref(5, true)))));
static assert(!is(typeof(compiles!(ptrDeref(6, false)))));
static assert(!is(typeof(compiles!(ptrDeref(6, true)))));
/**************************************************
Pointer +=
**************************************************/
static assert({
int[12] x;
int zzz;
assert(&zzz);
int* p = &x[10];
int* q = &x[4];
q = p;
assert(p == q);
q = &x[4];
assert(p != q);
q += 4;
assert(q == &x[8]);
q = q - 2;
q = q + 4;
assert(q is p);
return 6;
}() == 6);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5615
const(char)[] passthrough(const(char)[] x)
{
return x;
}
ptrdiff_t checkPass(Char1)(const(Char1)[] s)
{
const(Char1)[] balance = s[1 .. $];
return passthrough(balance).ptr - s.ptr;
}
static assert(checkPass("foobar") == 1);
/**************************************************
Pointers must not escape from CTFE
**************************************************/
struct Toq
{
char* m;
}
Toq ptrRet(bool b)
{
char[] x = "abc".dup;
return Toq(b ? x[0 .. 1].ptr : null);
}
static assert(is(typeof(compiles!({
enum Toq boz = ptrRet(false); // OK - ptr is null
Toq z = ptrRet(true); // OK -- ptr doesn't escape
return 4;
}()
))));
static assert(!is(typeof(compiles!({
enum Toq boz = ptrRet(true); // fail - ptr escapes
return 4;
}()
))));
/**************************************************
Pointers to struct members
**************************************************/
struct Qoz
{
int w;
int[3] yof;
}
static assert({
int[3] gaz;
gaz[2] = 3156;
Toq z = ptrRet(true);
auto p = z.m;
assert(*z.m == 'a');
assert(*p == 'a');
auto q = &z.m;
assert(*q == p);
assert(**q == 'a');
Qoz g = Qoz(2, [5, 6, 7]);
auto r = &g.w;
assert(*r == 2);
r = &g.yof[1];
assert(*r == 6);
g.yof[0] = 15;
++r;
assert(*r == 7);
r -= 2;
assert(*r == 15);
r = &gaz[0];
r += 2;
assert(*r == 3156);
return *p;
}() == 'a');
struct AList
{
AList* next;
int value;
static AList* newList()
{
AList[] z = new AList[1];
return &z[0];
}
static AList* make(int i, int j)
{
auto r = newList();
r.next = (new AList[1]).ptr;
r.value = 1;
AList* z = r.next;
(*z).value = 2;
r.next.value = j;
assert(r.value == 1);
assert(r.next.value == 2);
r.next.next = &(new AList[1])[0];
assert(r.next.next != null);
assert(r.next.next);
r.next.next.value = 3;
assert(r.next.next.value == 3);
r.next.next = newList();
r.next.next.value = 9;
return r;
}
static int checkList()
{
auto r = make(1,2);
assert(r.value == 1);
assert(r.next.value == 2);
assert(r.next.next.value == 9);
return 2;
}
}
static assert(AList.checkList() == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7194
// pointers as struct members
struct S7194 { int* p, p2; }
int f7194()
{
assert(S7194().p == null);
assert(!S7194().p);
assert(S7194().p == S7194().p2);
S7194 s = S7194();
assert(!s.p);
assert(s.p == null);
assert(s.p == s.p2);
int x;
s.p = &x;
s.p2 = s.p;
assert(s.p == &x);
return 0;
}
int g7194()
{
auto s = S7194();
assert(s.p); // should fail
return 0;
}
static assert(f7194() == 0);
static assert(!is(typeof(compiles!(g7194()))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7248
// recursive struct pointers in array
struct S7248 { S7248* ptr; }
bool bug7248()
{
S7248[2] sarr;
sarr[0].ptr = &sarr[1];
sarr[0].ptr = null;
S7248* t = sarr[0].ptr;
return true;
}
static assert(bug7248());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7216
// calling a struct pointer member
struct S7216
{
S7216* p;
int t;
void f() { }
void g() { ++t; }
}
bool bug7216()
{
S7216 s0, s1;
s1.t = 6;
s0.p = &s1;
s0.p.f();
s0.p.g();
assert(s1.t == 7);
return true;
}
static assert(bug7216());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10858
// Wrong code with array of pointers
bool bug10858()
{
int*[4] x;
x[0] = null;
assert(x[0] == null);
return true;
}
static assert(bug10858());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12528
// painting inout type for value type literals
inout(T)[] dup12528(T)(inout(T)[] a)
{
inout(T)[] res;
foreach (ref e; a)
res ~= e;
return res;
}
enum arr12528V1 = dup12528([0]);
enum arr12528V2 = dup12528([0, 1]);
static assert(arr12528V1 == [0]);
static assert(arr12528V2 == [0, 1]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9745
// Allow pointers to static variables
shared int x9745;
shared int[5] y9745;
shared(int)* bug9745(int m)
{
auto k = &x9745;
auto j = &x9745;
auto p = &y9745[0];
auto q = &y9745[3];
assert(j - k == 0);
assert(j == k);
assert(q - p == 3);
--q;
int a = 0;
assert(p + 2 == q);
if (m == 7)
{
auto z1 = y9745[0 .. 2]; // slice global pointer
}
if (m == 8)
p[1] = 7; // modify through a pointer
if (m == 9)
a = p[1]; // read from a pointer
if (m == 0)
return &x9745;
return &y9745[1];
}
int test9745(int m)
{
bug9745(m);
// type painting
shared int* w = bug9745(0);
return 1;
}
shared int* w9745a = bug9745(0);
shared int* w9745b = bug9745(1);
static assert( is(typeof(compiles!(test9745(6)))));
static assert(!is(typeof(compiles!(test9745(7)))));
static assert(!is(typeof(compiles!(test9745(8)))));
static assert(!is(typeof(compiles!(test9745(9)))));
// pointers cast from an absolute address
// (mostly applies to fake pointers, eg Windows HANDLES)
bool test9745b()
{
void* b6 = cast(void*)0xFEFEFEFE;
void* b7 = cast(void*)0xFEFEFEFF;
assert(b6 is b6);
assert(b7 != b6);
return true;
}
static assert(test9745b());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9364
// ICE with pointer to local struct
struct S9364
{
int i;
}
bool bug9364()
{
S9364 s;
auto k = (&s).i;
return 1;
}
static assert(bug9364());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10251
// Pointers to const globals
static const int glob10251 = 7;
const(int)* bug10251()
{
return &glob10251;
}
static a10251 = &glob10251; // OK
static b10251 = bug10251();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4065
// [CTFE] AA "in" operator doesn't work
bool bug4065(string s)
{
enum int[string] aa = ["aa":14, "bb":2];
int* p = s in aa;
if (s == "aa")
assert(*p == 14);
else if (s == "bb")
assert(*p == 2);
else
assert(!p);
int[string] zz;
assert(!("xx" in zz));
bool c = !p;
return cast(bool)(s in aa);
}
static assert(!bug4065("xx"));
static assert( bug4065("aa"));
static assert( bug4065("bb"));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12689
// assigning via pointer from 'in' expression
int g12689()
{
int[int] aa;
aa[1] = 13;
assert(*(1 in aa) == 13);
*(1 in aa) = 42;
return aa[1];
}
static assert(g12689() == 42);
/**************************************************
Pointers in ? :
**************************************************/
static assert({
int[2] x;
int* p = &x[1];
return p ? true: false;
}());
/**************************************************
Pointer slicing
**************************************************/
int ptrSlice()
{
auto arr = new int[5];
int* x = &arr[0];
int[] y = x[0 .. 5];
x[1 .. 3] = 6;
++x;
x[1 .. 3] = 14;
assert(arr[1] == 6);
assert(arr[2] == 14);
//x[-1 .. 4] = 5; // problematic because negative lower boundary will throw RangeError in runtime
(x - 1)[0 .. 3] = 5;
int[] z = arr[1 .. 2];
z.length = 4;
z[$ - 1] = 17;
assert(arr.length == 5);
return 2;
}
static assert(ptrSlice() == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6344
// create empty slice from null pointer
static assert({
char* c = null;
auto m = c[0 .. 0];
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8365
// block assignment of enum arrays
enum E8365 { first = 7, second, third, fourth }
static assert({ E8365[2] x; return x[0]; }() == E8365.first);
static assert({ E8365[2][2] x; return x[0][0]; }() == E8365.first);
static assert({ E8365[2][2][2] x; return x[0][0][0]; }() == E8365.first);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4448
// labelled break + continue
int bug4448()
{
int n = 2;
L1:
do
{
switch(n)
{
case 5:
return 7;
default:
n = 5;
break L1;
}
int w = 7;
} while (0);
return 3;
}
static assert(bug4448() == 3);
int bug4448b()
{
int n = 2;
L1:
for (n = 2; n < 5; ++n)
{
for (int m = 1; m < 6; ++m)
{
if (n < 3)
{
assert(m == 1);
continue L1;
}
}
break;
}
return 3;
}
static assert(bug4448b() == 3);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6985
// Formerly, non-constant case, but switch cases with mutable cases now error
// Currently: run-time constant variable case
int bug6985(int z)
{
const int q = z * 2 - 6;
switch(z)
{
case q:
return 87;
default:
}
return q;
}
static assert(bug6985(6) == 87);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6281
// [CTFE] A null pointer '!is null' returns 'true'
static assert(!{
auto p = null;
return p !is null;
}());
static assert(!{
auto p = null;
return p != null;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6331
// evaluate SliceExp on if condition
bool bug6331(string s)
{
if (s[0 .. 1])
return true;
return false;
}
static assert(bug6331("str"));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6283
// assign to AA with slice as index
static assert({
immutable p = "pp";
int[string] pieces = [p: 0];
pieces["qq"] = 1;
return true;
}());
static assert({
immutable renames = [0: "pp"];
int[string] pieces;
pieces[true ? renames[0] : "qq"] = 1;
pieces["anything"] = 1;
return true;
}());
static assert({
immutable qq = "qq";
string q = qq;
int[string] pieces = ["a":1];
pieces[q] = 0;
string w = "ab";
int z = pieces[w[0 .. 1]];
assert(z == 1);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6282
// dereference 'in' of an AA
static assert({
int[] w = new int[4];
w[2] = 6;
auto c = [5: w];
auto kk = (*(5 in c))[2];
(*(5 in c))[2] = 8;
(*(5 in c))[1 .. $ - 2] = 4;
auto a = [4:"1"];
auto n = *(4 in a);
return n;
}() == "1");
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6337
// member function call on struct literal
struct Bug6337
{
int k;
void six()
{
k = 6;
}
int ctfe()
{
six();
return k;
}
}
static assert(Bug6337().ctfe() == 6);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6603
// call manifest function pointer
int f6603(int a) { return a + 5; }
enum bug6603 = &f6603;
static assert(bug6603(6) == 11);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6375
struct D6375
{
int[] arr;
}
A6375 a6375(int[] array)
{
return A6375(array);
}
struct A6375
{
D6375* _data;
this(int[] arr)
{
_data = new D6375;
_data.arr = arr;
}
int[] data()
{
return _data.arr;
}
}
static assert({
int[] a = [1, 2];
auto app2 = a6375(a);
auto data = app2.data();
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6280
// Converting pointers to bool
static assert({
if ((0 in [0:0])) {}
if ((0 in [0:0]) && (0 in [0:0])) {}
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6276
// ~=
struct Bug6276
{
int[] i;
}
static assert({
Bug6276 foo;
foo.i ~= 1;
foo.i ~= 2;
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6374
// ptr[n] = x, x = ptr[n]
static assert({
int[] arr = [1];
arr.ptr[0] = 2;
auto k = arr.ptr[0];
assert(k == 2);
return arr[0];
}() == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6306
// recursion and local variables
void recurse6306()
{
bug6306(false);
}
bool bug6306(bool b)
{
int x = 0;
if (b)
recurse6306();
assert(x == 0);
x = 1;
return true;
}
static assert(bug6306(true));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6386
// ICE on unsafe pointer cast
static assert(!is(typeof(compiles!({
int x = 123;
int* p = &x;
float z;
float* q = cast(float*)p;
return true;
}()
))));
static assert({
int[] x = [123, 456];
int* p = &x[0];
auto m = cast(const(int)*)p;
auto q = p;
return *q;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6420
// ICE on dereference of invalid pointer
static assert({
// Should compile, but pointer can't be dereferenced
int x = 123;
int* p = cast(int*)x;
auto q = cast(char*)x;
auto r = cast(char*)323;
// Valid const-changing cast
const float *m = cast(immutable float*)[1.2f,2.4f,3f];
return true;
}()
);
static assert(!is(typeof(compiles!({
int x = 123;
int* p = cast(int*)x;
int a = *p;
return true;
}()
))));
static assert(!is(typeof(compiles!({
int* p = cast(int*)123;
int a = *p;
return true;
}()
))));
static assert(!is(typeof(compiles!({
auto k = cast(int*)45;
*k = 1;
return true;
}()
))));
static assert(!is(typeof(compiles!({
*cast(float*)"a" = 4.0;
return true;
}()
))));
static assert(!is(typeof(compiles!({
float f = 2.8;
long *p = &f;
return true;
}()
))));
static assert(!is(typeof(compiles!({
long *p = cast(long*)[1.2f, 2.4f, 3f];
return true;
}()
))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6250
// deref pointers to array
int[]* simple6250(int[]* x) { return x; }
void swap6250(int[]* lhs, int[]* rhs)
{
int[] kk = *lhs;
assert(simple6250(lhs) == lhs);
lhs = simple6250(lhs);
assert(kk[0] == 18);
assert((*lhs)[0] == 18);
assert((*rhs)[0] == 19);
*lhs = *rhs;
assert((*lhs)[0] == 19);
*rhs = kk;
assert(*rhs == kk);
assert(kk[0] == 18);
assert((*rhs)[0] == 18);
}
int ctfeSort6250()
{
int[][2] x;
int[3] a = [17, 18, 19];
x[0] = a[1 .. 2];
x[1] = a[2 .. $];
assert(x[0][0] == 18);
assert(x[0][1] == 19);
swap6250(&x[0], &x[1]);
assert(x[0][0] == 19);
assert(x[1][0] == 18);
a[1] = 57;
assert(x[0][0] == 19);
return x[1][0];
}
static assert(ctfeSort6250() == 57);
/**************************************************/
long[]* simple6250b(long[]* x) { return x; }
void swap6250b(long[]* lhs, long[]* rhs)
{
long[] kk = *lhs;
assert(simple6250b(lhs) == lhs);
lhs = simple6250b(lhs);
assert(kk[0] == 18);
assert((*lhs)[0] == 18);
assert((*rhs)[0] == 19);
*lhs = *rhs;
assert((*lhs)[0] == 19);
*rhs = kk;
assert(*rhs == kk);
assert(kk[0] == 18);
assert((*rhs)[0] == 18);
}
long ctfeSort6250b()
{
long[][2] x;
long[3] a = [17, 18, 19];
x[0] = a[1 .. 2];
x[1] = a[2 .. $];
assert(x[0][0] == 18);
assert(x[0][1] == 19);
swap6250b(&x[0], &x[1]);
assert(x[0][0] == 19);
assert(x[1][0] == 18);
a[1] = 57;
assert(x[0][0] == 19);
return x[1][0];
}
static assert(ctfeSort6250b() == 57);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6672
// circular references in array
void bug6672(ref string lhs, ref string rhs)
{
auto tmp = lhs;
lhs = rhs;
rhs = tmp;
}
static assert({
auto kw = ["a"];
bug6672(kw[0], kw[0]);
return true;
}());
void slice6672(ref string[2] agg, ref string lhs)
{
agg[0 .. $] = lhs;
}
static assert({
string[2] kw = ["a", "b"];
slice6672(kw, kw[0]);
assert(kw[0] == "a");
assert(kw[1] == "a");
return true;
}());
// an unrelated rejects-valid bug
static assert({
string[2] kw = ["a", "b"];
kw[0 .. 2] = "x";
return true;
}());
void bug6672b(ref string lhs, ref string rhs)
{
auto tmp = lhs;
assert(tmp == "a");
lhs = rhs;
assert(tmp == "a");
rhs = tmp;
}
static assert({
auto kw=["a", "b"];
bug6672b(kw[0], kw[1]);
assert(kw[0] == "b");
assert(kw[1] == "a");
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6399
// (*p).length = n
struct A6399
{
int[] arr;
int subLen()
{
arr = [1, 2, 3, 4, 5];
arr.length -= 1;
return cast(int)arr.length;
}
}
static assert({
A6399 a;
return a.subLen();
}() == 4);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7789
// (*p).length++ where *p is null
struct S7789
{
size_t foo()
{
_ary.length += 1;
return _ary.length;
}
int[] _ary;
}
static assert(S7789().foo());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6418
// member named 'length'
struct Bug6418
{
size_t length() { return 189; }
}
static assert(Bug6418.init.length == 189);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4021
// rehash
bool bug4021()
{
int[int] aa = [1: 1];
aa.rehash;
return true;
}
static assert(bug4021());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11629
// crash on AA.rehash
struct Base11629
{
alias T = ubyte, Char = char;
alias String = immutable(Char)[];
const Char[T] toChar;
this(int _dummy)
{
Char[T] toCharTmp = [0:'A'];
toChar = toCharTmp.rehash;
}
}
enum ct11629 = Base11629(4);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=3512
// foreach (dchar; string)
// https://issues.dlang.org/show_bug.cgi?id=6558
// foreach (int, dchar; string)
bool test3512()
{
string s = "öhai";
int q = 0;
foreach (wchar c; s)
{
if (q == 2)
assert(c == 'a');
++q;
}
assert(q == 4);
// _aApplycd1
foreach (dchar c; s)
{
++q;
if (c == 'h')
break;
}
assert(q == 6);
// _aApplycw2
foreach (ptrdiff_t i, wchar c; s)
{
assert(i >= 0 && i < s.length);
}
// _aApplycd2
foreach (ptrdiff_t i, dchar c; s)
{
assert(i >= 0 && i < s.length);
}
wstring w = "xüm";
// _aApplywc1
foreach (char c; w)
{
++q;
}
assert(q == 10);
// _aApplywd1
foreach (dchar c; w)
{
++q;
}
assert(q == 13);
// _aApplywc2
foreach (ptrdiff_t i, char c; w)
{
assert(i >= 0 && i < w.length);
}
// _aApplywd2
foreach (ptrdiff_t i, dchar c; w)
{
assert(i >= 0 && i < w.length);
}
dstring d = "yäq";
// _aApplydc1
q = 0;
foreach (char c; d)
{
++q;
}
assert(q == 4);
// _aApplydw1
q = 0;
foreach (wchar c; d)
{
++q;
}
assert(q == 3);
// _aApplydc2
foreach (ptrdiff_t i, char c; d)
{
assert(i >= 0 && i < d.length);
}
// _aApplydw2
foreach (ptrdiff_t i, wchar c; d)
{
assert(i >= 0 && i < d.length);
}
dchar[] dr = "squop"d.dup;
foreach (ptrdiff_t n, char c; dr)
{
if (n == 2)
break;
assert(c != 'o');
}
// _aApplyRdc1
foreach_reverse (char c; dr)
{}
// _aApplyRdw1
foreach_reverse (wchar c; dr)
{}
// _aApplyRdc2
foreach_reverse (ptrdiff_t n, char c; dr)
{
if (n == 4)
break;
assert(c != 'o');
}
// _aApplyRdw2
foreach_reverse (ptrdiff_t i, wchar c; dr)
{
assert(i >= 0 && i < dr.length);
}
q = 0;
wstring w2 = ['x', 'ü', 'm']; // foreach over array literals
foreach_reverse (ptrdiff_t n, char c; w2)
{
++q;
if (c == 'm') assert(n == 2 && q == 1);
if (c == 'x') assert(n == 0 && q == 4);
}
return true;
}
static assert(test3512());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6510
// ICE only with -inline
struct Stack6510
{
struct Proxy
{
void shrink() {}
}
Proxy stack;
void pop()
{
stack.shrink();
}
}
int bug6510()
{
static int used()
{
Stack6510 junk;
junk.pop();
return 3;
}
return used();
}
void test6510()
{
static assert(bug6510() == 3);
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6511
// arr[] shouldn't make a copy
T bug6511(T)()
{
T[1] a = [1];
a[] += a[];
return a[0];
}
static assert(bug6511!ulong() == 2);
static assert(bug6511!long() == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6512
// new T[][]
bool bug6512(int m)
{
auto x = new int[2][][](m, 5);
assert(x.length == m);
assert(x[0].length == 5);
assert(x[0][0].length == 2);
foreach (i; 0.. m)
foreach (j; 0 .. 5)
foreach (k; 0 .. 2)
x[i][j][k] = k + j*10 + i*100;
foreach (i; 0.. m)
foreach (j; 0 .. 5)
foreach (k; 0 .. 2)
assert(x[i][j][k] == k + j*10 + i*100);
return true;
}
static assert(bug6512(3));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6516
// ICE(constfold.c)
dstring bug6516()
{
return cast(dstring)new dchar[](0);
}
static assert(bug6516() == ""d);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6727
// ICE(interpret.c)
const(char)* ice6727(const(char)* z) { return z; }
static assert({
auto q = ice6727("a".dup.ptr);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6721
// Cannot get pointer to start of char[]
static assert({
char[] c1 = "".dup;
auto p = c1.ptr;
string c2 = "";
auto p2 = c2.ptr;
return 6;
}() == 6);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6693
// Assign to null AA
struct S6693
{
int[int] m;
}
static assert({
int[int][int] aaa;
aaa[3][1] = 4;
int[int][3] aab;
aab[2][1] = 4;
S6693 s;
s.m[2] = 4;
return 6693;
}() == 6693);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7602
// Segfault AA.keys on null AA
string[] test7602()
{
int[string] array;
return array.keys;
}
enum bug7602 = test7602();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6739
// Nested AA assignment
static assert({
int[int][int][int] aaa;
aaa[3][1][6] = 14;
return aaa[3][1][6];
}() == 14);
static assert({
int[int][int] aaa;
aaa[3][1] = 4;
aaa[3][3] = 3;
aaa[1][5] = 9;
auto kk = aaa[1][5];
return kk;
}() == 9);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6751
// ref AA assignment
void bug6751(ref int[int] aa)
{
aa[1] = 2;
}
static assert({
int[int] aa;
bug6751(aa);
assert(aa[1] == 2);
return true;
}());
void bug6751b(ref int[int][int] aa)
{
aa[1][17] = 2;
}
struct S6751
{
int[int][int] aa;
int[int] bb;
}
static assert({
S6751 s;
bug6751b(s.aa);
assert(s.aa[1][17] == 2);
return true;
}());
static assert({
S6751 s;
s.aa[7][56] = 57;
bug6751b(s.aa);
assert(s.aa[1][17] == 2);
assert(s.aa[7][56] == 57);
bug6751c(s.aa);
assert(s.aa.keys.length == 1);
assert(s.aa.values.length == 1);
return true;
}());
static assert({
S6751 s;
s.bb[19] = 97;
bug6751(s.bb);
assert(s.bb[1] == 2);
assert(s.bb[19] == 97);
return true;
}());
void bug6751c(ref int[int][int] aa)
{
aa = [38: [56 : 77]];
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7790
// AA foreach ref
struct S7790
{
size_t id;
}
size_t bug7790(S7790[string] tree)
{
foreach (k, ref v; tree)
v.id = 1;
return tree["a"].id;
}
static assert(bug7790(["a":S7790(0)]) == 1);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6765
// null AA.length
static assert({
int[int] w;
return w.length;
}() == 0);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6769
// AA.keys, AA.values with -inline
static assert({
double[char[3]] w = ["abc" : 2.3];
double[] z = w.values;
return w.keys.length;
}() == 1);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=4022
// AA.get
static assert({
int[int] aa = [58: 13];
int r = aa.get(58, 1000);
assert(r == 13);
r = aa.get(59, 1000);
return r;
}() == 1000);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6775
// AA.opApply
static assert({
int[int] aa = [58: 17, 45:6];
int valsum = 0;
int keysum = 0;
foreach (m; aa) // aaApply
{
valsum += m;
}
assert(valsum == 17 + 6);
valsum = 0;
foreach (n, m; aa) // aaApply2
{
valsum += m;
keysum += n;
}
assert(valsum == 17 + 6);
assert(keysum == 58 + 45);
// Check empty AA
valsum = 0;
int[int] bb;
foreach (m; bb)
{
++valsum;
}
assert(valsum == 0);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7890
// segfault struct with AA field
struct S7890
{
int[int] tab;
}
S7890 bug7890()
{
S7890 foo;
foo.tab[0] = 0;
return foo;
}
enum e7890 = bug7890();
/**************************************************
AA.remove
**************************************************/
static assert({
int[int] aa = [58: 17, 45:6];
aa.remove(45);
assert(aa.length == 1);
aa.remove(7);
assert(aa.length == 1);
aa.remove(58);
assert(aa.length == 0);
return true;
}());
/**************************************************
try, finally
**************************************************/
static assert({
int n = 0;
try
{
n = 1;
}
catch (Exception e)
{}
assert(n == 1);
try
{
n = 2;
}
catch (Exception e)
{}
finally
{
assert(n == 2);
n = 3;
}
assert(n == 3);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6800
// bad pointer casts
bool badpointer(int k)
{
int m = 6;
int* w = &m;
assert(*w == 6);
int[3] a = [17, 2, 21];
int* w2 = &a[2];
assert(*w2 == 21);
// cast int* to uint* is OK
uint* u1 = cast(uint*)w;
assert(*u1 == 6);
uint* u2 = cast(uint*)w2;
assert(*u2 == 21);
uint* u3 = cast(uint*)&m;
assert(*u3 == 6);
// cast int* to void* is OK
void* v1 = cast(void*)w;
void* v3 = &m;
void* v4 = &a[0];
// cast from void* back to int* is OK
int* t3 = cast(int*)v3;
assert(*t3 == 6);
int* t4 = cast(int*)v4;
assert(*t4 == 17);
// cast from void* to uint* is OK
uint* t1 = cast(uint*)v1;
assert(*t1 == 6);
// and check that they're real pointers
m = 18;
assert(*t1 == 18);
assert(*u3 == 18);
int** p = &w;
if (k == 1) // bad reinterpret
double *d1 = cast(double*)w;
if (k == 3) // bad reinterpret
char* d3 = cast(char*)w2;
if (k == 4) {
void* q1 = cast(void*)p; // OK-void is int*
void* *q = cast(void**)p; // OK-void is int
}
if (k == 5)
void*** q = cast(void***)p; // bad: too many *
if (k == 6) // bad reinterpret through void*
double* d1 = cast(double*)v1;
if (k == 7)
double* d7 = cast(double*)v4;
if (k == 8)
++v4; // can't do pointer arithmetic on void*
return true;
}
static assert(badpointer(4));
static assert(!is(typeof(compiles!(badpointer(1)))));
static assert( is(typeof(compiles!(badpointer(2)))));
static assert(!is(typeof(compiles!(badpointer(3)))));
static assert( is(typeof(compiles!(badpointer(4)))));
static assert(!is(typeof(compiles!(badpointer(5)))));
static assert(!is(typeof(compiles!(badpointer(6)))));
static assert(!is(typeof(compiles!(badpointer(7)))));
static assert(!is(typeof(compiles!(badpointer(8)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10211
// Allow casts S**->D**, when S*->D* is OK
int bug10211()
{
int m = 7;
int* x = &m;
int** y = &x;
assert(**y == 7);
uint* p = cast(uint*)x;
uint** q = cast(uint**)y;
return 1;
}
static assert(bug10211());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10568
// CTFE rejects function pointer safety casts
@safe void safetyDance() {}
int isItSafeToDance()
{
void function() @trusted yourfriends = &safetyDance;
void function() @safe nofriendsOfMine = yourfriends;
return 1;
}
static assert(isItSafeToDance());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12296
// CTFE rejects const compatible AA pointer cast
int test12296()
{
immutable x = [5 : 4];
auto aa = &x;
const(int[int])* y = aa;
return 1;
}
static assert(test12296());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9170
// Allow reinterpret casts float<->int
int f9170(float x)
{
return *(cast(int*)&x);
}
float i9170(int x)
{
return *(cast(float*)&x);
}
float u9170(uint x)
{
return *(cast(float*)&x);
}
int f9170arr(float[] x)
{
return *(cast(int*)&(x[1]));
}
long d9170(double x)
{
return *(cast(long*)&x);
}
int fref9170(ref float x)
{
return *(cast(int*)&x);
}
long dref9170(ref double x)
{
return *(cast(long*)&x);
}
bool bug9170()
{
float f = 1.25;
double d = 1.25;
assert(f9170(f) == 0x3FA0_0000);
assert(fref9170(f) == 0x3FA0_0000);
assert(d9170(d) == 0x3FF4_0000_0000_0000L);
assert(dref9170(d) == 0x3FF4_0000_0000_0000L);
float [3] farr = [0, 1.25, 0];
assert(f9170arr(farr) == 0x3FA0_0000);
int i = 0x3FA0_0000;
assert(i9170(i) == 1.25);
uint u = 0x3FA0_0000;
assert(u9170(u) == 1.25);
return true;
}
static assert(bug9170());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6792
// ICE with pointer cast of indexed array
struct S6792
{
int i;
}
static assert({
{
void* p;
p = [S6792(1)].ptr;
S6792 s = *(cast(S6792*)p);
assert(s.i == 1);
}
{
void*[] ary;
ary ~= [S6792(2)].ptr;
S6792 s = *(cast(S6792*)ary[0]);
assert(s.i == 2);
}
{
void*[7] ary;
ary[6]= [S6792(2)].ptr;
S6792 s = *(cast(S6792*)ary[6]);
assert(s.i == 2);
}
{
void* p;
p = [S6792(1)].ptr;
void*[7] ary;
ary[5]= p;
S6792 s = *(cast(S6792*)ary[5]);
assert(s.i == 1);
}
{
S6792*[string] aa;
aa["key"] = [S6792(3)].ptr;
const(S6792) s = *(cast(const(S6792)*)aa["key"]);
assert(s.i == 3);
}
{
S6792[string] blah;
blah["abc"] = S6792(6);
S6792*[string] aa;
aa["kuy"] = &blah["abc"];
const(S6792) s = *(cast(const(S6792)*)aa["kuy"]);
assert(s.i == 6);
void*[7] ary;
ary[5]= &blah["abc"];
S6792 t = *(cast(S6792*)ary[5]);
assert(t.i == 6);
int q = 6;
ary[3]= &q;
int gg = *(cast(int*)(ary[3]));
}
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7780
// array cast
int bug7780(int testnum)
{
int[] y = new int[2];
y[0] = 2000000;
if (testnum == 1)
{
void[] x = y;
return (cast(byte[])x)[1];
}
if (testnum == 2)
{
int[] x = y[0 .. 1];
return (cast(byte[])x)[1];
}
return 1;
}
static assert( is(typeof(compiles!(bug7780(0)))));
static assert(!is(typeof(compiles!(bug7780(1)))));
static assert(!is(typeof(compiles!(bug7780(2)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14028
// static array pointer that refers existing array elements.
int test14028a(size_t ofs)(bool ct)
{
int[4] a;
int[2]* p;
int num = ofs;
if (ct)
p = cast(int[2]*)&a[ofs]; // SymOffExp
else
p = cast(int[2]*)&a[num]; // CastExp + AddrExp
// pointers comparison
assert(cast(void*)a.ptr <= cast(void*)p);
assert(cast(void*)a.ptr <= cast(void*)&(*p)[0]);
assert(cast(void*)&a[0] <= cast(void*)p);
return 1;
}
static assert(test14028a!0(true));
static assert(test14028a!0(false));
static assert(test14028a!3(true));
static assert(test14028a!3(false));
static assert(!is(typeof(compiles!(test14028a!4(true)))));
static assert(!is(typeof(compiles!(test14028a!4(false)))));
int test14028b(int num)
{
int[4] a;
int[2]* p;
if (num == 1)
{
p = cast(int[2]*)&a[0]; // &a[0..2];
(*p)[0] = 1; // a[0] = 1
(*p)[1] = 2; // a[1] = 2
assert(a == [1,2,0,0]);
p = p + 1; // &a[0] -> &a[2]
(*p)[0] = 3; // a[2] = 3
(*p)[1] = 4; // a[3] = 4
assert(a == [1,2,3,4]);
}
if (num == 2)
{
p = cast(int[2]*)&a[1]; // &a[1..3];
(*p)[0] = 1; // a[1] = 1
p = p + 1; // &a[1..3] -> &a[3..5]
(*p)[0] = 2; // a[3] = 2
assert(a == [0,1,0,2]);
}
if (num == 3)
{
p = cast(int[2]*)&a[1]; // &a[1..3];
(*p)[0] = 1; // a[1] = 1
p = p + 1; // &a[1..3] -> &a[3..5]
(*p)[0] = 2; // a[3] = 2
(*p)[1] = 3; // a[4] = 3 (CTFE error)
}
if (num == 4)
{
p = cast(int[2]*)&a[0]; // &a[0..2];
p = p + 1; // &a[0..2] -> &a[2..4]
p = p + 1; // &a[2..4] -> &a[4..6] (ok)
}
if (num == 5)
{
p = cast(int[2]*)&a[1]; // &a[1..3];
p = p + 2; // &a[1..3] -> &a[5..7] (CTFE error)
}
return 1;
}
static assert(test14028b(1));
static assert(test14028b(2));
static assert(!is(typeof(compiles!(test14028b(3)))));
static assert(test14028b(4));
static assert(!is(typeof(compiles!(test14028b(5)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10275
// cast struct literals to immutable
struct Bug10275
{
uint[] ivals;
}
Bug10275 bug10275()
{
return Bug10275([1, 2, 3]);
}
int test10275()
{
immutable(Bug10275) xxx = cast(immutable(Bug10275))bug10275();
return 1;
}
static assert(test10275());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6851
// passing pointer by argument
void set6851(int* pn)
{
*pn = 20;
}
void bug6851()
{
int n = 0;
auto pn = &n;
*pn = 10;
assert(n == 10);
set6851(&n);
}
static assert({ bug6851(); return true; }());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7876
int* bug7876(int n) @system
{
int x;
auto ptr = &x;
if (n == 2)
ptr = null;
return ptr;
}
struct S7876
{
int* p;
}
S7876 bug7876b(int n) @system
{
int x;
S7876 s;
s.p = &x;
if (n == 11)
s.p = null;
return s;
}
int test7876(int n)
{
if (n >= 10)
{
S7876 m = bug7876b(n);
return 1;
}
int* p = bug7876(n);
return 1;
}
static assert( is(typeof(compiles!(test7876(2)))));
static assert(!is(typeof(compiles!(test7876(0)))));
static assert( is(typeof(compiles!(test7876(11)))));
static assert(!is(typeof(compiles!(test7876(10)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11824
int f11824(T)()
{
T[] arr = new T[](1);
T* getAddr(ref T a)
{
return &a;
}
getAddr(arr[0]);
return 1;
}
static assert(f11824!int()); // OK
static assert(f11824!(int[])()); // OK <- NG
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6817
// if converted to &&, only with -inline
static assert({
void toggle()
{
bool b;
if (b)
b = false;
}
toggle();
return true;
}());
/**************************************************
cast to void
**************************************************/
static assert({
cast(void)(71);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6816
// nested function can't access this
struct S6816
{
size_t foo()
{
return (){ return value +1 ; }();
}
size_t value;
}
enum s6816 = S6816().foo();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7277
// ICE nestedstruct.init.tupleof
struct Foo7277
{
int a;
int func()
{
int b;
void nested()
{
b = 7;
a = 10;
}
nested();
return a+b;
}
}
static assert(Foo7277().func() == 17);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10217
// ICE. CTFE version of 9315
bool bug10217()
{
struct S
{
int i;
void bar() {}
}
auto yyy = S.init.tupleof[$ - 1];
assert(!yyy);
return 1;
}
static assert(bug10217());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8276
// ICE
void bug8676(int n)
{
const int X1 = 4 + n;
const int X2 = 4;
int X3 = 4;
int bar1() { return X1; }
int bar2() { return X2; }
int bar3() { return X3; }
static assert(!is(typeof(compiles!(bar1()))));
static assert( is(typeof(compiles!(bar2()))));
static assert(!is(typeof(compiles!(bar3()))));
}
/**************************************************
classes and interfaces
**************************************************/
interface SomeInterface
{
int daz();
float bar(char);
int baz();
}
interface SomeOtherInterface
{
int xxx();
}
class TheBase : SomeInterface, SomeOtherInterface
{
int q = 88;
int rad = 61;
int a = 14;
int somebaseclassfunc() { return 28; }
int daz() { return 0; }
int baz() { return 0; }
int xxx() { return 762; }
int foo() { return q; }
float bar(char c) { return 3.6; }
}
class SomeClass : TheBase, SomeInterface
{
int gab = 9;
int fab;
int a = 17;
int b = 23;
override int foo() { return gab + a; }
override float bar(char c) { return 2.6; }
int something() { return 0; }
override int daz() { return 0; }
override int baz() { return 0; }
}
class Unrelated : TheBase
{
this(int x) { a = x; }
}
auto classtest1(int n)
{
SomeClass c = new SomeClass;
assert(c.a == 17);
assert(c.q == 88);
TheBase d = c;
assert(d.a == 14);
assert(d.q == 88);
if (n == 7)
{
// bad cast -- should fail
Unrelated u = cast(Unrelated)d;
assert(u is null);
}
SomeClass e = cast(SomeClass)d;
d.q = 35;
assert(c.q == 35);
assert(c.foo() == 9 + 17);
++c.a;
assert(c.foo() == 9 + 18);
assert(d.foo() == 9 + 18);
d = new TheBase;
SomeInterface fc = c;
SomeOtherInterface ot = c;
assert(fc.bar('x') == 2.6);
assert(ot.xxx() == 762);
fc = d;
ot = d;
assert(fc.bar('x') == 3.6);
assert(ot.xxx() == 762);
Unrelated u2 = new Unrelated(7);
assert(u2.a == 7);
return 6;
}
static assert(classtest1(1));
static assert(classtest1(2));
static assert(classtest1(7)); // https://issues.dlang.org/show_bug.cgi?id=7154
// can't initialize enum with not null class
SomeClass classtest2(int n)
{
return n == 5 ? (new SomeClass) : null;
}
static assert( is(typeof((){ enum const(SomeClass) xx = classtest2(2);}())));
static assert(!is(typeof((){ enum const(SomeClass) xx = classtest2(5);}())));
class RecursiveClass
{
int x;
this(int n) { x = n; }
RecursiveClass b;
void doit() { b = new RecursiveClass(7); b.x = 2;}
}
int classtest3()
{
RecursiveClass x = new RecursiveClass(17);
x.doit();
RecursiveClass y = x.b;
assert(y.x == 2);
assert(x.x == 17);
return 1;
}
static assert(classtest3());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12016
// class cast and qualifier reinterpret
class B12016 { }
class C12016 : B12016 { }
bool f12016(immutable B12016 b)
{
assert(b);
return true;
}
static assert(f12016(new immutable C12016));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10610
// ice immutable implicit conversion
class Bug10610(T)
{
int baz() immutable
{
return 1;
}
static immutable(Bug10610!T) min = new Bug10610!T();
}
void ice10610()
{
alias T10610 = Bug10610!(int);
static assert (T10610.min.baz());
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13141
// regression fix caused by 10610
struct MapResult13141(alias pred)
{
int[] range;
@property empty() { return range.length == 0; }
@property front() { return pred(range[0]); }
void popFront() { range = range[1 .. $]; }
}
string[] array13141(R)(R r)
{
typeof(return) result;
foreach (e; r)
result ~= e;
return result;
}
//immutable string[] splitterNames = [4].map!(e => "4").array();
immutable string[] splitterNames13141 = MapResult13141!(e => "4")([4]).array13141();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11587
// AA compare
static assert([1:2, 3:4] == [3:4, 1:2]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14325
// more AA comparisons
static assert([1:1] != [1:2, 2:1]); // OK
static assert([1:1] != [1:2]); // OK
static assert([1:1] != [2:1]); // OK <- Error
static assert([1:1, 2:2] != [3:3, 4:4]); // OK <- Error
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7147
// typeid()
static assert({
TypeInfo xxx = typeid(Object);
TypeInfo yyy = typeid(new Error("xxx"));
return true;
}());
int bug7147(int n)
{
Error err = n ? new Error("xxx") : null;
TypeInfo qqq = typeid(err);
return 1;
}
// Must not segfault if class is null
static assert(!is(typeof(compiles!(bug7147(0)))));
static assert( is(typeof(compiles!(bug7147(1)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14123
// identity TypeInfo objects
static assert({
bool eq(TypeInfo t1, TypeInfo t2)
{
return t1 is t2;
}
class C {}
struct S {}
assert( eq(typeid(C), typeid(C)));
assert(!eq(typeid(C), typeid(Object)));
assert( eq(typeid(S), typeid(S)));
assert(!eq(typeid(S), typeid(int)));
assert( eq(typeid(int), typeid(int)));
assert(!eq(typeid(int), typeid(long)));
Object o = new Object;
Object c = new C;
assert( eq(typeid(o), typeid(o)));
assert(!eq(typeid(c), typeid(o)));
assert(!eq(typeid(o), typeid(S)));
return 1;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6885
// wrong code with new array
struct S6885
{
int p;
}
int bug6885()
{
auto array = new double[1][2];
array[1][0] = 6;
array[0][0] = 1;
assert(array[1][0] == 6);
auto barray = new S6885[2];
barray[1].p = 5;
barray[0].p = 2;
assert(barray[1].p == 5);
return 1;
}
static assert(bug6885());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6886
// ICE with new array of dynamic arrays
int bug6886()
{
auto carray = new int[][2];
carray[1] = [6];
carray[0] = [4];
assert(carray[1][0] == 6);
return 1;
}
static assert(bug6886());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10198
// Multidimensional struct block initializer
struct Block10198
{
int[4][3] val;
}
int bug10198()
{
Block10198 pp = Block10198(67);
assert(pp.val[2][3] == 67);
assert(pp.val[1][3] == 67);
return 1;
}
static assert(bug10198());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14440
// Multidimensional block initialization should create distinct arrays for each elements
struct Matrix14440(E, size_t row, size_t col)
{
E[col][row] array2D;
@safe pure nothrow
this(E[row * col] numbers...)
{
foreach (r; 0 .. row)
{
foreach (c; 0 .. col)
{
array2D[r][c] = numbers[r * col + c];
}
}
}
}
void test14440()
{
// Replace 'enum' with 'auto' here and it will work fine.
enum matrix = Matrix14440!(int, 3, 3)(
1, 2, 3,
4, 5, 6,
7, 8, 9
);
static assert(matrix.array2D[0][0] == 1);
static assert(matrix.array2D[0][1] == 2);
static assert(matrix.array2D[0][2] == 3);
static assert(matrix.array2D[1][0] == 4);
static assert(matrix.array2D[1][1] == 5);
static assert(matrix.array2D[1][2] == 6);
static assert(matrix.array2D[2][0] == 7);
static assert(matrix.array2D[2][1] == 8);
static assert(matrix.array2D[2][2] == 9);
}
/****************************************************
* Exception chaining tests from xtest46.d
****************************************************/
class A75
{
pure static void raise(string s)
{
throw new Exception(s);
}
}
int test75()
{
int x = 0;
try
{
A75.raise("a");
}
catch (Exception e)
{
x = 1;
}
assert(x == 1);
return 1;
}
static assert(test75());
/****************************************************
* Exception chaining tests from test4.d
****************************************************/
int test4_test54()
{
int status = 0;
try
{
try
{
status++;
assert(status == 1);
throw new Exception("first");
}
finally
{
status++;
assert(status == 2);
status++;
throw new Exception("second");
}
}
catch (Exception e)
{
assert(e.msg == "first");
assert(e.next.msg == "second");
}
return true;
}
static assert(test4_test54());
void foo55()
{
try
{
Exception x = new Exception("second");
throw x;
}
catch (Exception e)
{
assert(e.msg == "second");
}
}
int test4_test55()
{
int status = 0;
try
{
try
{
status++;
assert(status == 1);
Exception x = new Exception("first");
throw x;
}
finally
{
status++;
assert(status == 2);
status++;
foo55();
}
}
catch (Exception e)
{
assert(e.msg == "first");
assert(status == 3);
}
return 1;
}
static assert(test4_test55());
/****************************************************
* Exception chaining tests from eh.d
****************************************************/
void bug1513outer()
{
int result1513;
void bug1513a()
{
throw new Exception("d");
}
void bug1513b()
{
try
{
try
{
bug1513a();
}
finally
{
result1513 |= 4;
throw new Exception("f");
}
}
catch (Exception e)
{
assert(e.msg == "d");
assert(e.next.msg == "f");
assert(!e.next.next);
}
}
void bug1513c()
{
try
{
try
{
throw new Exception("a");
}
finally
{
result1513 |= 1;
throw new Exception("b");
}
}
finally
{
bug1513b();
result1513 |= 2;
throw new Exception("c");
}
}
void bug1513()
{
result1513 = 0;
try
{
bug1513c();
}
catch (Exception e)
{
assert(result1513 == 7);
assert(e.msg == "a");
assert(e.next.msg == "b");
assert(e.next.next.msg == "c");
}
}
bug1513();
}
void collideone()
{
try
{
throw new Exception("x");
}
finally
{
throw new Exception("y");
}
}
void doublecollide()
{
try
{
try
{
try
{
throw new Exception("p");
}
finally
{
throw new Exception("q");
}
}
finally
{
collideone();
}
}
catch (Exception e)
{
assert(e.msg == "p");
assert(e.next.msg == "q");
assert(e.next.next.msg == "x");
assert(e.next.next.next.msg == "y");
assert(!e.next.next.next.next);
}
}
void collidetwo()
{
try
{
try
{
throw new Exception("p2");
}
finally
{
throw new Exception("q2");
}
}
finally
{
collideone();
}
}
void collideMixed()
{
int works = 6;
try
{
try
{
try
{
throw new Exception("e");
}
finally
{
throw new Error("t");
}
}
catch (Exception f)
{
// Doesn't catch, because Error is chained to it.
works += 2;
}
}
catch (Error z)
{
works += 4;
assert(z.msg == "t"); // Error comes first
assert(z.next is null);
assert(z.bypassedException.msg == "e");
}
assert(works == 10);
}
class AnotherException : Exception
{
this(string s)
{
super(s);
}
}
void multicollide()
{
try
{
try
{
try
{
try
{
throw new Exception("m2");
}
finally
{
throw new AnotherException("n2");
}
}
catch (AnotherException s)
{
// Not caught -- we needed to catch the root cause "m2", not
// just the collateral "n2" (which would leave m2 uncaught).
assert(0);
}
}
finally
{
collidetwo();
}
}
catch (Exception f)
{
assert(f.msg == "m2");
assert(f.next.msg == "n2");
Throwable e = f.next.next;
assert(e.msg == "p2");
assert(e.next.msg == "q2");
assert(e.next.next.msg == "x");
assert(e.next.next.next.msg == "y");
assert(!e.next.next.next.next);
}
}
int testsFromEH()
{
bug1513outer();
doublecollide();
collideMixed();
multicollide();
return 1;
}
static assert(testsFromEH());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6901
// With + synchronized statements
struct With1
{
int a;
int b;
}
class Foo6
{
}
class Foo32
{
struct Bar
{
int x;
}
}
class Base56
{
private string myfoo;
private string mybar;
// Get/set properties that will be overridden.
void foo(string s) { myfoo = s; }
string foo() { return myfoo; }
// Get/set properties that will not be overridden.
void bar(string s) { mybar = s; }
string bar() { return mybar; }
}
class Derived56 : Base56
{
alias Base56.foo foo; // Bring in Base56's foo getter.
override void foo(string s) { super.foo = s; } // Override foo setter.
}
int testwith()
{
With1 x = With1(7);
with (x)
{
a = 2;
}
assert(x.a == 2);
// from test11.d
Foo6 foo6 = new Foo6();
with (foo6)
{
int xx;
xx = 4;
}
with (new Foo32)
{
Bar z;
z.x = 5;
}
Derived56 d = new Derived56;
with (d)
{
foo = "hi";
d.foo = "hi";
bar = "hi";
assert(foo == "hi");
assert(d.foo == "hi");
assert(bar == "hi");
}
int w = 7;
synchronized
{
++w;
}
assert(w == 8);
return 1;
}
static assert(testwith());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9236
// ICE switch with(EnumType)
enum Command9236
{
Char,
Any,
};
bool bug9236(Command9236 cmd)
{
int n = 0;
with (Command9236) switch (cmd)
{
case Any:
n = 1;
break;
default:
n = 2;
}
assert(n == 1);
switch (cmd) with (Command9236)
{
case Any:
return true;
default:
return false;
}
}
static assert(bug9236(Command9236.Any));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6416
// static struct declaration
static assert({
static struct S { int y = 7; }
S a;
a.y += 6;
assert(a.y == 13);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10499
// static template struct declaration
static assert({
static struct Result() {}
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13757
// extern(C) alias declaration
static assert({
alias FP1 = extern(C) int function();
alias extern(C) int function() FP2;
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6522
// opAssign + foreach ref
struct Foo6522
{
bool b = false;
void opAssign(int x)
{
this.b = true;
}
}
bool foo6522()
{
Foo6522[1] array;
foreach (ref item; array)
item = 1;
return true;
}
static assert(foo6522());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7245
// pointers + foreach ref
int bug7245(int testnum)
{
int[3] arr;
arr[0] = 4;
arr[1] = 6;
arr[2] = 8;
int* ptr;
foreach (i, ref p; arr)
{
if (i == 1)
ptr = &p;
if (testnum == 1)
p = 5;
}
return *ptr;
}
static assert(bug7245(0) == 6);
static assert(bug7245(1) == 5);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8498
// modifying foreach
// https://issues.dlang.org/show_bug.cgi?id=7658
// foreach ref
// https://issues.dlang.org/show_bug.cgi?id=8539
// nested funcs, ref param, -inline
int bug8498()
{
foreach (ref i; 0 .. 5)
{
assert(i == 0);
i = 100;
}
return 1;
}
static assert(bug8498());
string bug7658()
{
string[] children = ["0"];
foreach (ref child; children)
child = "1";
return children[0];
}
static assert(bug7658() == "1");
int bug8539()
{
static void one(ref int x)
{
x = 1;
}
static void go()
{
int y;
one(y);
assert(y == 1); // fails with -inline
}
go();
return 1;
}
static assert(bug8539());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7874
// https://issues.dlang.org/show_bug.cgi?id=13297
// https://issues.dlang.org/show_bug.cgi?id=13740
// better lvalue handling
int bug7874(int x){ return ++x = 1; }
static assert(bug7874(0) == 1);
// ----
struct S13297
{
int* p;
}
void f13297(ref int* p)
{
p = cast(int*) 1;
assert(p); // passes
}
static assert(
{
S13297 s;
f13297(s.p);
return s.p != null; // false
}());
// ----
class R13740
{
int e;
bool empty = false;
@property ref front() { return e; }
void popFront() { empty = true; }
}
static assert({
auto r = new R13740();
foreach (ref e; r)
e = 42;
assert(r.e == 42); /* fails in CTFE */
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6919
void bug6919(int* val)
{
*val = 1;
}
void test6919()
{
int n;
bug6919(&n);
assert(n == 1);
}
static assert({ test6919(); return true; }());
void bug6919b(string* val)
{
*val = "1";
}
void test6919b()
{
string val;
bug6919b(&val);
assert(val == "1");
}
static assert({ test6919b(); return true; }());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6995
struct Foo6995
{
static size_t index(size_t v)()
{
return v;
}
}
static assert(Foo6995.index!(27)() == 27);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7043
// ref with -inline
int bug7043(S)(ref int x)
{
return x;
}
static assert({
int i = 416;
return bug7043!(char)(i);
}() == 416);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6037
// recursive ref
void bug6037(ref int x, bool b)
{
int w = 3;
if (b)
{
bug6037(w, false);
assert(w == 6);
}
else
{
x = 6;
assert(w == 3); // fails
}
}
int bug6037outer()
{
int q;
bug6037(q, true);
return 401;
}
static assert(bug6037outer() == 401);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14299
// [REG2.067a], more than one depth of recursive call with ref
string gen14299(int max, int idx, ref string name)
{
string ret;
name = [cast(char)(idx + '0')];
ret ~= name;
if (idx < max)
{
string subname;
ret ~= gen14299(max, idx + 1, subname);
}
ret ~= name;
return ret;
}
string test14299(int max)
{
string n;
return gen14299(max, 0, n);
}
static assert(test14299(1) == "0110"); // OK <- fail
static assert(test14299(2) == "012210"); // OK <- ICE
static assert(test14299(3) == "01233210");
static assert(test14299(4) == "0123443210");
static assert(test14299(5) == "012345543210");
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7940
// wrong code for complicated assign
struct Bug7940
{
int m;
}
struct App7940
{
Bug7940[] x;
}
int bug7940()
{
Bug7940[2] y;
App7940 app;
app.x = y[0 .. 1];
app.x[0].m = 12;
assert(y[0].m == 12);
assert(app.x[0].m == 12);
return 1;
}
static assert(bug7940());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10298
// wrong code for struct array literal init
struct Bug10298
{
int m;
}
int bug10298()
{
Bug10298[1] y = [Bug10298(78)];
y[0].m = 6;
assert(y[0].m == 6);
// Root cause
Bug10298[1] x;
x[] = [cast(const Bug10298)(Bug10298(78))];
assert(x[0].m == 78);
return 1;
}
static assert(bug10298());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7266
// dotvar ref parameters
struct S7266 { int a; }
bool bug7266()
{
S7266 s;
s.a = 4;
bar7266(s.a);
assert(s.a == 5);
out7266(s.a);
assert(s.a == 7);
return true;
}
void bar7266(ref int b)
{
b = 5;
assert(b == 5);
}
void out7266(out int b)
{
b = 7;
assert(b == 7);
}
static assert(bug7266());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9982
// dotvar assign through pointer
struct Bug9982
{
int a;
}
int test9982()
{
Bug9982 x;
int*q = &x.a;
*q = 99;
assert(x.a == 99);
return 1;
}
static assert(test9982());
// https://issues.dlang.org/show_bug.cgi?id=9982
// rejects-valid case
struct SS9982
{
Bug9982 s2;
this(Bug9982 s1)
{
s2.a = 6;
emplace9982(&s2, s1);
assert(s2.a == 3);
}
}
void emplace9982(Bug9982* chunk, Bug9982 arg)
{
*chunk = arg;
}
enum s9982 = Bug9982(3);
enum p9982 = SS9982(s9982);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11618
// dotvar assign through casted pointer
struct Tuple11618(T...)
{
T field;
alias field this;
}
static assert({
Tuple11618!(immutable dchar) result = void;
auto addr = cast(dchar*)&result[0];
*addr = dchar.init;
return (result[0] == dchar.init);
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7143
// 'is' for classes
class C7143
{
int x;
}
int bug7143(int test)
{
C7143 c = new C7143;
C7143 d = new C7143;
if (test == 1)
{
if (c)
return c.x + 8;
return -1;
}
if (test == 2)
{
if (c is null)
return -1;
return c.x + 45;
}
if (test == 3)
{
if (c is c)
return 58;
}
if (test == 4)
{
if (c !is c)
return -1;
else
return 48;
}
if (test == 6)
d = c;
if (test == 5 || test == 6)
{
if (c is d)
return 188;
else
return 48;
}
return -1;
}
static assert(bug7143(1) == 8);
static assert(bug7143(2) == 45);
static assert(bug7143(3) == 58);
static assert(bug7143(4) == 48);
static assert(bug7143(5) == 48);
static assert(bug7143(6) == 188);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7147
// virtual function calls from base class
class A7147
{
int foo() { return 0; }
int callfoo()
{
return foo();
}
}
class B7147 : A7147
{
override int foo() { return 1; }
}
int test7147()
{
A7147 a = new B7147;
return a.callfoo();
}
static assert(test7147() == 1);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7158
class C7158
{
bool b() { return true; }
}
struct S7158
{
C7158 c;
}
bool test7158()
{
S7158 s = S7158(new C7158);
return s.c.b;
}
static assert(test7158());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8484
class C8484
{
int n;
int b() { return n + 3; }
}
struct S
{
C8484 c;
}
int t8484(ref C8484 c)
{
return c.b();
}
int test8484()
{
auto s = S(new C8484);
s.c.n = 4;
return t8484(s.c);
}
static assert(test8484() == 7);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7419
struct X7419
{
double x;
this(double x)
{
this.x = x;
}
}
void bug7419()
{
enum x = {
auto p = X7419(3);
return p.x;
}();
static assert(x == 3);
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9445
// ice
template c9445(T...) { }
void ice9445(void delegate() expr, void function() f2)
{
static assert(!is(typeof(c9445!(f2()))));
static assert(!is(typeof(c9445!(expr()))));
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10452
// delegate ==
struct S10452
{
bool func() { return true; }
}
struct Outer10452
{
S10452 inner;
}
class C10452
{
bool func() { return true; }
}
bool delegate() ref10452(return ref S10452 s)
{
return &s.func;
}
bool test10452()
{
bool delegate() bar = () { return true; };
assert(bar !is null);
assert(bar is bar);
S10452 bag;
S10452[6] bad;
Outer10452 outer;
C10452 tag = new C10452;
auto rat = &outer.inner.func;
assert(rat == rat);
auto tat = &tag.func;
assert(tat == tat);
auto bat = &outer.inner.func;
auto mat = &bad[2].func;
assert(mat is mat);
assert(rat == bat);
auto zat = &bag.func;
auto cat = &bag.func;
assert(zat == zat);
assert(zat == cat);
auto drat = ref10452(bag);
assert(cat == drat);
assert(drat == drat);
drat = ref10452(bad[2]);
assert( drat == mat);
assert(tat != rat);
assert(zat != rat);
assert(rat != cat);
assert(zat != bar);
assert(tat != cat);
cat = bar;
assert(cat == bar);
return true;
}
static assert(test10452());
/**************************************************/
//https://issues.dlang.org/show_bug.cgi?id=7162
// https://issues.dlang.org/show_bug.cgi?id=4711
void f7162() { }
bool ice7162()
{
false && f7162();
false || f7162();
false && f7162(); // https://issues.dlang.org/show_bug.cgi?id=4711
true && f7162();
return true;
}
static assert(ice7162());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=8857
// only with -inline (creates an &&)
struct Result8857 { char[] next; }
void bug8857()()
{
Result8857 r;
r.next = null;
if (true)
{
auto next = r.next;
}
}
static assert({
bug8857();
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7527
struct Bug7527
{
char[] data;
}
enum bug7527 = ()
{
auto app = Bug7527();
app.data.ptr[0 .. 1] = "x";
return 1;
};
static assert(!is(typeof(compiles!(bug7527()))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7527
int bug7380;
static assert(!is(typeof( compiles!(
(){
return &bug7380;
}()
))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7165
struct S7165
{
int* ptr;
bool f() const { return !!ptr; }
}
static assert(!S7165().f());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7187
int[] f7187() { return [0]; }
int[] f7187b(int n) { return [0]; }
int g7187(int[] r)
{
auto t = r[0 .. 0];
return 1;
}
static assert(g7187(f7187()));
static assert(g7187(f7187b(7)));
struct S7187 { const(int)[] field; }
const(int)[] f7187c()
{
auto s = S7187([0]);
return s.field;
}
bool g7187c(const(int)[] r)
{
auto t = r[0 .. 0];
return true;
}
static assert(g7187c(f7187c()));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6933
// struct destructors
struct Bug6933
{
int x = 3;
~this() { }
}
int test6933()
{
Bug6933 q;
assert(q.x == 3);
return 3;
}
static assert(test6933());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7197
int foo7197(int[] x...)
{
return 1;
}
template bar7197(y...)
{
enum int bar7197 = foo7197(y);
}
enum int bug7197 = 7;
static assert(bar7197!(bug7197));
/**************************************************
Enum string compare
**************************************************/
enum EScmp : string { a = "aaa" }
bool testEScmp()
{
EScmp x = EScmp.a;
assert(x < "abc");
return true;
}
static assert(testEScmp());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7667
bool baz7667(int[] vars...)
{
return true;
}
struct S7667
{
static void his(int n)
{
static assert(baz7667(2));
}
}
bool bug7667()
{
S7667 unused;
unused.his(7);
return true;
}
enum e7667 = bug7667();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7536
bool bug7536(string expr)
{
return true;
}
void vop()
{
const string x7536 = "x";
static assert(bug7536(x7536));
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6681
// unions
struct S6681
{
this(int a, int b) { this.a = b; this.b = a; }
union
{
ulong g;
struct { int a, b; };
}
}
static immutable S6681 s6681 = S6681(0, 1);
bool bug6681(int test)
{
S6681 x = S6681(0, 1);
x.g = 5;
auto u = &x.g;
auto v = &x.a;
long w = *u;
int z;
assert(w == 5);
if (test == 4)
z = *v; // error
x.a = 2; // invalidate g, and hence u.
if (test == 1)
w = *u; // error
z = *v;
assert(z == 2);
x.g = 6;
w = *u;
assert(w == 6);
if (test == 3)
z = *v;
return true;
}
static assert(bug6681(2));
static assert(!is(typeof(compiles!(bug6681(1)))));
static assert(!is(typeof(compiles!(bug6681(3)))));
static assert(!is(typeof(compiles!(bug6681(4)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9113
// ICE with struct in union
union U9113
{
struct M
{
int y;
}
int xx;
}
int bug9113(T)()
{
U9113 x;
x.M.y = 10; // error, need 'this'
return 1;
}
static assert(!is(typeof(compiles!(bug9113!(int)()))));
/**************************************************
Creation of unions
**************************************************/
union UnionTest1
{
int x;
float y;
}
int uniontest1()
{
UnionTest1 u = UnionTest1(1);
return 1;
}
static assert(uniontest1());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=6438
// void
struct S6438
{
int a;
int b = void;
}
void fill6438(int[] arr, int testnum)
{
if (testnum == 2)
{
auto u = arr[0];
}
foreach (ref x; arr)
x = 7;
auto r = arr[0];
S6438[2] s;
auto p = &s[0].b;
if (testnum == 3)
{
auto v = *p;
}
}
bool bug6438(int testnum)
{
int[4] stackSpace = void;
fill6438(stackSpace[], testnum);
assert(stackSpace == [7, 7, 7, 7]);
return true;
}
static assert( is(typeof(compiles!(bug6438(1)))));
static assert(!is(typeof(compiles!(bug6438(2)))));
static assert(!is(typeof(compiles!(bug6438(3)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10994
// void static array members
struct Bug10994
{
ubyte[2] buf = void;
}
static bug10994 = Bug10994.init;
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10937
// struct inside union
struct S10937
{
union
{
ubyte[1] a;
struct
{
ubyte b;
}
}
this(ubyte B)
{
if (B > 6)
this.b = B;
else
this.a[0] = B;
}
}
enum test10937 = S10937(7);
enum west10937 = S10937(2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13831
struct Vector13831()
{
}
struct Coord13831
{
union
{
struct { short x; }
Vector13831!() vector;
}
}
struct Chunk13831
{
this(Coord13831)
{
coord = coord;
}
Coord13831 coord;
static const Chunk13831* unknownChunk = new Chunk13831(Coord13831());
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7732
struct AssociativeArray
{
int* impl;
int f()
{
if (impl !is null)
auto x = *impl;
return 1;
}
}
int test7732()
{
AssociativeArray aa;
return aa.f;
}
static assert(test7732());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7784
struct Foo7784
{
void bug()
{
tab["A"] = Bar7784(&this);
auto pbar = "A" in tab;
auto bar = *pbar;
}
Bar7784[string] tab;
}
struct Bar7784
{
Foo7784* foo;
int val;
}
bool ctfe7784()
{
auto foo = Foo7784();
foo.bug();
return true;
}
static assert(ctfe7784());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7781
static assert(({ return true; }()));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7785
bool bug7785(int n)
{
int val = 7;
auto p = &val;
if (n == 2)
{
auto ary = p[0 .. 1];
}
auto x = p[0];
val = 6;
assert(x == 7);
if (n == 3)
p[0 .. 1] = 1;
return true;
}
static assert(bug7785(1));
static assert(!is(typeof(compiles!(bug7785(2)))));
static assert(!is(typeof(compiles!(bug7785(3)))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7987
class C7987
{
int m;
}
struct S7987
{
int* p;
C7987 c;
}
bool bug7987()
{
int[7] q;
int[][2] b = q[0 .. 5];
assert(b == b);
assert(b is b);
C7987 c1 = new C7987;
C7987 c2 = new C7987;
S7987 s, t;
s.p = &q[0];
t.p = &q[1];
assert(s != t);
s.p = &q[1];
/*assert(s == t);*/ assert(s.p == t.p);
s.c = c1;
t.c = c2;
/*assert(s != t);*/ assert(s.c !is t.c);
assert(s !is t);
s.c = c2;
/*assert(s == t);*/ assert(s.p == t.p && s.c is t.c);
assert(s is t);
return true;
}
static assert(bug7987());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10579
// typeinfo.func() must not segfault
static assert(!is(typeof(compiles!(typeid(int).toString.length))));
class Bug10579
{
int foo() { return 1; }
}
Bug10579 uninitialized10579;
static assert(!is(typeof(compiles!(uninitialized10579.foo()))));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10804
// mixin ArrayLiteralExp typed string
void test10804()
{
String identity(String)(String a) { return a; }
string cfun()
{
char[] s;
s.length = 8 + 2 + (2) + 1 + 2;
s[] = "identity(`Ω`c)"c[];
return cast(string)s; // Return ArrayLiteralExp as the CTFE result
}
{
enum a1 = "identity(`Ω`c)"c;
enum a2 = cfun();
static assert(cast(ubyte[])mixin(a1) == [0xCE, 0xA9]);
static assert(cast(ubyte[])mixin(a2) == [0xCE, 0xA9]); // should pass
}
wstring wfun()
{
wchar[] s;
s.length = 8 + 2 + (2) + 1 + 2;
s[] = "identity(`\U0002083A`w)"w[];
return cast(wstring)s; // Return ArrayLiteralExp as the CTFE result
}
{
enum a1 = "identity(`\U0002083A`w)"w;
enum a2 = wfun();
static assert(cast(ushort[])mixin(a1) == [0xD842, 0xDC3A]);
static assert(cast(ushort[])mixin(a2) == [0xD842, 0xDC3A]);
}
dstring dfun()
{
dchar[] s;
s.length = 8 + 2 + (1) + 1 + 2;
s[] = "identity(`\U00101000`d)"d[];
return cast(dstring)s; // Return ArrayLiteralExp as the CTFE result
}
{
enum a1 = "identity(`\U00101000`d)"d;
enum a2 = dfun();
static assert(cast(uint[])mixin(a1) == [0x00101000]);
static assert(cast(uint[])mixin(a2) == [0x00101000]);
}
}
/******************************************************/
struct B73 {}
struct C73 { B73 b; }
C73 func73() { C73 b = void; b.b = B73(); return b; }
C73 test73 = func73();
/******************************************************/
struct S74
{
int[1] n;
static S74 test(){ S74 ret = void; ret.n[0] = 0; return ret; }
}
enum Test74 = S74.test();
/******************************************************/
static bool bug8865()
in
{
int x = 0;
label:
foreach (i; (++x) .. 3)
{
if (i == 1)
continue label; // doesn't work.
else
break label; // doesn't work.
}
}
out
{
int x = 0;
label:
foreach (i; (++x) .. 3)
{
if (i == 1)
continue label; // doesn't work.
else
break label; // doesn't work.
}
}
do
{
int x = 0;
label:
foreach (i; (++x) .. 3)
{
if (i == 1)
continue label; // works.
else
break label; // works.
}
return true;
}
static assert(bug8865());
/******************************************************/
// https://issues.dlang.org/show_bug.cgi?id=15450
// labeled foreach + continue/break
static assert({
L1:
foreach (l; [0])
continue L1;
L2:
foreach (l; [0])
break L2;
return true;
}());
struct Test75
{
this(int) pure {}
}
/******************************************************/
static assert( __traits(compiles, { static shared(Test75*) t75 = new shared(Test75)(0); return t75; }));
static assert( __traits(compiles, { static shared(Test75)* t75 = new shared(Test75)(0); return t75; }));
static assert( __traits(compiles, { static __gshared Test75* t75 = new Test75(0); return t75; }));
static assert( __traits(compiles, { static const(Test75*) t75 = new const(Test75)(0); return t75; }));
static assert( __traits(compiles, { static immutable Test75* t75 = new immutable(Test75)(0); return t75; }));
static assert(!__traits(compiles, { static Test75* t75 = new Test75(0); return t75; }));
/+
static assert(!__traits(compiles, { enum t75 = new shared(Test75)(0); return t75; }));
static assert(!__traits(compiles, { enum t75 = new Test75(0); return t75; }));
static assert(!__traits(compiles, { enum shared(Test75)* t75 = new shared(Test75)(0); return t75; }));
static assert(!__traits(compiles, { enum Test75* t75 = new Test75(0); return t75; }));
static assert( __traits(compiles, { enum t75 = new const(Test75)(0); return t75;}));
static assert( __traits(compiles, { enum t75 = new immutable(Test75)(0); return t75;}));
static assert( __traits(compiles, { enum const(Test75)* t75 = new const(Test75)(0); return t75;}));
static assert( __traits(compiles, { enum immutable(Test75)* t75 = new immutable(Test75)(0); return t75;}));
+/
/******************************************************/
class Test76
{
this(int) pure {}
}
/+
static assert(!__traits(compiles, { enum t76 = new shared(Test76)(0); return t76;}));
static assert(!__traits(compiles, { enum t76 = new Test76(0); return t76;}));
static assert(!__traits(compiles, { enum shared(Test76) t76 = new shared(Test76)(0); return t76;}));
static assert(!__traits(compiles, { enum Test76 t76 = new Test76(0); return t76;}));
static assert( __traits(compiles, { enum t76 = new const(Test76)(0); return t76;}));
static assert( __traits(compiles, { enum t76 = new immutable(Test76)(0); return t76;}));
static assert( __traits(compiles, { enum const(Test76) t76 = new const(Test76)(0); return t76;}));
static assert( __traits(compiles, { enum immutable(Test76) t76 = new immutable(Test76)(0); return t76;}));
+/
/******************************************************/
static assert( __traits(compiles, { static shared Test76 t76 = new shared(Test76)(0); return t76; }));
static assert( __traits(compiles, { static shared(Test76) t76 = new shared(Test76)(0); return t76; }));
static assert( __traits(compiles, { static __gshared Test76 t76 = new Test76(0); return t76; }));
static assert( __traits(compiles, { static const Test76 t76 = new const(Test76)(0); return t76; }));
static assert( __traits(compiles, { static immutable Test76 t76 = new immutable Test76(0); return t76; }));
static assert(!__traits(compiles, { static Test76 t76 = new Test76(0); return t76; }));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=5678
struct Bug5678
{
this(int) {}
}
static assert(!__traits(compiles, { enum const(Bug5678)* b5678 = new const(Bug5678)(0); return b5678; }));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10782
// run semantic2 for class field
enum e10782 = 0;
class C10782 { int x = e10782; }
string f10782()
{
auto c = new C10782();
return "";
}
mixin(f10782());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=10929
// NRVO support in CTFE
struct S10929
{
this(this)
{
postblitCount++;
}
~this()
{
dtorCount++;
}
int payload;
int dtorCount;
int postblitCount;
}
auto makeS10929()
{
auto s = S10929(42, 0, 0);
return s;
}
bool test10929()
{
auto s = makeS10929();
assert(s.postblitCount == 0);
assert(s.dtorCount == 0);
return true;
};
static assert(test10929());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9245
// support postblit call on array assignments
bool test9245()
{
int postblits = 0;
struct S
{
this(this)
{
++postblits;
}
}
S s;
S[2] a;
assert(postblits == 0);
{
S[2] arr = s;
assert(postblits == 2);
arr[] = s;
assert(postblits == 4);
postblits = 0;
S[2] arr2 = arr;
assert(postblits == 2);
arr2 = arr;
assert(postblits == 4);
postblits = 0;
const S[2] constArr = s;
assert(postblits == 2);
postblits = 0;
const S[2] constArr2 = arr;
assert(postblits == 2);
postblits = 0;
}
{
S[2][2] arr = s;
assert(postblits == 4);
arr[] = a;
assert(postblits == 8);
postblits = 0;
S[2][2] arr2 = arr;
assert(postblits == 4);
arr2 = arr;
assert(postblits == 8);
postblits = 0;
const S[2][2] constArr = s;
assert(postblits == 4);
postblits = 0;
const S[2][2] constArr2 = arr;
assert(postblits == 4);
postblits = 0;
}
return true;
}
static assert(test9245());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12906
// don't call postblit on blit initializing
struct S12906 { this(this) { assert(0); } }
static assert({
S12906[1] arr;
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11510
// support overlapped field access in CTFE
struct S11510
{
union
{
size_t x;
int* y; // pointer field
}
}
bool test11510()
{
S11510 s;
s.y = [1,2,3].ptr; // writing overlapped pointer field is OK
assert(s.y[0 .. 3] == [1,2,3]); // reading valid field is OK
s.x = 10;
assert(s.x == 10);
// There's no reinterpretation between S.x and S.y
return true;
}
static assert(test11510());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11534
// subtitude inout
struct MultiArray11534
{
void set(size_t[] sizes...)
{
storage = new size_t[5];
}
@property auto raw_ptr() inout
{
return storage.ptr + 1;
}
size_t[] storage;
}
enum test11534 = () {
auto m = MultiArray11534();
m.set(3,2,1);
auto start = m.raw_ptr; //this trigger the bug
//auto start = m.storage.ptr + 1; //this obviously works
return 0;
}();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11941
// Regression of 11534 fix
void takeConst11941(const string[]) {}
string[] identity11941(string[] x) { return x; }
bool test11941a()
{
struct S { string[] a; }
S s;
takeConst11941(identity11941(s.a));
s.a ~= [];
return true;
}
static assert(test11941a());
bool test11941b()
{
struct S { string[] a; }
S s;
takeConst11941(identity11941(s.a));
s.a ~= "foo"; /* Error refers to this line (15), */
string[] b = s.a[]; /* but only when this is here. */
return true;
}
static assert(test11941b());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11535
// element-wise assignment from string to ubyte array literal
struct Hash11535
{
ubyte[6] _buffer;
void put(scope const(ubyte)[] data...)
{
uint i = 0, index = 0;
auto inputLen = data.length;
(&_buffer[index])[0 .. inputLen - i] = (&data[i])[0 .. inputLen - i];
}
}
auto md5_digest11535(T...)(scope const T data)
{
Hash11535 hash;
hash.put(cast(const(ubyte[]))data[0]);
return hash._buffer;
}
static assert(md5_digest11535(`TEST`) == [84, 69, 83, 84, 0, 0]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11540
// goto label + try-catch-finally / with statement
static assert(()
{
// jump inside TryCatchStatement.body
{
bool c = false;
try
{
if (c) // need to bypass front-end optimization
throw new Exception("");
else
goto L2;
L2:
;
}
catch (Exception e) {}
}
// exit from TryCatchStatement.body
{
bool c = false;
try
{
if (c) // need to bypass front-end optimization
throw new Exception("");
else
goto L3;
}
catch (Exception e) {}
c = true;
L3:
assert(!c);
}
return 1;
}());
static assert(()
{
// enter to TryCatchStatement.catches which has no exception variable
{
bool c = false;
goto L1;
try
{
c = true;
}
catch (Exception/* e*/)
{
L1:
;
}
assert(c == false);
}
// jump inside TryCatchStatement.catches
{
bool c = false;
try
{
throw new Exception("");
}
catch (Exception e)
{
goto L2;
c = true;
L2:
;
}
assert(c == false);
}
// exit from TryCatchStatement.catches
{
bool c = false;
try
{
throw new Exception("");
}
catch (Exception e)
{
goto L3;
c = true;
}
L3:
assert(c == false);
}
return 1;
}());
static assert(()
{
// jump inside TryFinallyStatement.body
{
try
{
goto L2;
L2: ;
}
finally {}
}
// exit from TryFinallyStatement.body
{
bool c = false;
try
{
goto L3;
}
finally {}
c = true;
L3:
assert(!c);
}
// enter in / exit out from finally block is rejected in semantic analysis
// jump inside TryFinallyStatement.finalbody
{
bool c = false;
try
{
}
finally
{
goto L4;
c = true;
L4:
assert(c == false);
}
}
return 1;
}());
static assert(()
{
{
bool c = false;
with (Object.init)
{
goto L2;
c = true;
L2:
;
}
assert(c == false);
}
{
bool c = false;
with (Object.init)
{
goto L3;
c = true;
}
L3:
assert(c == false);
}
return 1;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11627
//cast dchar to char at compile time on AA assignment
bool test11627()
{
char[ubyte] toCharTmp;
dchar letter = 'A';
//char c = cast(char)letter; // OK
toCharTmp[0] = cast(char)letter; // NG
return true;
}
static assert(test11627());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=11664
// ignore function local static variables
bool test11664()
{
static int x;
static int y = 1;
return true;
}
static assert(test11664());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12110
// operand of dereferencing does not need to be an lvalue
struct SliceOverIndexed12110
{
Uint24Array12110* arr;
@property front(uint val)
{
arr.dupThisReference();
}
}
struct Uint24Array12110
{
ubyte[] data;
this(ubyte[] range)
{
data = range;
SliceOverIndexed12110(&this).front = 0;
assert(data.length == range.length * 2);
}
void dupThisReference()
{
auto new_data = new ubyte[data.length * 2];
data = new_data;
}
}
static m12110 = Uint24Array12110([0x80]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12310
// heap allocation for built-in sclar types
bool test12310()
{
auto p1 = new int, p2 = p1;
assert(*p1 == 0);
assert(*p2 == 0);
*p1 = 10;
assert(*p1 == 10);
assert(*p2 == 10);
auto q1 = new int(3), q2 = q1;
assert(*q1 == 3);
assert(*q2 == 3);
*q1 = 20;
assert(*q1 == 20);
assert(*q2 == 20);
return true;
}
static assert(test12310());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12499
// initialize TupleDeclaraion in CTFE
auto f12499()
{
//Initialize 3 ints to 5.
TypeTuple!(int, int, int) a = 5;
return a[0]; //Error: variable _a_field_0 cannot be read at compile time
}
static assert(f12499() == 5);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12602
// slice in struct literal members
struct Result12602
{
uint[] source;
}
auto wrap12602a(uint[] r)
{
return Result12602(r);
}
auto wrap12602b(uint[] r)
{
Result12602 x;
x.source = r;
return x;
}
auto testWrap12602a()
{
uint[] dest = [1, 2, 3, 4];
auto ra = wrap12602a(dest[0 .. 2]);
auto rb = wrap12602a(dest[2 .. 4]);
foreach (i; 0 .. 2)
rb.source[i] = ra.source[i];
assert(ra.source == [1,2]);
assert(rb.source == [1,2]);
assert(&ra.source[0] == &dest[0]);
assert(&rb.source[0] == &dest[2]);
assert(dest == [1,2,1,2]);
return dest;
}
auto testWrap12602b()
{
uint[] dest = [1, 2, 3, 4];
auto ra = wrap12602b(dest[0 .. 2]);
auto rb = wrap12602b(dest[2 .. 4]);
foreach (i; 0 .. 2)
rb.source[i] = ra.source[i];
assert(ra.source == [1,2]);
assert(rb.source == [1,2]);
assert(&ra.source[0] == &dest[0]);
assert(&rb.source[0] == &dest[2]);
assert(dest == [1,2,1,2]);
return dest;
}
auto testWrap12602c()
{
uint[] dest = [1, 2, 3, 4];
auto ra = Result12602(dest[0 .. 2]);
auto rb = Result12602(dest[2 .. 4]);
foreach (i; 0 .. 2)
rb.source[i] = ra.source[i];
assert(ra.source == [1,2]);
assert(rb.source == [1,2]);
assert(&ra.source[0] == &dest[0]);
assert(&rb.source[0] == &dest[2]);
assert(dest == [1,2,1,2]);
return dest;
}
auto testWrap12602d()
{
uint[] dest = [1, 2, 3, 4];
Result12602 ra; ra.source = dest[0 .. 2];
Result12602 rb; rb.source = dest[2 .. 4];
foreach (i; 0 .. 2)
rb.source[i] = ra.source[i];
assert(ra.source == [1,2]);
assert(rb.source == [1,2]);
assert(&ra.source[0] == &dest[0]);
assert(&rb.source[0] == &dest[2]);
assert(dest == [1,2,1,2]);
return dest;
}
static assert(testWrap12602a() == [1,2,1,2]);
static assert(testWrap12602b() == [1,2,1,2]);
static assert(testWrap12602c() == [1,2,1,2]);
static assert(testWrap12602d() == [1,2,1,2]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12677
// class type initializing from DotVarExp
final class C12677
{
TypeTuple!(Object, int[]) _test;
this()
{
auto t0 = _test[0]; //
auto t1 = _test[1]; //
assert(t0 is null);
assert(t1 is null);
}
}
struct S12677
{
auto f = new C12677();
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12851
// interpret function local const static array
void test12851()
{
const int[5] arr;
alias staticZip = TypeTuple!(arr[0]);
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13630
// indexing and setting array element via pointer
struct S13630(T)
{
T[3] arr;
this(A...)(const auto ref A args)
{
auto p = arr.ptr;
foreach (ref v; args)
{
*p = 0;
}
}
}
enum s13630 = S13630!float(1);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13827
struct Matrix13827(T, uint N)
{
private static defaultMatrix()
{
T[N] arr;
return arr;
}
union
{
T[N] A = defaultMatrix;
T[N] flat;
}
this(A...)(const auto ref A args)
{
uint k;
foreach (ref v; args)
flat[k++] = cast(T)v;
}
}
enum m13827 = Matrix13827!(int, 3)(1, 2, 3);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13847
// support DotTypeExp
class B13847
{
int foo() { return 1; }
}
class C13847 : B13847
{
override int foo() { return 2; }
final void test(int n)
{
assert(foo() == n);
assert(B13847.foo() == 1);
assert(C13847.foo() == 2);
assert(this.B13847.foo() == 1);
assert(this.C13847.foo() == 2);
}
}
class D13847 : C13847
{
override int foo() { return 3; }
}
static assert({
C13847 c = new C13847();
c.test(2);
assert(c.B13847.foo() == 1);
assert(c.C13847.foo() == 2);
D13847 d = new D13847();
d.test(3);
assert(d.B13847.foo() == 1);
assert(d.C13847.foo() == 2);
assert(d.D13847.foo() == 3);
c = d;
c.test(3);
assert(c.B13847.foo() == 1);
assert(c.C13847.foo() == 2);
return true;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12495
// cast from string to immutable(ubyte)[]
string getStr12495()
{
char[1] buf = void; // dummy starting point.
string s = cast(string)buf[0..0]; // empty slice, .ptr points mutable.
assert(buf.ptr == s.ptr);
s ~= 'a'; // this should allocate.
assert(buf.ptr != s.ptr);
return s.idup; // this should allocate again, and
// definitely point immutable memory.
}
auto indexOf12495(string s)
{
auto p1 = s.ptr;
auto p2 = (cast(immutable(ubyte)[])s).ptr;
assert(cast(void*)p1 == cast(void*)p2); // OK <- fails
return cast(void*)p2 - cast(void*)p1; // OK <- "cannot subtract pointers ..."
}
static assert(indexOf12495(getStr12495()) == 0);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13992
// Repainting pointer arithmetic result
enum hash13992 = hashOf13992("abcd".ptr);
@trusted hashOf13992(const void* buf)
{
auto data = cast(const(ubyte)*) buf;
size_t hash;
data += 2; // problematic pointer arithmetic
hash += *data; // CTFE internal issue was shown by the dereference
return hash;
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13739
// Precise copy for ArrayLiteralExp elements
static assert(
{
int[] a1 = [13];
int[][] a2 = [a1];
assert(a2[0] is a1); // OK
assert(a2[0].ptr is a1.ptr); // OK <- NG
a1[0] = 1;
assert(a2[0][0] == 1); // OK <- NG
a2[0][0] = 2;
assert(a1[0] == 2); // OK <- NG
return 1;
}());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14463
// ICE on slice assignment without postblit
struct Boo14463
{
private int[1] c;
this(int[] x)
{
c = x;
}
}
immutable Boo14463 a14463 = Boo14463([1]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=13295
// Don't copy struct literal in VarExp::interpret()
struct S13295
{
int n;
}
void f13295(ref const S13295 s)
{
*cast(int*) &s.n = 1;
assert(s.n == 1); // OK <- fail
}
static assert(
{
S13295 s;
f13295(s);
return s.n == 1; // true <- false
}());
int foo14061(int[] a)
{
foreach (immutable x; a)
{
auto b = a ~ x;
return b == [1, 1];
}
return 0;
}
static assert(foo14061([1]));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14024
// CTFE version
bool test14024()
{
string op;
struct S
{
char x = 'x';
this(this) { op ~= x-0x20; } // upper case
~this() { op ~= x; } // lower case
}
S[4] mem;
ref S[2] slice(int a, int b) { return mem[a .. b][0 .. 2]; }
op = null;
mem[0].x = 'a';
mem[1].x = 'b';
mem[2].x = 'x';
mem[3].x = 'y';
slice(0, 2) = slice(2, 4); // [ab] = [xy]
assert(op == "XaYb", op);
op = null;
mem[0].x = 'x';
mem[1].x = 'y';
mem[2].x = 'a';
mem[3].x = 'b';
slice(2, 4) = slice(0, 2); // [ab] = [xy]
assert(op == "XaYb", op);
op = null;
mem[0].x = 'a';
mem[1].x = 'b';
mem[2].x = 'c';
slice(0, 2) = slice(1, 3); // [ab] = [bc]
assert(op == "BaCb", op);
op = null;
mem[0].x = 'x';
mem[1].x = 'y';
mem[2].x = 'z';
slice(1, 3) = slice(0, 2); // [yz] = [xy]
assert(op == "YzXy", op);
return true;
}
static assert(test14024());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14304
// cache of static immutable value
immutable struct Bug14304
{
string s_name;
alias s_name this;
string fun()()
{
return "fun";
}
}
class Buggy14304
{
static string fun(string str)()
{
return str;
}
static immutable val = immutable Bug14304("val");
}
void test14304()
{
enum kt = Buggy14304.fun!(Buggy14304.val);
static assert(kt == "val");
enum bt = Buggy14304.val.fun();
static assert(bt == "fun");
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=14371
// evaluate BinAssignExp as lvalue
int test14371()
{
int x;
++(x += 1);
return x;
}
static assert(test14371() == 2);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=7151
// [CTFE] cannot compare classes with ==
bool test7151()
{
auto a = new Object;
return a == a && a != new Object;
}
static assert(test7151());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=12603
// [CTFE] goto does not correctly call dtors
struct S12603
{
this(uint* dtorCalled)
{
*dtorCalled = 0;
this.dtorCalled = dtorCalled;
}
@disable this();
~this()
{
++*dtorCalled;
}
uint* dtorCalled;
}
auto numDtorCallsByGotoWithinScope()
{
uint dtorCalled;
{
S12603 s = S12603(&dtorCalled);
assert(dtorCalled == 0);
goto L_abc;
L_abc:
assert(dtorCalled == 0);
}
assert(dtorCalled == 1);
return dtorCalled;
}
static assert(numDtorCallsByGotoWithinScope() == 1);
auto numDtorCallsByGotoOutOfScope()
{
uint dtorCalled;
{
S12603 s = S12603(&dtorCalled);
assert(dtorCalled == 0);
goto L_abc;
}
L_abc:
assert(dtorCalled == 1);
return dtorCalled;
}
static assert(numDtorCallsByGotoOutOfScope() == 1);
uint numDtorCallsByGotoDifferentScopeAfter()
{
uint dtorCalled;
{
S12603 s = S12603(&dtorCalled);
assert(dtorCalled == 0);
}
assert(dtorCalled == 1);
goto L_abc;
L_abc:
assert(dtorCalled == 1);
return dtorCalled;
}
static assert(numDtorCallsByGotoDifferentScopeAfter() == 1);
auto numDtorCallsByGotoDifferentScopeBefore()
{
uint dtorCalled;
assert(dtorCalled == 0);
goto L_abc;
L_abc:
assert(dtorCalled == 0);
{
S12603 s = S12603(&dtorCalled);
assert(dtorCalled == 0);
}
assert(dtorCalled == 1);
return dtorCalled;
}
static assert(numDtorCallsByGotoDifferentScopeBefore() == 1);
struct S12603_2
{
~this()
{
dtorCalled = true;
}
bool dtorCalled = false;
}
auto structInCaseScope()
{
auto charsets = S12603_2();
switch(1)
{
case 0:
auto set = charsets;
break;
default:
break;
}
return charsets.dtorCalled;
}
static assert(!structInCaseScope());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=15233
// ICE in TupleExp, Copy On Write bug
alias TT15233(stuff ...) = stuff;
struct Tok15233 {}
enum tup15233 = TT15233!(Tok15233(), "foo");
static assert(tup15233[0] == Tok15233());
static assert(tup15233[1] == "foo");
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=15251
// void cast in ForStatement.increment
int test15251()
{
for (ubyte lwr = 19;
lwr != 20;
cast(void)++lwr) // have to to be evaluated with CTFEGoal.Nothing
{}
return 1;
}
static assert(test15251());
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=15998
// Sagfault caused by memory corruption
immutable string[2] foo15998 = ["",""];
immutable string[2][] bar15998a = foo15998 ~ baz15998;
immutable string[2][] bar15998b = baz15998 ~ foo15998;
auto baz15998()
{
immutable(string[2])[] r;
return r;
}
static assert(bar15998a == [["", ""]]);
static assert(bar15998b == [["", ""]]);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=16094
// Non-overlapped slice assignment on an aggregate
char[] f16094a()
{
char[] x = new char[](6);
x[3..6] = x[0..3];
return x;
}
int[] f16094b()
{
int[] x = new int[](6);
x[3..6] = x[0..3];
return x;
}
enum copy16094a = f16094a();
enum copy16094b = f16094b();
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=17407
bool foo17407()
{
void delegate ( ) longest_convert;
return __traits(compiles, longest_convert = &doesNotExists);
}
static assert(!foo17407);
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=18057
// Recursive field initializer causes segfault.
struct RBNode(T)
{
RBNode!T *copy = new RBNode!T;
}
static assert(!__traits(compiles, { alias bug18057 = RBNode!int; }));
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=19140
void test19140()
{
real f19140();
static if (__traits(compiles, (){ enum real r = f19140(); })) {}
}
/**************************************************/
// https://issues.dlang.org/show_bug.cgi?id=19074
struct S19074a { }
struct S19074b
{
S19074a field;
this(S19074a) { }
static const S19074b* data = new S19074b(S19074a());
}
void test19074()
{
auto var = S19074b.data;
}
/************************************************/
// https://issues.dlang.org/show_bug.cgi?id=19447
bool f19447()
{
int[3] c=1;
assert(c[0]==1);
g19447(c[0..2]);
assert(c[0]!=1); //fails
assert(c[0]==2);
return true;
}
void g19447(ref int[2] a)
{
int[2] b=2;
a=b;
//a[]=b; // works
//a[] = b[]; // works
assert(a[0]==2);
}
static assert(f19447());
/***/
char[] mangle19447(char[] dst)
{
dst.length = 10;
size_t i = "_D".length;
dst[0 .. i] = "_D";
return dst;
}
static char[] x19447 = mangle19447(null);
/***/
enum KindEnum
{
integer,
arrayOf
}
struct FullKind
{
KindEnum[] contents;
this(KindEnum ) { opAssign; }
this(KindEnum , FullKind contentKind)
{
contents = contentKind.contents;
}
void opAssign()
{
contents = [];
}
}
enum fk = FullKind(KindEnum.integer);
enum fk2 = FullKind(KindEnum.arrayOf, fk);
/************************************************/
// https://issues.dlang.org/show_bug.cgi?id=9937
int test9937()
{
import core.math;
float x = float.max;
x *= 2;
x = toPrec!float(x);
x /= 2;
assert(x == float.infinity);
return 1;
}
static assert(test9937());
/************************************************/
// static array .tupleof
struct SArrayTupleEquiv(T)
{
T f1;
T f2;
}
// basic .tupleof invariants
bool testSArrayTupleA()
{
int[2] xs;
assert(xs.tupleof == TypeTuple!(0, 0));
assert(xs.tupleof == (cast(int[2])[0, 0]).tupleof);
xs.tupleof = TypeTuple!(1, 2);
assert(xs.tupleof == TypeTuple!(1, 2));
auto ys = SArrayTupleEquiv!int(1, 2);
assert(xs.tupleof == ys.tupleof);
return true;
}
static assert(testSArrayTupleA());
// tuples with side effects
bool testSArrayTupleB()
{
// Counter records lifetime events in copies/dtors, as a cheap way to check that .tupleof for
// static arrays exhibit all the same side effects as an equivalent struct's .tupleof
int[int] copies;
int[int] dtors;
struct Counter
{
int id = -1;
this(this)
{
copies[id] = copies.get(id, 0) + 1;
}
~this()
{
dtors[id] = dtors.get(id, 0) + 1;
}
}
void consume(Counter, Counter) {}
Counter[2] produce(int id1, int id2)
{
return [Counter(id1), Counter(id2)];
}
// first sample expected behavior from struct .tupleof
// braces create a subscope, shortening lifetimes
{
auto a = SArrayTupleEquiv!Counter(Counter(0), Counter(1));
typeof(a) b;
b.tupleof = a.tupleof;
Counter x, y;
TypeTuple!(x, y) = a.tupleof;
a.tupleof[0] = Counter(2);
a.tupleof[1] = Counter(3);
consume(a.tupleof);
a.tupleof = produce(4, 5).tupleof;
}
int[int][2] expected = [copies.dup, dtors.dup];
copies = null; // .clear is not CTFE friendly
dtors = null;
// the real test -- sample behavior of array .tupleof
{
Counter[2] a = [Counter(0), Counter(1)];
typeof(a) b;
b.tupleof = a.tupleof;
Counter x, y;
TypeTuple!(x, y) = a.tupleof;
a.tupleof[0] = Counter(2);
a.tupleof[1] = Counter(3);
consume(a.tupleof);
a.tupleof = produce(4, 5).tupleof;
}
assert(expected[0] == copies);
assert(expected[1] == dtors);
return true;
}
static assert(testSArrayTupleB());
|