www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2713] New: Error resolving types with ? : and const

reply d-bugmail puremagic.com writes:

           Summary: Error resolving types with ? : and const
           Product: D
           Version: 2.025
          Platform: PC
               URL: http://www.digitalmars.com/webnews/newsgroups.php?art_gr
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: minor
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: zildjohn01 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;

Mar 06 2009
parent d-bugmail puremagic.com writes:

Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED

--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-06-07 01:51:10 PDT ---
Fixed DMD2.031.

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 07 2010