[Bug 24] Arithmetic operators are allowed on boolean expressions

Derek Parnell derek at psych.ward
Thu Mar 9 18:12:18 PST 2006


On Fri, 10 Mar 2006 02:03:22 +0000 (UTC), d-bugmail at puremagic.com wrote:

> http://d.puremagic.com/bugzilla/show_bug.cgi?id=24
> 
> ddparnell at bigpond.com changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|RESOLVED                    |REOPENED
>          Resolution|INVALID                     |
> 
> ------- Comment #4 from ddparnell at bigpond.com  2006-03-09 20:03 -------
> With version v0.149 (Windows) I get this ...
> 
> void main()
> {
>     bool x1 = true + true; // fails
>     bool x2 = true - true; // accepted
>     bool x3 = true * true; // accepted
>     bool x4 = true / true; // accepted
>     bool x5; x5 += true;  // fails
>     bool x6; x6 -= true; // fails
>     bool x7; x7 *= true; // fails
>     bool x8; x8 /= true; // fails
> }

I see what's happening now. The compiler is converting the 'true'/'false'
to 1 and 0 then doing the calculation and if the result is 1 or 0, it
accepts the code otherwise it rejects it.

However, this is still not the appropriate way to do it because even though
"false + false" would be accepted by dmd, it shouldn't be because 'false'
is not a number even though it can be converted to zero by convention.

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
10/03/2006 1:09:49 PM



More information about the Digitalmars-d-bugs mailing list