mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
add behavior test for comptime pointer casting
comptime `@ptrCast` a subset of an array, then write through it closes #2444
This commit is contained in:
parent
f4b067743f
commit
6e9fbc83ca
@ -61,6 +61,7 @@ test "array concat with undefined" {
|
||||
}
|
||||
|
||||
test "array concat with tuple" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@ const Entry = packed struct {
|
||||
test {
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
const frame = Frame{ .num = 0x7FDE };
|
||||
var entry = Entry{ .other = 0, .frame = .{ .num = 0xFFFFF } };
|
||||
|
||||
@ -257,3 +257,16 @@ test "@ptrCast slice to slice" {
|
||||
try expect(buf[1] == 42);
|
||||
try expect(alias.len == 4);
|
||||
}
|
||||
|
||||
test "comptime @ptrCast a subset of an array, then write through it" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
|
||||
|
||||
comptime {
|
||||
var buff: [16]u8 align(4) = undefined;
|
||||
const len_bytes = @ptrCast(*u32, &buff);
|
||||
len_bytes.* = 16;
|
||||
std.mem.copy(u8, buff[4..], "abcdef");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user