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

Can't perform pointer casts in constant expressions #4531

Closed
jdm opened this Issue Jan 18, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@jdm
Contributor

jdm commented Jan 18, 2013

<anon>:41:26: 41:60 error: can not cast to *core::libc::types::os::arch::c95::c_char in a constant expression

There's an llvm::LLVMConstPointerCast, so I don't see why this should be forbidden.

@pnkfelix

This comment has been minimized.

Show comment
Hide comment
@pnkfelix

pnkfelix Apr 29, 2013

Member

This bug is too vague; it needs an example to illustrate what the desired original Rust source expression is.


Its also possible that this bug has been fixed; or at least, my attempt to create an example to illustrate the bug has failed Here is the example I devised:

static x : [int, ..2] = [3, 4];
static y : [libc::c_char, ..2] = [97, 98];

unsafe fn aref<T>(a: *T, offset: uint) -> T {
    let ptr : uint = (a as uint) + sys::size_of::<T>() * offset;
    let ptr : *T   = ptr as *T;
    *ptr
}

fn main() {
    static px : *int = &x as *int;
    static py : *libc::c_char = &y as *libc::c_char;
    let vx0, vx1, vy0, vy1;
    unsafe {
        vx0 = aref(px, 0);
        vx1 = aref(px, 1);
        vy0 = aref(py, 0);
        vy1 = aref(py, 1);
    }
    io::println(fmt!("x[0]: %d x[1]: %d", vx0, vx1));
    io::println(fmt!("y[0]: %c y[1]: %c", vy0 as char, vy1 as char));
}

but note that this compiles and runs successfully. So either I misunderstand how to exercise const expressions (which is quite possible), or this bug has been fixed.

@jdm feel free to reopen if you have a concrete example to illustrate the issue.

Member

pnkfelix commented Apr 29, 2013

This bug is too vague; it needs an example to illustrate what the desired original Rust source expression is.


Its also possible that this bug has been fixed; or at least, my attempt to create an example to illustrate the bug has failed Here is the example I devised:

static x : [int, ..2] = [3, 4];
static y : [libc::c_char, ..2] = [97, 98];

unsafe fn aref<T>(a: *T, offset: uint) -> T {
    let ptr : uint = (a as uint) + sys::size_of::<T>() * offset;
    let ptr : *T   = ptr as *T;
    *ptr
}

fn main() {
    static px : *int = &x as *int;
    static py : *libc::c_char = &y as *libc::c_char;
    let vx0, vx1, vy0, vy1;
    unsafe {
        vx0 = aref(px, 0);
        vx1 = aref(px, 1);
        vy0 = aref(py, 0);
        vy1 = aref(py, 1);
    }
    io::println(fmt!("x[0]: %d x[1]: %d", vx0, vx1));
    io::println(fmt!("y[0]: %c y[1]: %c", vy0 as char, vy1 as char));
}

but note that this compiles and runs successfully. So either I misunderstand how to exercise const expressions (which is quite possible), or this bug has been fixed.

@jdm feel free to reopen if you have a concrete example to illustrate the issue.

@pnkfelix pnkfelix closed this Apr 29, 2013

@jdm

This comment has been minimized.

Show comment
Hide comment
@jdm

jdm Apr 29, 2013

Contributor

I fixed it and never referenced it from a commit. Closing the the correct action.

Contributor

jdm commented Apr 29, 2013

I fixed it and never referenced it from a commit. Closing the the correct action.

@jdm jdm removed their assignment Jun 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment