mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
tests: update for accepted language change
`packed struct`s and `packed union`s can no longer contain pointer fields. There are a few reasons for this, but in particular, binary formats do not typically support the relocation types we would need to lower such values into static memory. See the proposal at https://github.com/ziglang/zig/issues/24657 for details.
This commit is contained in:
@@ -76,6 +76,11 @@ export fn entry14() void {
|
||||
x: E,
|
||||
});
|
||||
}
|
||||
export fn entry15() void {
|
||||
_ = @sizeOf(packed struct {
|
||||
x: *const u32,
|
||||
});
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
@@ -103,3 +108,6 @@ export fn entry14() void {
|
||||
// :70:12: note: types are not available at runtime
|
||||
// :76:12: error: packed structs cannot contain fields of type 'tmp.entry14.E'
|
||||
// :74:15: note: enum declared here
|
||||
// :81:12: error: packed structs cannot contain fields of type '*const u32'
|
||||
// :81:12: note: pointers cannot be directly bitpacked
|
||||
// :81:12: note: consider using 'usize' and '@intFromPtr'
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
const Foo = struct {
|
||||
a: u32,
|
||||
b: f32,
|
||||
};
|
||||
const Payload = packed union {
|
||||
A: Foo,
|
||||
B: bool,
|
||||
};
|
||||
export fn entry() void {
|
||||
const a: Payload = .{ .B = true };
|
||||
_ = a;
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :6:8: error: packed unions cannot contain fields of type 'tmp.Foo'
|
||||
// :6:8: note: only packed structs layout are allowed in packed types
|
||||
// :1:13: note: struct declared here
|
||||
@@ -0,0 +1,20 @@
|
||||
export fn entry0() void {
|
||||
_ = @sizeOf(packed union {
|
||||
foo: struct { a: u32 },
|
||||
bar: bool,
|
||||
});
|
||||
}
|
||||
export fn entry1() void {
|
||||
_ = @sizeOf(packed union {
|
||||
x: *const u32,
|
||||
});
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :3:14: error: packed unions cannot contain fields of type 'packed_union_with_fields_of_not_allowed_types.entry0__union_180__struct_182'
|
||||
// :3:14: note: non-packed structs do not have a bit-packed representation
|
||||
// :3:14: note: struct declared here
|
||||
// :9:12: error: packed unions cannot contain fields of type '*const u32'
|
||||
// :9:12: note: pointers cannot be directly bitpacked
|
||||
// :9:12: note: consider using 'usize' and '@intFromPtr'
|
||||
Reference in New Issue
Block a user