From 6473dc22fc1659df218ade897647c0658e0ebec9 Mon Sep 17 00:00:00 2001 From: Nils Koch Date: Wed, 17 Dec 2025 17:54:31 +0100 Subject: [PATCH] std.ArrayList: Fix compile error when `@sizeOf(T) == 0` --- lib/std/array_list.zig | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index d84bafca0e..f15388d7b5 100644 --- 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" {