From 04366576ea4be4959b596ebff7041d17e18d08d8 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 25 Sep 2021 17:52:50 -0700 Subject: stage2: implement `@sizeOf` for non-packed structs --- test/behavior/struct.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/behavior/struct.zig') diff --git a/test/behavior/struct.zig b/test/behavior/struct.zig index 6f00b71057..e048848799 100644 --- a/test/behavior/struct.zig +++ b/test/behavior/struct.zig @@ -31,3 +31,24 @@ test "return empty struct instance" { fn returnEmptyStructInstance() StructWithNoFields { return empty_global_instance; } + +const StructFoo = struct { + a: i32, + b: bool, + c: f32, +}; +test "structs" { + var foo: StructFoo = undefined; + @memset(@ptrCast([*]u8, &foo), 0, @sizeOf(StructFoo)); + foo.a += 1; + foo.b = foo.a == 1; + try testFoo(foo); + testMutation(&foo); + try expect(foo.c == 100); +} +fn testFoo(foo: StructFoo) !void { + try expect(foo.b); +} +fn testMutation(foo: *StructFoo) void { + foo.c = 100; +} -- cgit v1.2.3