D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2172 - statically disallow bool + bool
Summary: statically disallow bool + bool
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: Walter Bright
URL:
Keywords: accepts-invalid, diagnostic
Depends on: 1511
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-25 10:29 UTC by david
Modified: 2015-06-09 05:11 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description david 2008-06-25 10:29:34 UTC
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 Walter Bright 2008-06-27 17:15:30 UTC
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 BCS 2008-06-27 17:29:49 UTC
I think the confusion comes from the cast failure being value dependent rather than just type dependent.
Comment 3 david 2008-06-29 22:11:51 UTC
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 bearophile_hugs 2012-01-30 04:28:27 UTC
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 yebblies 2012-01-30 07:17:02 UTC
I tend to agree.