What does 'scope' mean for non-class types?

Stewart Gordon smjg_1998 at yahoo.com
Tue Jun 1 10:04:32 PDT 2010

div0 wrote:
> No, that bug is completely different.
> None of Lars example code involved assigning to a scope var after it's
> declaration. We've discussed this before; allowing assignment to a scope
> variable raise questions about which object should actually be deleted.

True, but you stated before that scope on a primitive type does 
_nothing_ effect, so I was just pointing out that by spec that isn't 
literally the case.

>>>>   struct B { ... }
>>>>   scope B b;
>>> Nothing, B's destructor will be called even without scope.
>>>>   scope int[] c;
>>> c gets deleted when the scope ends. this applies to classes as well.
>> <snip>
>> What gets deleted - the array or the individual objects?
>> Stewart.
> Just the array. There maybe references to those objects elsewhere.
> Though if the compiler can do escape analysis and prove all the objects
> are dead, then they should be deleted at end of scope as well.

But you might also want to create an array of RAII objects.

At the moment, you can't have an array of a scope class, and if you want 
an array of RAII objects you have to declare each individually and then 
put them into the array (meaning there can only be a fixed number of them).


More information about the Digitalmars-d-learn mailing list