mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 21:08:36 +00:00
add behavior test for comptime pointer casting
closes #1150 closes #1292 closes #4093
This commit is contained in:
parent
aca9c74e80
commit
09ee887e9f
@ -203,6 +203,37 @@ test "comptime ptrcast keeps larger alignment" {
|
||||
}
|
||||
}
|
||||
|
||||
test "ptrcast of const integer has the correct object size" {
|
||||
const is_value = ~@intCast(isize, std.math.minInt(isize));
|
||||
const is_bytes = @ptrCast([*]const u8, &is_value)[0..@sizeOf(isize)];
|
||||
if (@sizeOf(isize) == 8) {
|
||||
switch (native_endian) {
|
||||
.Little => {
|
||||
try expect(is_bytes[0] == 0xff);
|
||||
try expect(is_bytes[1] == 0xff);
|
||||
try expect(is_bytes[2] == 0xff);
|
||||
try expect(is_bytes[3] == 0xff);
|
||||
|
||||
try expect(is_bytes[4] == 0xff);
|
||||
try expect(is_bytes[5] == 0xff);
|
||||
try expect(is_bytes[6] == 0xff);
|
||||
try expect(is_bytes[7] == 0x7f);
|
||||
},
|
||||
.Big => {
|
||||
try expect(is_bytes[0] == 0x7f);
|
||||
try expect(is_bytes[1] == 0xff);
|
||||
try expect(is_bytes[2] == 0xff);
|
||||
try expect(is_bytes[3] == 0xff);
|
||||
|
||||
try expect(is_bytes[4] == 0xff);
|
||||
try expect(is_bytes[5] == 0xff);
|
||||
try expect(is_bytes[6] == 0xff);
|
||||
try expect(is_bytes[7] == 0xff);
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test "implicit optional pointer to optional anyopaque pointer" {
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user