D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2713 - Error resolving types with ? : and const
Summary: Error resolving types with ? : and const
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 All
: P3 minor
Assignee: No Owner
URL: http://www.digitalmars.com/webnews/ne...
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-03-06 16:48 UTC by John Simon
Modified: 2015-06-09 01:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description John Simon 2009-03-06 16:48:18 UTC
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;
    }
}
Comment 1 Don 2010-06-07 01:51:10 UTC
Fixed DMD2.031.