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(); }
Comment #2 by bugzilla — 2017-08-10T04:01:19Z
Note that it works if int[] is replaced by int*. https://github.com/dlang/dmd/pull/7076
Comment #3 by github-bugzilla — 2017-08-10T12:16:55Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fc9c84ba1722c02f0c1877ffa39134c84a5e13e0 fix Issue 17388 - [scope] e[] should be treated like &e as far as scope goes https://github.com/dlang/dmd/commit/09cd19d51b1e000dc81a61d167dc559480958f3e Merge pull request #7076 from WalterBright/fix17388 fix Issue 17388 - [scope] e[] should be treated like &e as far as sco… merged-on-behalf-of: Martin Nowak <[email protected]>
Comment #4 by github-bugzilla — 2017-08-16T13:24:23Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/fc9c84ba1722c02f0c1877ffa39134c84a5e13e0 fix Issue 17388 - [scope] e[] should be treated like &e as far as scope goes https://github.com/dlang/dmd/commit/09cd19d51b1e000dc81a61d167dc559480958f3e Merge pull request #7076 from WalterBright/fix17388