From 508294e9be2173b47c2e4d2fb1c52c41fcfcbc1c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 26 Jul 2023 17:49:36 -0700 Subject: [PATCH] add behavior test for comptime ptrcast packed struct closes #9912 --- test/behavior/ptrcast.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/behavior/ptrcast.zig b/test/behavior/ptrcast.zig index 3a2ec9db19..8837c42a86 100644 --- 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); +}