zig/test/behavior/bugs/726.zig
mlugg f26dda2117 all: migrate code to new cast builtin syntax
Most of this migration was performed automatically with `zig fmt`. There
were a few exceptions which I had to manually fix:

* `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten
* `@truncate`'s fixup is incorrect for vectors
* Test cases are not formatted, and their error locations change
2023-06-24 16:56:39 -07:00

27 lines
1.0 KiB
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_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);
}