March 10, 2006 Re: [Bug 24] Arithmetic operators are allowed on boolean expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Kelly | "Sean Kelly" <sean@f4.ca> wrote in message news:dur6p8$2ila$1@digitaldaemon.com... >> bool x5; x5 += true; // fails because x5+true is int, and int cannot >> be >> implicitly converted to bool unless it is 0 or 1 > > bool defaults to false/0, so x5 + true should equal 1, which should not fail. That would be true if x5 is a const, but it isn't, so it doesn't get constant folded. The same applies to the other examples. |
March 10, 2006 Re: [Bug 24] Arithmetic operators are allowed on boolean expressions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Walter Bright wrote:
> "Sean Kelly" <sean@f4.ca> wrote in message news:dur6p8$2ila$1@digitaldaemon.com...
>>> bool x5; x5 += true; // fails because x5+true is int, and int cannot be
>>> implicitly converted to bool unless it is 0 or 1
>> bool defaults to false/0, so x5 + true should equal 1, which should not fail.
>
> That would be true if x5 is a const, but it isn't, so it doesn't get constant folded. The same applies to the other examples.
Oh I see. Makes a lot more sense now :-)
Sean
|
Copyright © 1999-2021 by the D Language Foundation