| ... | ... | @@ -1125,3 +1125,24 @@ test "splat with an error union or optional result type" { |
| 1125 | 1125 | _ = try S.doTest(@Vector(4, u32)); |
| 1126 | 1126 | _ = try S.doTest([4]u32); |
| 1127 | 1127 | } |
| 1128 | |
| 1129 | test "resist alias of explicit copy of array passed as arg" { |
| 1130 | const S = struct { |
| 1131 | const Thing = [1]u32; |
| 1132 | |
| 1133 | fn destroy_and_replace(box_b: *Thing, a: Thing, box_a: *Thing) void { |
| 1134 | box_a.* = undefined; |
| 1135 | box_b.* = a; |
| 1136 | } |
| 1137 | }; |
| 1138 | |
| 1139 | var buf_a: S.Thing = .{1234}; |
| 1140 | var buf_b: S.Thing = .{5678}; |
| 1141 | const box_a = &buf_a; |
| 1142 | const box_b = &buf_b; |
| 1143 | |
| 1144 | const a = box_a.*; // explicit copy |
| 1145 | S.destroy_and_replace(box_b, a, box_a); |
| 1146 | |
| 1147 | try expect(buf_b[0] == 1234); |
| 1148 | } |