My Reference Safety System (DIP???)

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Feb 26 12:46:06 PST 2015


On Thursday, 26 February 2015 at 16:40:27 UTC, Zach the Mystic 
wrote:
> I'm unclear about what you're saying. Can you give an example 
> in code?
>

See below.

>> That would allow to copy a parameter reference to a global, 
>> which is dead unsafe.
>
> Actually, it's not unsafe, so long as you have the parameter 
> attribute `noscope` (or possibly `static`) working for you:
>

Consider :

void foo(T** a) {
     T** b = a; // OK
     T*  = ...;
     *b = c; // Legal because of your transitive clause,
             // but not safe as a can have an
             // arbitrary large lifetime.
}

This show that anything you reach through an indirection can have 
from the same lifetime as the indirection up to an infinite 
lifetime (and anything in between). When using it as an lvalue, 
you should consider the largest possible lifetime, when using it 
as an rvalue, you should consider the smallest (this is the only 
way to be safe).


More information about the Digitalmars-d mailing list