[Issue 5747] cannot cast away shared if opCast defined

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 12 14:09:05 PST 2013


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



--- Comment #9 from Max Samukha <samukha at voliacable.com> 2013-12-12 14:08:45 PST ---
(In reply to comment #7)
> (In reply to comment #6)
> > (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:
> 
> Your example snippet still overflows for me for the initial use case:

It doesn't with dmd 2.064. But that's irrelevant. As I said, it is trivial to
avoid recursion, contrary to your claim that it is impossible.

> 
> void main()
> {
>     immutable(S) s;
>     auto b = cast(S)(s); //How to do 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).
> 
> *What* limitations?

The limitation that I won't be able to intercept the qualifier-only cast down
the road if the need emerges. The limitation that you've just unnecessarily
introduced.

> 
> If we *really* wanted to overload a "qualifier cast", then arguably, we could
> add an enhancement request for something like:

No. That would be not an enhancement. That would be a bug report requesting the
removal of an necessarily introduced limitation.

> 
> auto opCast(); //Removes qualifier cast
> auto opCast(const); //Adds const
> auto opCast(shared); //Adds shared

That's not necessary since the general case of type cast handles the specific
case of qualifier-only cast perfectly.

> 
> But I really don't see how a *type* cast should interfere a *qualifier* cast.

Qualifier cast *is* a special case of type cast!

-- 
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