Bug 2172 – statically disallow bool + bool

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-06-25T10:29:00Z
Last change time
2015-06-09T05:11:44Z
Keywords
accepts-invalid, diagnostic
Assigned to
bugzilla
Creator
davidl
Depends on
1511

Comments

Comment #0 by davidl — 2008-06-25T10:29:34Z
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.
Comment #5 by yebblies — 2012-01-30T07:17:02Z
I tend to agree.