void main()
{
union e{
bool k;
Object v;
}
e m;
m.v = new Object;
assert(m.k);
assert((!m.k) == false); // assertion failure
}
Comment #1 by bugzilla — 2007-10-29T05:51:39Z
The only valid values for a bool are true and false. In the example, a union is used to set bool to an invalid value, hence the subsequent operations on that bool do not produce the expected results.
The code is incorrect, not the compiler.
Comment #2 by davidl — 2007-10-29T06:58:21Z
Where does the specification tell what the value of true/false is?
So you actually mean a bool in a union is dangerous? I'm not aware of that.
I think either doc or compiler need to be fixed
Comment #3 by matti.niemenmaa+dbugzilla — 2007-10-29T07:07:06Z
http://www.digitalmars.com/d/1.0/type.html
"A bool value can be implicitly converted to any integral type, with false becoming 0 and true becoming 1. The numeric literals 0 and 1 can be implicitly converted to the bool values false and true, respectively."
If you shove a value which is neither 0 nor 1 into a variable, and expect it to behave as though it were 0 or 1, you are doing something wrong.