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