| 2086 | 2085 | |
|---|
| 2087 | 2086 | int goodfoo1() |
|---|
| 2088 | 2087 | { |
|---|
| 2089 | 2088 | int[8] w; // use static array in CTFE |
|---|
| 2090 | 2089 | w[]=7; // full slice assign |
|---|
| 2091 | 2090 | w[$-1]=538; // use of $ in index assignment |
|---|
| 2092 | 2091 | assert(w[6]==7); |
|---|
| 2093 | 2092 | return w[7]; |
|---|
| 2094 | 2093 | } |
|---|
| 2095 | 2094 | static assert(goodfoo1()==538); |
|---|
| 2096 | 2095 | |
|---|
| 2097 | 2096 | int goodfoo2() |
|---|
| 2098 | 2097 | { |
|---|
| 2099 | 2098 | S[4] w = S(101); // Block-initialize array of structs |
|---|
| 2100 | 2099 | w[$-2].x = 917; // use $ in index member assignment |
|---|
| 2101 | 2100 | w[$-2].y = 58; // this must not clobber the prev assignment |
|---|
| 2102 | 2101 | return w[2].x; // check we got the correct one |
|---|
| 2103 | 2102 | } |
|---|
| 2104 | 2103 | static assert(goodfoo2()==917); |
|---|
| 2105 | 2104 | |
|---|
| 2113 | 2112 | |
|---|
| 2114 | 2113 | int goodfoo4() |
|---|
| 2115 | 2114 | { |
|---|
| 2116 | 2115 | S[4] b = [S(7), S(15), S(56), S(12)]; // assign from array literal |
|---|
| 2117 | 2116 | assert(b[3]==S(12)); |
|---|
| 2118 | 2117 | return b[2].x-55; |
|---|
| 2119 | 2118 | } |
|---|
| 2120 | 2119 | static assert(goodfoo4()==1); |
|---|
| 2121 | 2120 | |
|---|
| 2122 | 2121 | int goodfoo5() |
|---|
| 2123 | 2122 | { |
|---|
| 2124 | 2123 | S[4] b = [S(7), S(15), S(56), S(12)]; |
|---|
| 2125 | 2124 | b[0..2] = [S(2),S(6)]; // slice assignment from array literal |
|---|
| 2126 | 2125 | assert(b[3]==S(12)); |
|---|
| 2127 | 2126 | assert(b[1]==S(6)); |
|---|
| 2128 | 2127 | return b[0].x; |
|---|
| 2129 | 2128 | } |
|---|
| 2130 | 2129 | static assert(goodfoo5()==2); |
|---|
| 2131 | 2130 | static assert(goodfoo5()==2); // check for memory corruption |
|---|
| 2132 | 2131 | |
|---|