Bug 4773 – Rebindable should be castable to bool

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-08-31T08:03:00Z
Last change time
2011-07-30T11:03:08Z
Keywords
patch, rejects-valid
Assigned to
nobody
Creator
simen.kjaras
Depends on
5020

Comments

Comment #0 by simen.kjaras — 2010-08-31T08:03:15Z
Comment #1 by simen.kjaras — 2010-08-31T08:09:08Z
Yeah, that's what you get when you press the wrong buttons. :p Anyways, Rebindable should be castable to bool, to allow for the idiom Rebindable!T foo; if (foo) {}. Addition to typecons.d, line 747: T opCast(T : bool)() { return original !is null; }
Comment #2 by rsinfu — 2010-10-08T13:18:00Z
Actually, it's explicitly castable to bool: Rebindable!(const Object) r; if (cast(bool) r) assert(0); r = new Object; if (!cast(bool) r) assert(0); But dmd doesn't forward implicit boolean conversions in if (or other) conditions to Rebindable's alias-this object. Reported: bug 5020.
Comment #3 by k.hara.pg — 2011-07-26T21:07:23Z
This is dmd issue. Fixing bug5020 is incomplete, so property function + alias this is not implicitly convertible to bool. ---- struct Rebindable { Object obj; @property const(Object) get(){ return obj; } alias get this; } Rebindable r; if (r) assert(0); r.obj = new Object; if (!r) assert(0); ----
Comment #4 by k.hara.pg — 2011-07-29T19:17:26Z
Comment #5 by bugzilla — 2011-07-30T10:37:44Z
Comment #6 by bearophile_hugs — 2011-07-30T11:03:08Z
*** Issue 5256 has been marked as a duplicate of this issue. ***