-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enumerate all kinds of undefined behavior, even that which cannot be safety-checked #1966
Comments
So you are saying that we need to add a no-safety sub section in https://ziglang.org/documentation/master/#Undefined-Behavior that will be continuously populated? |
I believe that the subsection listing all no-safety behavior should be added.
#3180 is already mentioned above. Other examples are unsafe language constructs and builtin functions including (but, not limited to) the followings.
|
Here is an undefined behavior caused by incorrectly using comptimeconst std = @import("std");
const s = "hello";
pub fn main() void {
comptime {
var s2 = @qualCast(*[5:0]u8, s);
s2[0] = 'H';
}
} $ zig run comptime_qual-cast-ub.zig
runtimeconst std = @import("std");
const debug = std.debug;
const s = "hello";
pub fn main() void {
var s2 = @qualCast(*[5:0]u8, s);
s2[0] = 'H';
std.debug.print("s[0]: {c}\n", .{s[0]});
} $ zig run runtime_qual-cast-ub.zig
|
The language reference should have a comprehensive list of every of possible undefined behavior that is possible, with a description of either how safety checks work for it, and under what circumstances the safety check will catch the problem or not, or the docs should explain why there cannot be safety checking for this particular kind of undefined behavior.
With this it will be obvious how close (or distant) zig is from a safe language.
The text was updated successfully, but these errors were encountered: