[Dlang-internal] DIP1000 discussion and testing

Mathias Lang via Dlang-internal dlang-internal at puremagic.com
Sun Dec 11 23:17:11 PST 2016


On Saturday, 10 December 2016 at 05:00:42 UTC, Walter Bright 
wrote:
> On 11/22/2016 6:09 AM, Martin Nowak wrote:
>> - what about unwanted/incorrect return scope inference
>>
>> Mixed return branches would conservatively assume a scoped 
>> return value?
>> Is this a valid use-case? Should at least work with @system 
>> code.
>>
>> int* func()(int* arg, bool allocate)
>> {
>>     return allocate ? new int : arg;
>> }
>
> ?: returns the most restrictive scope of any of its operands. 
> This applies equally as well to a function with numerous 
> parameters that are return scope or return ref.
>

Not quite: https://issues.dlang.org/show_bug.cgi?id=16037

Also, another reason why tainting the STC of an aggregate is not 
a good idea:

struct Foo
{
     int* ptr;
}

void main () @safe
{
     Foo f;
     escape1(f);
     assert(*f.ptr == 42);
}

void escape1 (ref Foo f) @safe
{
     int i = 42;
     f.ptr = &i;
}



More information about the Dlang-internal mailing list