[Issue 1626] New: bool spec problem

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 29 06:40:21 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1626

           Summary: bool spec problem
           Product: D
           Version: 1.022
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: davidl at 126.com


According to :
http://www.digitalmars.com/d/1.0/expression.html
NumericLiteral is right under Primary Expressions

As we all know 
int i=3;
if (i) {} 
above is valid D code.

And right in:
http://www.digitalmars.com/d/1.0/statement.html#IfStatement
IfCondition is either Expression,auto Identifier = Expression, or Declarator =
Expression
The situation here that "i" is an Expression. 

and in the IfStatement part spec says: "Expression is evaluated and must have a
type that can be converted to a boolean."

I *assume* boolean here means bool, and it should be bool.

So expression here can be *implicitly* convert to bool.

But:

bool b=3; fails as expected with message  "Error: cannot implicitly convert
expression (3) of type int to bool"

3 is NumericLiteral therefore Primary Expressions, i.e. 3 is an Expression.

And the statement I concluded tells "expression can be *implicitly* convert to
bool"

so should 3 be implicitly converted to bool?

I hope not. The error message is obviously designed by Walter.

So maybe something more should be done to the spec.


-- 



More information about the Digitalmars-d-bugs mailing list