mirror of
https://github.com/ziglang/zig.git
synced 2025-12-27 16:43:07 +00:00
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
27 lines
1.0 KiB
Zig
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);
|
|
}
|