Skip to content

runtime initialized sentinel-terminated array literal fails to initialize sentinel value #4372

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
andrewrk opened this issue Feb 2, 2020 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Feb 2, 2020

const std = @import("std");

test "runtime initialized sentinel-terminated array literal" {
    var c: u16 = 300;
    const f = &[_:0x9999]u16{c};
    const g = @ptrCast(*[4]u8, f);
    std.testing.expect(g[2] == 0x99);
    std.testing.expect(g[3] == 0x99);
}

Test case fails. Should pass.

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Feb 2, 2020
@andrewrk andrewrk added this to the 0.6.0 milestone Feb 2, 2020
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Apr 9, 2020
@jayschwa
Copy link
Contributor

jayschwa commented Jul 6, 2020

Is the following test case failure covered by this issue? It looks like it should be compile-time to me, but figured I'd check before creating a new issue.

const std = @import("std");
const assert = std.debug.assert;

test "$ terminated slice" {
    const slice: [:'$']const u8 = "hello";

    assert(slice.len == 5);
    assert(slice[5] == '$');
}

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 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
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 1, 2023
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 stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

No branches or pull requests

2 participants