[Issue 5747] cannot cast away shared if opCast defined
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Nov  3 08:31:47 PST 2013
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=5747
monarchdodra at gmail.com changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com
--- Comment #4 from monarchdodra at gmail.com 2013-11-03 08:31:45 PST ---
Just hit this. IMO, this is a bug: The presence of an opCast should not prevent
"qualification-cast", which don't actually change the type. In particular, the
problem is that *even* trying to hand write it, it's not possible:
//----
import std.traits;
struct S
{
    int* p; //prevent implicit cast
    T opCast(T:bool)() pure const
    {
        return false;
    }
    T opCast(T)() const
    if (is(Unqual!T == S))
    {
        return this; //This fails
        return cast(T) this; //This overflows
    }
}
void main()
{
    immutable(S) s;
    auto b = cast(S)(s); //How to do this?
}
//----
IMO, a cast to the *same* type (but different quals) should always be defined
by the compiler, even if another opCast is defined, unless the use explicitly
overrides *that* opCast.
-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
    
    
More information about the Digitalmars-d-bugs
mailing list