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
Do we commit to supporting "0 as T*" to express null const expression? #4671
Comments
Hmm, according to rusti you can cast integer literals to unsafe pointers without any trouble. Looks like this is a const-specific limitation. |
This seems to "work" now: static w : *int = 0 as *int;
fn main() {
let wval : int;
io::println(fmt!("w: %u", w as uint));
io::println(fmt!("w == null: %b", w == ptr::null()));
unsafe { wval = *w; }
io::println(fmt!("*w: %d", wval));
} which when run does:
At first I was hesitant to claim that this would mean that the bug is fixed, since historically some machine architectures have not used 0 to represent the null pointer at the machine level:
but since I guess the I'm going to nominate this for the backwards compatibility milestone, since handling of NULL seems like the kind of thing we should solidify at that point. |
For my purposes the issue is fixed; one of my series of const-related commits added the ability to cast integer types to pointers. I suspect that filing a new issue that laid out @pnkfelix's remaining concerns and nominating that would be slightly more productive. |
Check on what C++ |
From what I can tell, the C++ nullptr_t has more to do with overloading based on arguments---that is, one problem with using |
@nikomatsakis: Yeah, they added Rust now treats casts to and from a raw pointer as a safe operation, so the original bug here is fixed. I'm going to close this and we can open another one if there are any lingering issues. |
Original title: "Can't use null unsafe pointers in const expressions"
We can't use ptr::null(), since that requires a function call. There's nothing castable, even with #4531 fixed. Maybe we could allow casting literal zero to unsafe pointer types?
The text was updated successfully, but these errors were encountered: