Bug 17388 – [scope] e[] should be treated like &e as far as scope goes
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-05-09T18:10:13Z
Last change time
2017-08-16T13:24:23Z
Keywords
safe
Assigned to
No Owner
Creator
Per Nordlöw
Comments
Comment #0 by per.nordlow — 2017-05-09T18:10:13Z
A file named `test_scope.d` containing
@safe pure nothrow @nogc:
struct S
{
@safe pure nothrow @nogc
inout(int)[] opSlice() inout return scope
{
return x[];
}
int[4] x;
}
int[] f()
{
S s;
return s[];
}
compiled with -dip1000 correctly errors as
test_scope.d(16,13): Error: escaping reference to local variable s
but if return type of `opSlice` is changed to `auto` the compiler acccepts it which is wrong.
Comment #1 by bugzilla — 2017-08-10T00:39:25Z
This shrinks down a bit to:
struct S {
int[] // works
//auto // doesn't work
foo() return @safe {
return x[];
}
int[4] x;
}
@safe int[] f() {
S s;
return s.foo();
}