[Issue 2713] New: Error resolving types with ? : and const
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri Mar  6 14:48:15 PST 2009
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=2713
           Summary: Error resolving types with ? : and const
           Product: D
           Version: 2.025
          Platform: PC
               URL: http://www.digitalmars.com/webnews/newsgroups.php?art_gr
                    oup=digitalmars.D&article_id=85423
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: minor
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: zildjohn01 at gmail.com
The following fails to compile:
bool flag() {
        bool left, right;
        return true ? cast(const bool)left : cast(bool)right;
}
with the error "cannot implicitly convert expression (cast(int)left) of type
int to bool".  It seems to happen whenever the left and right sides differ in
const-ness or invariant-ness.
This becomes an issue when trying to write const-correct class functions which
return bool, for example:
class C {
    private int mask;
    private bool readyYet() const {return true;}
    public bool ExtractStateBit() const {
        return readyYet() ? (mask & 1) : false;
    }
}
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list