Bug 18644 – [dip1000] escape of outer local not detected
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-21T07:30:21Z
Last change time
2018-03-22T00:08:44Z
Keywords
safe
Assigned to
No Owner
Creator
Walter Bright
Comments
Comment #0 by bugzilla — 2018-03-21T07:30:21Z
Consider:
@safe void test() {
int i;
int*[] a = [&i]; // error detected correctly
int* foo() { return &i; }
int*[] b = [foo()]; // should detect error
}
Comment #1 by issues.dlang — 2018-03-21T08:23:10Z
Shouldn't the error be that
int* foo() { return &i; }
is trying to convert scope int* to int* in @safe code? Unless foo isn't inferred as @safe in spite of it being declared in an @safe function, but if that's the case, then calling foo should be an error, since otherwise, an @safe function would be calling an @system function without @trusted being involved. Certainly, given the fact that foo() returns int*, I don't see how
int*[] b = [foo()]; // should detect error
is invalid. It's only dealing with int*. So, there's no escaping as far is that bit of code is concerned.
(In reply to Jonathan M Davis from comment #1)
> int i;
> int* foo() { return &i; }
should behave like:
int* foo(int* p) { return p; }
and then the error is detected:
int*[] b = [foo(&i)];
The [ ] puts things on the heap, where they escape.
Comment #4 by github-bugzilla — 2018-03-22T00:08:43Z