-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.14.1
Steps to Reproduce and Observed Behavior
From std/array_list.zig
:
const init_capacity = @as(comptime_int, @max(1, std.atomic.cache_line / @sizeOf(T)));
When @sizeOf(T) == 0
this causes a compile error:
const std = @import("std");
const Unit = enum { one };
const List = std.ArrayListUnmanaged(Unit);
pub fn main() !void {
var l = List.empty;
try l.append(std.heap.page_allocator, .one);
}
$ zig run test.zig
/home/joe/.local/lib/zig/std/array_list.zig:1220:81: error: division by zero here causes undefined behavior
const init_capacity = @as(comptime_int, @max(1, std.atomic.cache_line / @sizeOf(T)));
^~~~~~~~~~
I encountered this with v0.14.1 but the code is still there on master AFAICT.
Expected Behavior
The comptime calculation should handle a size of 0 and not compile error.
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior