zig
zig copied to clipboard
Allocator.realloc can't handle 0-size types
const std = @import("std");
test "asdf" {
var list1 = std.ArrayList(u1).init(std.testing.allocator);
defer list1.deinit();
try list1.append(0); // works fine
var list0 = std.ArrayList(u0).init(std.testing.allocator);
defer list0.deinit();
try list0.append(0); // compile error
}
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/mem.zig:165:37: error: alignment must be >= 1
break :t Error![]align(Slice.alignment) Slice.child;
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/mem.zig:163:69: note: called from here
pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: {
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/array_list.zig:200:71: note: called from here
pub fn ensureCapacity(self: *Self, new_capacity: usize) !void {
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/mem.zig:165:24: note: referenced here
break :t Error![]align(Slice.alignment) Slice.child;
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/mem.zig:163:69: note: referenced here
pub fn realloc(self: *Allocator, old_mem: var, new_n: usize) t: {
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/array_list.zig:209:58: note: referenced here
const new_memory = try self.allocator.realloc(self.allocatedSlice(), better_capacity);
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/array_list.zig:225:13: note: referenced here
try self.ensureCapacity(newlen);
^
./zig-linux-x86_64-0.5.0+dbc00e242/lib/zig/std/array_list.zig:110:34: note: referenced here
const new_item_ptr = try self.addOne();
^
./test.zig:9:5: note: referenced here
try list0.append(0);
^
for what?