zig/test/behavior/bugs/726.zig
Jacob Young 525dcaecba behavior: enable stage2_c tests that are currently passing
Also fix C warnings triggered by these tests.
2022-10-25 05:11:28 -04:00

25 lines
868 B
Zig

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_x86_64) return error.SkipZigTest;
const c: u8 = 4;
var x: ?*const u8 = @ptrCast(?*const u8, &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_x86_64) return error.SkipZigTest;
const container = struct {
var c: u8 = 4;
};
var x: ?*const u8 = @ptrCast(?*const u8, &container.c);
try expect(x.?.* == 4);
}