You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constassert=@import("std").debug.assert;
test"implicitly cast a pointer to a const pointer of it" {
varx: i32=1;
constxp=&x;
foo(xp);
assert(x==2);
}
fnfoo(x: &const&i32) {
**x+=1;
}
Because we allow implicit casting from T to &const T, we expect the parameter to foo to take a const reference of the pointer, however, instead it thinks we should do a pointer reinterpret.
This leaves the question open, however, what should this do?
varx: i32=1;
constlove= (&const&i32)(&x); // what is love?
Is it supposed to do a pointer reinterpret, or does it make a temporary stack variable for &x and then make love point to it?
The text was updated successfully, but these errors were encountered:
andrewrk
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Mar 31, 2017
Now that I've gone through and modified all the code to use @bitcast instead of normal casting for pointer reinterpreting, I'm starting to think that @bitcast is too unsafe. You could easily accidentally cast any old thing that wasn't a pointer to a pointer. Plus there are now 2 ways to convert between a usize and a pointer.
So instead I propose that we rename @bitcast to @ptrcast and make it only work when the source and destination types are both &T or both ?&T.
Because we allow implicit casting from
T
to&const T
, we expect the parameter tofoo
to take a const reference of the pointer, however, instead it thinks we should do a pointer reinterpret.This leaves the question open, however, what should this do?
Is it supposed to do a pointer reinterpret, or does it make a temporary stack variable for
&x
and then makelove
point to it?The text was updated successfully, but these errors were encountered: