aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/bugs/726.zig
blob: 37e8d31cc942029c2942ecf961cb693bd7ee2469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const expect = @import("std").testing.expect;
const builtin = @import("builtin");

test "@ptrCast from const to nullable" {
    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
    if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
    if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;

    const c: u8 = 4;
    var x: ?*const u8 = @as(?*const u8, @ptrCast(&c));
    try expect(x.?.* == 4);
}

test "@ptrCast from var in empty struct to nullable" {
    if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
    if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
    if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
    if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;

    const container = struct {
        var c: u8 = 4;
    };
    var x: ?*const u8 = @as(?*const u8, @ptrCast(&container.c));
    try expect(x.?.* == 4);
}