bool t;
t= true+false; // this accepted
t= true+true; // Error: cannot implicitly convert expression (2) of type int to bool
bool type shouldn't be addable.
and error message is confusing.
Comment #1 by bugzilla — 2008-06-27T17:15:30Z
bool follows the same integral promotion rules that C has, and this is working as designed. I also do not understand why the error message is confusing - 2 cannot be implicitly converted to bool, as it says.
Comment #2 by shro8822 — 2008-06-27T17:29:49Z
I think the confusion comes from the cast failure being value dependent rather than just type dependent.
Comment #3 by davidl — 2008-06-29T22:11:51Z
I don't think we still need to keep consistent with C on that exactly point.
Compiler can at least giving a waring on this.
And adding code to BinExp::semantic , and provide a table like implicitconv table
[op, e1->type, e2->type] mapping to bin op allow
for TOK.TOKadd, bool, bool -> false
TOK.TOKmul, bool, bool -> false
and this naturally fix issue 1511
Comment #4 by bearophile_hugs — 2012-01-30T04:28:27Z
The error message looks clear.
And and this point I don't think D boolean semantics will change.
So I think this bug report needs to be closed.