Closed nine-fox closed 1 day ago
std.debug.assert
when not run in a comptime context is a runtime safety check in Debug
and ReleaseSafe
modes. the code above produced a compile error.
The issue tracker is not for beginner questions, please ask those elsewhere.
Zig Version
0.14.dev
Steps to Reproduce and Observed Behavior
The assertion in the following code is not fired. Not sure why. Is it expected?
const std = @import("std");
pub inline fn myfunc(value: usize) bool { std.debug.assert(value != 0); return value & (value - 1) == 0; }
pub fn main() !void { _ = myfunc(0); }
output is as follows.
$ zig run main.zig main.zig:152:27: error: overflow of integer type 'usize' with value '-1' return value & (value - 1) == 0;
~~^~~ main.zig:156:15: note: called from here _ = myfunc(0);~~^~~ referenced by: WinStartup: D:\zig\0.14.dev\lib\std\start.zig:617:37 comptime: D:\zig\0.14.dev\lib\std\start.zig:64:30 2 reference(s) hidden; use '-freference-trace=4' to see all referencesExpected Behavior
assert should be emited an error rather than value check