Bug 2713 – Error resolving types with ? : and const
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2009-03-06T16:48:00Z
Last change time
2015-06-09T01:21:08Z
Keywords
rejects-valid
Assigned to
nobody
Creator
zildjohn01
Comments
Comment #0 by zildjohn01 — 2009-03-06T16:48:18Z
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;
}
}