-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Incorrect slice bounds detection in comptime @ptrCast
#1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Milestone
Comments
Simplified test case: const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
comptime {
var x: u32 = 0x1a2b3c4d;
var s = @ptrCast([*]u8, &x)[0..@sizeOf(u32)];
if (builtin.endian == builtin.Endian.Big) {
assert(s[0] == 0x1a);
assert(s[1] == 0x2b);
assert(s[2] == 0x3c);
assert(s[3] == 0x4d);
} else {
assert(s[0] == 0x4d);
assert(s[1] == 0x3c);
assert(s[2] == 0x2b);
assert(s[3] == 0x1a);
}
} I started working on this, but I think it would be better for post-0.3.0, it's more an issue of "implement more compile-time pointer reinterpreting support" which is a tall order for 1 week before release. |
Duplicate of #1150 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler seems to think that only
[0..1]
is valid. Outside of comptime this works fine.The text was updated successfully, but these errors were encountered: