Skip to content

Commit 9d3363f

Browse files
committed
add behavior test for bitcast packed struct twice
closes #9914
1 parent 508294e commit 9d3363f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/behavior/packed-struct.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,13 @@ test "store undefined to packed result location" {
640640
var s = packed struct { x: u4, y: u4 }{ .x = x, .y = if (x > 0) x else undefined };
641641
try expectEqual(x, s.x);
642642
}
643+
644+
test "bitcast back and forth" {
645+
// Originally reported at https://github.com/ziglang/zig/issues/9914
646+
const S = packed struct { one: u6, two: u1 };
647+
const s = S{ .one = 0b110101, .two = 0b1 };
648+
const u: u7 = @bitCast(s);
649+
const s2: S = @bitCast(u);
650+
try expect(s.one == s2.one);
651+
try expect(s.two == s2.two);
652+
}

0 commit comments

Comments
 (0)