Semantics of casting **to** shared?

Denis Koroskin 2korden at gmail.com
Sat Sep 4 12:38:19 PDT 2010


On Sat, 04 Sep 2010 22:05:05 +0400, dsimcha <dsimcha at yahoo.com> wrote:

> I noticed that the following code compiles even in SafeD.  Is this a  
> bug?  If
> not, what are the semantics of casting unshared to shared?  TDPL doesn't  
> seem
> to mention this.  Isn't it dangerous to have shared and unshared  
> references to
> the same memory?
>
> @safe:
> class Foo {
>     uint num;
> }
>
> void main() {
>     auto foo = new Foo;
>     auto bar = cast(shared) foo;
> }

I loved the recent clone() idea. I think it might be better to disable  
casting to (and from) shared (and immutable) and make a (deep?) copy of an  
object instead. This will make sure that the isn't any dangling reference  
left. I strongly believe dangling references could become a major source  
of bugs which might be hard to find and fix.


More information about the Digitalmars-d mailing list