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.
Comment #2 by bugzilla — 2018-03-21T08:25:51Z
Comment #3 by bugzilla — 2018-03-21T08:29:35Z
(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
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/51565f362fd318ceb0cf94519819c3232b1adb22 fix Issue 18644 - [dip1000] escape of outer local not detected https://github.com/dlang/dmd/commit/0e0df72c1d3b70cb2f1a7fb2f6b26ac7bb8dcc39 Merge pull request #8062 from WalterBright/fix18644 fix Issue 18644 - [dip1000] escape of outer local not detected