Mon, 01 Dec 2008 10:26:31 -0700, Russell Lewis wrote: > The thing to remember is that "scope" is *not* transitive. Scope limits > the most shallow reference, *not* not anything deeper. It is perfectly > valid to have a scope pointer to a non-scope thing. The point of scope > is to enforce that the pointer cannot escape; it does not say anything > about whether the pointed-to object escapes or not. > > The point then, is that you can create a non-scope object, and assign it > to a scope pointer. When you do something like: > > BEGIN CODE > scope <type> a; > a = <allocate thing>; > END CODE > > ...you are doing exactly that. > > (At least, that's how I think it ought to work.)
http://www.digitalmars.com/d/1.0/attribute.html#scope Originally, the scope keyword wasn't about escaping, it was about memory management. The code scope C c = new C; was a sugar for C c =new C; scope(exit) delete c; The spec says, "Assignment to a scope, other than initialization, is not allowed." Therefore your example is illegal. I think the fact that DMD accepts such a code is a bug. I'll file a bug report.