Lots of bool operations shouldn't compile

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Feb 28 06:17:12 PST 2006


Don Clugston skrev:
> Four examples, although it's only one bug. Almost all operations on bool 
> should be disabled, but I found the ones below a little amusing. None of 
> them should compile, but they all evaluate as "true".
> 
> void main()
> {
>     if (true >= ireal.nan) { writefln("This is kind of ridiculous"); }
>     if (false >= ireal.nan) { writefln("This is kind of ridiculous"); }
>     if (true <> -2i) { writefln("NCEG operators too ??!!"); }
>     if (false != -2i) { writefln("and again"); }
> }

According to the specification, booleans are a numeric type. true == 1 
and false == 0. So this error is not specific to bool.

Try s/true/1/g and s/false/0/g and you will get the same results.

The first two comparisons should be false I guess since they are 
unordered. The other two are correct.

(If it is wise to have bool as a numeric type is a different question.)

/Oskar





More information about the Digitalmars-d-bugs mailing list