[Issue 1624] New: test of bool doesn't hold always

Matti Niemenmaa see_signature at for.real.address
Mon Oct 29 04:38:54 PDT 2007


d-bugmail at puremagic.com wrote:
> http://d.puremagic.com/issues/show_bug.cgi?id=1624
> 
>            Summary: test of bool doesn't hold always
>            Product: D
>            Version: 1.022
>           Platform: PC
>         OS/Version: Windows
>             Status: NEW
>           Severity: normal
>           Priority: P2
>          Component: DMD
>         AssignedTo: bugzilla at digitalmars.com
>         ReportedBy: davidl at 126.com
> 
> 
> void main()
> {
>         union e{
>                 bool k;
>                 Object v;
>         }
>         e m;
>         m.v = new Object;
>         assert(m.k);
>         assert((!m.k) == false);   // assertion failure
> }

This is analogous to doing something like:

bool b;
byte* p = cast(byte*)&b;
*p = 127;
assert (b || !b); // 127 != 0 so "b" holds
assert (b == true || b == false); // oh noes, true == 1 and 1 != 127

Expecting to find true or false when you've explicitly forced the variable to
hold neither value will obviously not work.

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi


More information about the Digitalmars-d-bugs mailing list