[Issue 5747] cannot cast away shared if opCast defined

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 11 09:16:35 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=5747


Max Samukha <samukha at voliacable.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samukha at voliacable.com


--- Comment #6 from Max Samukha <samukha at voliacable.com> 2013-12-11 09:16:24 PST ---
(In reply to comment #4)

>     {
>         return this; //This fails
>         return cast(T) this; //This overflows
>     }

That's expected. It is easy to break the recursion:

struct S
{
    int* p; //prevent implicit cast
    T opCast(T:bool)() pure const
    {
        return false;
    }

    T opCast(T)() const
        if (is(Unqual!T == S))
    {
        static if (is(T == const))
            return this;
        else
            return cast(T)this;     
    }
}

I think the fix to issue 11722 has introduced an unnecessary limitation
(provided other annoyances are removed, such as opCast not being called if
types match exactly).

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


More information about the Digitalmars-d-bugs mailing list