[Issue 20148] void initializated bool can be both true and false

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 1 17:24:30 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=20148

hsteoh at qfbox.info changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #8 from hsteoh at qfbox.info ---
The specified PR does not fully fix the problem.

Proof:
--------
bool schrodingersCat() @safe {
        union Box { bool b; ubyte y; }
        Box u;
        u.y = 2;
        return u.b;
}

void main() @safe {
        import std.stdio;
        bool b = schrodingersCat();
        if (b) writeln("alive");
        if (!b) writeln("dead");
}
--------

Output:
--------
alive
dead
--------

--


More information about the Digitalmars-d-bugs mailing list