commit 508294e9be2173b47c2e4d2fb1c52c41fcfcbc1c (tree) parent 2936602566c5c460abae350a6d59c1da0e0989ee Author: Andrew Kelley <andrew@ziglang.org> Date: Wed, 26 Jul 2023 17:49:36 -0700 add behavior test for comptime ptrcast packed struct closes #9912 Diffstat:
| M | test/behavior/ptrcast.zig | | | 9 | +++++++++ |
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig @@ -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); +}