Skip to content

@ptrCast between real pointers and 0-sized pointers should be a compile error #1469

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

Closed
thejoshwolfe opened this issue Sep 4, 2018 · 3 comments
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@thejoshwolfe
Copy link
Contributor

This came up in #960.

test "*usize to *void" {
    var i = usize(0);
    var v = @ptrCast(*void, &i);
    v.* = {};
}

This should be a compile error. A *void has 0 size (just like void itself) so this cast makes no sense.

@Hejsil was there a usecase you were running into in #960 where you wanted to do this cast?

@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Sep 4, 2018
@andrewrk andrewrk added this to the 0.4.0 milestone Sep 4, 2018
@Hejsil
Copy link
Contributor

Hejsil commented Sep 4, 2018

@thejoshwolfe I think I was implementing some vtable/interface stuff. Was trying to use *void as I would use void * in C, and hit this. So no, there wasn't really a usecase.

@andrewrk andrewrk added the accepted This proposal is planned. label Sep 4, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Sep 28, 2018
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 May 3, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 3, 2020
@tadeokondrak
Copy link
Contributor

Casting from normal pointers to pointers to zero-length arrays seems to be reasonable code, which happens in std.heap.GeneralPurposeAllocator.

@SpexGuy
Copy link
Contributor

SpexGuy commented Nov 21, 2020

In #6706 we've decided to remove 0-sized pointers, so this is no longer relevant.

@SpexGuy SpexGuy closed this as completed Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
5 participants