[Bug 24] Arithmetic operators are allowed on boolean expressions
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 9 22:21:03 PST 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=24
walter at digitalmars.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|REOPENED |RESOLVED
Resolution| |INVALID
------- Comment #5 from walter at digitalmars.com 2006-03-10 00:21 -------
First, note that the bool operands undergo integral promotion rules, so that
(true op true) is evaluated as (cast(int)true op cast(int)true), with a result
type of int. The integral promotion for bools does not apply if op is & | ^
void main()
{
bool x1 = true + true; // fails because true+true => 2, and 2 cannot be
implicitly converted to bool
bool x2 = true - true; // accepted because true-true=>0, and 0 can be
implicitly converted to bool
bool x3 = true * true; // accepted because true*true => 1, and 1 can be
implicitly converted to bool
bool x4 = true / true; // accepted because true/true => 1, and 1 can be
implicitly converted to bool
bool x5; x5 += true; // fails because x5+true is int, and int cannot be
implicitly converted to bool unless it is 0 or 1
bool x6; x6 -= true; // fails because x6-true is int, and int cannot be
implicitly converted to bool unless it is 0 or 1
bool x7; x7 *= true; // fails because x7*true is int, and int cannot be
implicitly converted to bool unless it is 0 or 1
bool x8; x8 /= true; // fails because x8/true is int, and int cannot be
implicitly converted to bool unless it is 0 or 1
}
--
More information about the Digitalmars-d-bugs
mailing list