Summary: Error resolving types with ? : and const
           Product: D
           Version: 2.025
          Platform: PC
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: minor
          Priority: P3
         Component: DMD

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;


Reply via email to