zig icon indicating copy to clipboard operation
zig copied to clipboard

stdlib: std.mem.zeroes fail to initialize sentinel slice

Open hawkbee opened this issue 3 years ago • 0 comments

Zig Version

0.10.0-dev.4185+9c2fb6e18

Steps to Reproduce

const std = @import("std");
test "sentinel slice zeroes" {
    const S = struct {
        ss: [:0]const u8,
    };

    var a: S = std.mem.zeroes(S);
    try std.testing.expect(a.ss.len == 0);
    a.ss = "hello";
    try std.testing.expect(a.ss.len == 5);
}

Expected Behavior

test pass.

Actual Behavior

/usr/lib/zig/lib/std/mem.zig:288:28: error: expected type '[:0]const u8', found '*const [0]u8'
                    return &[_]ptr_info.child{};
                           ^~~~~~~~~~~~~~~~~~~~
/usr/lib/zig/lib/std/mem.zig:288:28: note: destination pointer requires '0' sentinel
/usr/lib/zig/lib/std/mem.zig:252:33: note: function return type declared here
pub fn zeroes(comptime T: type) T {

hawkbee avatar Oct 22 '22 01:10 hawkbee