authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-07-29 05:51:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-29 09:00:23-07:00
log8d1805f81c97a0b773772e86aa39f26c894b7985
tree3ff12eec565d6a93ddacc08e17764bb8f9a4036c
parent417b92f0852eca8bd47f1964a63a9d1f6f3e6f6b

behavior: add coverage for no longer reproducing issue

Closes #14305

2 files changed, 41 insertions(+), 0 deletions(-)

test/behavior.zig+1
......@@ -193,6 +193,7 @@ test {
193193 _ = @import("behavior/optional.zig");
194194 _ = @import("behavior/packed-struct.zig");
195195 _ = @import("behavior/packed_struct_explicit_backing_int.zig");
196 _ = @import("behavior/packed-union.zig");
196197 _ = @import("behavior/pointers.zig");
197198 _ = @import("behavior/popcount.zig");
198199 _ = @import("behavior/prefetch.zig");
test/behavior/packed-union.zig created+40
......@@ -0,0 +1,40 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const expectEqual = std.testing.expectEqual;
4
5test "flags in packed union" {
6 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
7 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
8 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
9 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
10
11 const FlagBits = packed struct(u8) {
12 enable_1: bool = false,
13 enable_2: bool = false,
14 enable_3: bool = false,
15 enable_4: bool = false,
16 other_flags: packed union {
17 flags: packed struct(u4) {
18 enable_1: bool = true,
19 enable_2: bool = false,
20 enable_3: bool = false,
21 enable_4: bool = false,
22 },
23 bits: u4,
24 } = .{ .flags = .{} },
25 };
26 var test_bits: FlagBits = .{};
27
28 try expectEqual(false, test_bits.enable_1);
29 try expectEqual(true, test_bits.other_flags.flags.enable_1);
30
31 test_bits.enable_1 = true;
32
33 try expectEqual(true, test_bits.enable_1);
34 try expectEqual(true, test_bits.other_flags.flags.enable_1);
35
36 test_bits.other_flags.flags.enable_1 = false;
37
38 try expectEqual(true, test_bits.enable_1);
39 try expectEqual(false, test_bits.other_flags.flags.enable_1);
40}