RCArray is unsafe

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Wed Mar 4 11:13:53 PST 2015


On Wednesday, 4 March 2015 at 17:13:13 UTC, Zach the Mystic wrote:
> Another example:
>
> T* jun(return static T* a) {
>   static T* t;
>   t = a;
>   return a;
> }
>
> Again, no ownership, because of the `static` parameter 
> attribute. In a previous post, you suggested that such an 
> attribute was unnecessary, but an ownership system would 
> require that a given parameter `a` which was returned, not also 
> be copied to a global at the same time. So `static` tells the 
> compiler this, and thus cancels ownership.

Actually, I think you convinced me before that `static` (or 
`noscope`) parameters wouldn't carry their weight. Instead, 
copying a parameter reference to a global variable is unsafe by 
default. Wrap it in a `@trusted` lambda if you know what you're 
doing. (Trusted lambdas are assumed to copy no reference 
parameters.) In this way, you can assume ownership. Any unsafe 
global escapes are just ignored. ???


More information about the Digitalmars-d mailing list