mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
25 lines
848 B
Zig
25 lines
848 B
Zig
test "@setRuntimeSafety" {
|
|
// The builtin applies to the scope that it is called in. So here, integer overflow
|
|
// will not be caught in ReleaseFast and ReleaseSmall modes:
|
|
// var x: u8 = 255;
|
|
// x += 1; // undefined behavior in ReleaseFast/ReleaseSmall modes.
|
|
{
|
|
// However this block has safety enabled, so safety checks happen here,
|
|
// even in ReleaseFast and ReleaseSmall modes.
|
|
@setRuntimeSafety(true);
|
|
var x: u8 = 255;
|
|
x += 1;
|
|
|
|
{
|
|
// The value can be overridden at any scope. So here integer overflow
|
|
// would not be caught in any build mode.
|
|
@setRuntimeSafety(false);
|
|
// var x: u8 = 255;
|
|
// x += 1; // undefined behavior in all build modes.
|
|
}
|
|
}
|
|
}
|
|
|
|
// test_safety=integer overflow
|
|
// optimize=ReleaseFast
|