2013/4/28 Walter Bright <newshou...@digitalmars.com>

> On 4/27/2013 3:58 PM, Walter Bright wrote:
>
>> On 4/27/2013 1:26 PM, kenji hara wrote:
>>
>>> I don't have so much knowledge about C/C++ language spec, but for the
>>> issue case
>>> C++ makes "ambiguous error".
>>>
>>
>> That's because C++ regards an implicit conversion of 1 to bool or long as
>> having
>> equal weight, and it has no further mechanism.
>>
>>
> Note that the following is also ambiguous in C++:
>
> void foo(bool b) { }
> void foo(long l) { }
>
> void main() {
>     foo(3);
> }
>


Yes, but all C++ users would accept the behavior - In C++, all integer
types are treated as bool type under the rule that zero/non-zero value is
equivalent to false /true. From the view of D user, it looks inconvenient,
but there is still few and consistent rule.
On the other hand, D looks like having *special rule* of 0 and 1 literal
for boolean type. Even if the underlying rule is sane (partial ordering
rule and VRP), the combination makes weird behavior.

----

Now I doubt that this problem comes from the history of D and wrong dmd
implementation. In early D1 age, we had had 'bit' type which exactly have
one bit value 0 and 1. After the while, the name 'bit' changed to
'bool'. At that point, 'bool' was kept the characteristics that it is one
of the integer types - even though we should discard it. Right?

VRP is a new concept that introduced in D2 age. But, maybe, the combination
of bool and VRP had not been considered enough. So now problem is appeared
there.

Now it feels to me that is a debt from D1.

Kenji Hara

Reply via email to