ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.89k stars 2.55k forks source link

assertion is not fired #21972

Closed nine-fox closed 1 day ago

nine-fox commented 1 day ago

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 references

Expected Behavior

assert should be emited an error rather than value check

nektro commented 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.

andrewrk commented 1 day ago

The issue tracker is not for beginner questions, please ask those elsewhere.