| author | |
| committer | |
| log | fecd28371d5c0e25357dfb91f75c8790f8b4155b |
| tree | 4bfe1fc081d3f3f82a061b6577fe1f4df731ccd6 |
| parent | fc1c83a363d32e749b9061044db63852ab7255d0 |
Resolves: https://codeberg.org/ziglang/zig/issues/319443 files changed, 14 insertions(+), 0 deletions(-)
src/Sema/bitcast.zig+2| ... | @@ -565,6 +565,7 @@ const PackValueBits = struct { | ... | @@ -565,6 +565,7 @@ const PackValueBits = struct { |
| 565 | }, | 565 | }, |
| 566 | .@"packed" => { | 566 | .@"packed" => { |
| 567 | const backing_int_val = try pack.primitive(ty.bitpackBackingInt(zcu)); | 567 | const backing_int_val = try pack.primitive(ty.bitpackBackingInt(zcu)); |
| 568 | if (backing_int_val.isUndef(zcu)) return pt.undefValue(ty); | ||
| 568 | return pt.bitpackValue(ty, backing_int_val); | 569 | return pt.bitpackValue(ty, backing_int_val); |
| 569 | }, | 570 | }, |
| 570 | }, | 571 | }, |
| ... | @@ -659,6 +660,7 @@ const PackValueBits = struct { | ... | @@ -659,6 +660,7 @@ const PackValueBits = struct { |
| 659 | }, | 660 | }, |
| 660 | .@"packed" => { | 661 | .@"packed" => { |
| 661 | const backing_int_val = try pack.primitive(ty.bitpackBackingInt(zcu)); | 662 | const backing_int_val = try pack.primitive(ty.bitpackBackingInt(zcu)); |
| 663 | if (backing_int_val.isUndef(zcu)) return pt.undefValue(ty); | ||
| 662 | return pt.bitpackValue(ty, backing_int_val); | 664 | return pt.bitpackValue(ty, backing_int_val); |
| 663 | }, | 665 | }, |
| 664 | }, | 666 | }, |
test/behavior/packed-struct.zig+6| ... | @@ -1240,3 +1240,9 @@ test "packed struct store of comparison result" { | ... | @@ -1240,3 +1240,9 @@ test "packed struct store of comparison result" { |
| 1240 | try expect(result2.a); | 1240 | try expect(result2.a); |
| 1241 | try expect(!result2.b); | 1241 | try expect(!result2.b); |
| 1242 | } | 1242 | } |
| 1243 | |||
| 1244 | test "initialize packed struct field to undefined at comptime" { | ||
| 1245 | const S = packed struct(u8) { x: u8 }; | ||
| 1246 | const val: S = .{ .x = undefined }; | ||
| 1247 | _ = val; | ||
| 1248 | } |
test/behavior/packed-union.zig+6| ... | @@ -219,3 +219,9 @@ test "packed union equality" { | ... | @@ -219,3 +219,9 @@ test "packed union equality" { |
| 219 | try S.doTest(x, y); | 219 | try S.doTest(x, y); |
| 220 | comptime try S.doTest(x, y); | 220 | comptime try S.doTest(x, y); |
| 221 | } | 221 | } |
| 222 | |||
| 223 | test "initialize packed union field to undefined at comptime" { | ||
| 224 | const U = packed union(u8) { x: u8 }; | ||
| 225 | const val: U = .{ .x = undefined }; | ||
| 226 | _ = val; | ||
| 227 | } |