authorgravatar for mail@nilskch.devNils Koch <mail@nilskch.dev> 2025-12-17 17:54:31+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-02-09 19:59:09+01:00
log6473dc22fc1659df218ade897647c0658e0ebec9
tree8f0960e64eda1d637b4ff19c328d2a530a3d1921
parentf1b255402377b41e47cec65b4dbc2633e1dd7b83

std.ArrayList: Fix compile error when `@sizeOf(T) == 0`


1 files changed, 10 insertions(+), 2 deletions(-)

lib/std/array_list.zig+10-2
...@@ -1362,11 +1362,11 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {...@@ -1362,11 +1362,11 @@ pub fn Aligned(comptime T: type, comptime alignment: ?mem.Alignment) type {
1362 return self.getLast();1362 return self.getLast();
1363 }1363 }
13641364
1365 const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
1366
1367 /// Called when memory growth is necessary. Returns a capacity larger than1365 /// Called when memory growth is necessary. Returns a capacity larger than
1368 /// minimum that grows super-linearly.1366 /// minimum that grows super-linearly.
1369 pub fn growCapacity(minimum: usize) usize {1367 pub fn growCapacity(minimum: usize) usize {
1368 if (@sizeOf(T) == 0) return math.maxInt(usize);
1369 const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
1370 return minimum +| (minimum / 2 + init_capacity);1370 return minimum +| (minimum / 2 + init_capacity);
1371 }1371 }
1372 };1372 };
...@@ -1751,6 +1751,14 @@ test "insert" {...@@ -1751,6 +1751,14 @@ test "insert" {
1751 try testing.expect(list.items[2] == 2);1751 try testing.expect(list.items[2] == 2);
1752 try testing.expect(list.items[3] == 3);1752 try testing.expect(list.items[3] == 3);
1753 }1753 }
1754 {
1755 var list: ArrayList(struct {}) = .empty;
1756 defer list.deinit(a);
1757
1758 try list.insert(a, 0, .{});
1759 try list.append(a, .{});
1760 try testing.expect(list.items.len == 2);
1761 }
1754}1762}
17551763
1756test "insertSlice" {1764test "insertSlice" {