add behavior test for comptime ptrcast packed struct

closes #9912
This commit is contained in:
Andrew Kelley 2023-07-26 17:49:36 -07:00
parent 2936602566
commit 508294e9be

View File

@ -284,3 +284,12 @@ test "@ptrCast undefined value at comptime" {
_ = x;
}
}
test "comptime @ptrCast with packed struct leaves value unmodified" {
const S = packed struct { three: u3 };
const st: S = .{ .three = 6 };
try expect(st.three == 6);
const p: *const [1]u3 = @ptrCast(&st);
try expect(p.*[0] == 6);
try expect(st.three == 6);
}