[Dlang-internal] DIP1000 discussion and testing
Mathias Lang via Dlang-internal
dlang-internal at puremagic.com
Mon Oct 24 02:13:58 PDT 2016
On Sunday, 23 October 2016 at 06:42:41 UTC, Walter Bright wrote:
> On 10/22/2016 7:34 PM, Walter Bright wrote:
>> 2. You're right that the above should error, I'll look into it.
>
> Added the fix to the PR.
Somehow my previous (mailed yesterday afternoon) message didn't
go through, so I'm going to paste it here again:
Just looked at it.
The diff shows:
+fail_compilation/retscope.d(198): Error: scope variable e may
not be returned
+void* escapeDg1(scope void* d) @safe
+{
+ Escaper e;
+ e.DG = d;
+ return e.DG; // L198
+}
So it means that the storage class of 'e' changes during semantic
analysis of the function. I don't think that's something we want
to ever do.
Crafting a test case that exploit this was trivial:
void* escape3 (scope void* p) @safe
{
Escaper e;
scope dg = () { return e.e; };
e.e = p;
return dg();
}
Not to mention, if we ever relax the restriction on taking the
address of a local variable, as the DIP seems to hint as a goal,
you can just do:
Escaper e;
Escaper* pe = &e;
And you'll have the same issue.
More information about the Dlang-internal
mailing list