Bug 17784 – [scope][DIP1000] Confusing error message for escaping local via new-expression

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-08-27T06:34:15Z
Last change time
2018-03-21T02:37:16Z
Keywords
diagnostic, safe
Assigned to
No Owner
Creator
ZombineDev

Comments

Comment #0 by petar.p.kirov — 2017-08-27T06:34:15Z
With PR https://github.com/dlang/dmd/pull/7101, given the following code: ``` #line 1300 // https://issues.dlang.org/show_bug.cgi?id=17370 void test1300() @safe { int i; auto p = new S1300(&i).oops; // line 1306 } struct S1300 { int* oops; // this(int* p) @safe { oops = p; } } ``` The compiler produces the following error message: scope_test.d(1306): Error: returning `& i` escapes a reference to local variable `i` Which is confusing to the user, because there are no return statements in the whole file. I suggest the following error message: scope_test.d(1306): Error: reference to local variable `i` assigned to heap-allocated `S1300.oops` with possibly longer lifetime
Comment #1 by bugzilla — 2018-03-19T07:54:33Z
Comment #2 by github-bugzilla — 2018-03-21T02:37:15Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/940cfd79fa681809e0e983faa1576d2efebf0953 fix Issue 17784 - [scope][DIP1000] Confusing error message for escaping local via new-expression https://github.com/dlang/dmd/commit/ce08cffe71911e86d8adfb241ff4d4e63136db8c Merge pull request #8054 from WalterBright/fix17784 fix Issue 17784 - [scope][DIP1000] Confusing error message for escapi…