Consider: @safe void test() { int i; int*[] a = [&i]; // error detected correctly int* foo() { return &i; } int*[] b = [foo()]; // should detect error }
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.
https://github.com/dlang/dmd/pull/8062
(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.
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