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

safeD doesn't mean your code is safe... only "memory safe". Similarly, "shared"
sort of partitions data and there is no provably safe way to create or use it.
I have no idea if your example is truly legit safeD or not...
dsimcha 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;
}

have no idea if your example is truly legit safeD or not...
1. Using __gshared and casting **away** shared are illegal in SafeD.
2. Low level data races can cause memory corruption if pointers get overwritten
with invalid data.

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.

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.

Holy %)(*$%, casting **to** immutable works in SafeD, too? Of course casting
from/to shared/immutable should be allowed in non- safe code, but I don't think
either should be allowed in safe code. The only way to get aliasing between
mutable and immutable data in safe code should be by using broken trusted
code.
Otherwise the safe-ty of SafeD is really questionable.
Also, as far as cloning, The fact that it's really a special case of
serialization
was brought up by a few people, so I'm taking a wait-and-see attitude and seeing
what people who wrote serialization libraries come up w/ for cloning, rather
than
working on cloning now.