digitalmars.D.bugs - [Issue 2172] New: bool add bool accepted?
- d-bugmail puremagic.com Jun 25 2008
- d-bugmail puremagic.com Jun 27 2008
- "Jarrett Billingsley" <kb3ctd2 yahoo.com> Jun 27 2008
- d-bugmail puremagic.com Jun 27 2008
- d-bugmail puremagic.com Jun 29 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172 Summary: bool add bool accepted? Product: D Version: 1.030 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: davidl 126.com BugsThisDependsOn: 1511 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. --
Jun 25 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #1 from bugzilla digitalmars.com 2008-06-27 17:15 ------- 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. --
Jun 27 2008
<d-bugmail puremagic.com> wrote in message news:g43oq2$2k82$1 digitalmars.com...http://d.puremagic.com/issues/show_bug.cgi?id=2172 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #1 from bugzilla digitalmars.com 2008-06-27 17:15 ------- 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.
I can understand the OP's confusion. http://www.digitalmars.com/d/1.0/type.html "The only operators that can accept operands of type bool are: & | ^ &= |= ^= ! && || ?:. A bool value can be implicitly converted to any integral type, with false becoming 0 and true becoming 1." Which one is it? It seems that promotion to an int makes the first rule unnecessary. Also, keep in mind that D *is* your language and you don't *have* to do everything the same way as C. I think that having boolean types not implicitly convertible to ints makes a lot more sense.
Jun 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172 ------- Comment #2 from shro8822 vandals.uidaho.edu 2008-06-27 17:29 ------- I think the confusion comes from the cast failure being value dependent rather than just type dependent. --
Jun 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2172 davidl 126.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|INVALID | ------- Comment #3 from davidl 126.com 2008-06-29 22:11 ------- 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 --
Jun 29 2008









"Jarrett Billingsley" <kb3ctd2 yahoo.com> 