Skip to content

Allowed to use undefined in comparison #8056

Open
@ratfactor

Description

@ratfactor

Normally using undefined in a comparison produces a compiler error:

./foo.zig:9:9: error: use of undefined value here causes undefined behavior
    if(1==undefined) return;

But when using "this one weird trick" (comparing an optional pointer struct field), there are no errors and it compiles and runs:

const std = @import("std");

const Foo = struct{ a: ?*u8 = undefined };

pub fn main() void {
    var foo = Foo{};
    if(foo.a == undefined) std.debug.print("foo.a is undef {}\n",.{foo.a});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstage1The process of building from source via WebAssembly and the C backend.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions