commit 6473dc22fc1659df218ade897647c0658e0ebec9 (tree)
parent f1b255402377b41e47cec65b4dbc2633e1dd7b83
Author: Nils Koch <mail@nilskch.dev>
Date: Wed, 17 Dec 2025 17:54:31 +0100
std.ArrayList: Fix compile error when `@sizeOf(T) == 0`
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig
@@ -1362,11 +1362,11 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
return self.getLast();
}
- const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
-
/// Called when memory growth is necessary. Returns a capacity larger than
/// minimum that grows super-linearly.
pub fn growCapacity(minimum: usize) usize {
+ if (@sizeOf(T) == 0) return math.maxInt(usize);
+ const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
return minimum +| (minimum / 2 + init_capacity);
}
};
@@ -1751,6 +1751,14 @@ test "insert" {
try testing.expect(list.items[2] == 2);
try testing.expect(list.items[3] == 3);
}
+ {
+ var list: ArrayList(struct {}) = .empty;
+ defer list.deinit(a);
+
+ try list.insert(a, 0, .{});
+ try list.append(a, .{});
+ try testing.expect(list.items.len == 2);
+ }
}
test "insertSlice" {