diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-02-26 11:11:28 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-26 11:11:28 -0500 |
| commit | c4a2734aa08a9e810680d7be2c976fe3ae67cc5b (patch) | |
| tree | 762fb4fe3e6a334f8845c0fb5ccffd685b65ebcb /test | |
| parent | aa2aad229c96427f8b9130a3665a1f6ad768ec4c (diff) | |
| parent | d2535c003c6188fcc362028e01ef9f7fb3356727 (diff) | |
| download | zig-c4a2734aa08a9e810680d7be2c976fe3ae67cc5b.tar.gz zig-c4a2734aa08a9e810680d7be2c976fe3ae67cc5b.zip | |
Merge pull request #4561 from LemonBoy/fix-4536-1
Resend of #4552
Diffstat (limited to 'test')
| -rw-r--r-- | test/stage1/behavior/sizeof_and_typeof.zig | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/test/stage1/behavior/sizeof_and_typeof.zig b/test/stage1/behavior/sizeof_and_typeof.zig index a738dbbbf9..322c5fbbad 100644 --- a/test/stage1/behavior/sizeof_and_typeof.zig +++ b/test/stage1/behavior/sizeof_and_typeof.zig @@ -1,5 +1,7 @@ -const builtin = @import("builtin"); -const expect = @import("std").testing.expect; +const std = @import("std"); +const builtin = std.builtin; +const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@sizeOf and @TypeOf" { const y: @TypeOf(x) = 120; @@ -135,3 +137,53 @@ test "@bitSizeOf" { a: u2 }) == 2); } + +test "@sizeOf comparison against zero" { + const S0 = struct { + f: *@This(), + }; + const U0 = union { + f: *@This(), + }; + const S1 = struct { + fn H(comptime T: type) type { + return struct { + x: T, + }; + } + f0: H(*@This()), + f1: H(**@This()), + f2: H(***@This()), + }; + const U1 = union { + fn H(comptime T: type) type { + return struct { + x: T, + }; + } + f0: H(*@This()), + f1: H(**@This()), + f2: H(***@This()), + }; + const S = struct { + fn doTheTest(comptime T: type, comptime result: bool) void { + expectEqual(result, @sizeOf(T) > 0); + } + }; + // Zero-sized type + S.doTheTest(u0, false); + S.doTheTest(*u0, false); + // Non byte-sized type + S.doTheTest(u1, true); + S.doTheTest(*u1, true); + // Regular type + S.doTheTest(u8, true); + S.doTheTest(*u8, true); + S.doTheTest(f32, true); + S.doTheTest(*f32, true); + // Container with ptr pointing to themselves + S.doTheTest(S0, true); + S.doTheTest(U0, true); + S.doTheTest(S1, true); + S.doTheTest(U1, true); +} |
