Skip to content

empty slice ptr cast with offset of 0 fails #2140

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
BarabasGitHub opened this issue Mar 30, 2019 · 1 comment
Closed

empty slice ptr cast with offset of 0 fails #2140

BarabasGitHub opened this issue Mar 30, 2019 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@BarabasGitHub
Copy link
Contributor

BarabasGitHub commented Mar 30, 2019

Zig compiler version 0.3.0+5703ab1d

test "empty slice ptr cast with offset of 0" {
    const empty_slice: []u8 = [_]u8{};
    const p: [*]u8 = empty_slice.ptr + 0;
    const t = @ptrCast([*]u8, p);
}

gives the error:
ptr cast empty slice offset with 0...cast causes pointer to be null

however this works

test "empty slice ptr cast with offset of 0" {
    const empty_slice: []u8 = [_]u8{};
    const p: [*]u8 = empty_slice.ptr;
    const t = @ptrCast([*]u8, p);
}

Doesn't make sense to me.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Mar 31, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Mar 31, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 27, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 3, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 30, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nektro
Copy link
Contributor

nektro commented Oct 12, 2021

if you add & on the array add _ = t; this works on 0.9.0-dev.1343+75cecef63

Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 28, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 29, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Dec 29, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants