Thread overview
[Issue 8538] array variadic apparently doesn't get copied in closure
Apr 03, 2022
Dennis
Jul 28, 2022
Walter Bright
Jul 28, 2022
Walter Bright
Jul 28, 2022
Walter Bright
[Issue 8538] scope parameters escaping via closure
Aug 12, 2022
Walter Bright
Aug 12, 2022
Dlang Bot
Aug 12, 2022
Walter Bright
Aug 12, 2022
Walter Bright
April 03, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe
                 CC|                            |dkorpel@live.nl
           Severity|minor                       |major

--- Comment #1 from Dennis <dkorpel@live.nl> ---
Bumping the priority, because this is a memory safety issue not caught by @safe
/ dip1000:
```
@safe:
void delegate() @safe test(Object[] objs...) {
        return () {assert(objs[0]); assert(objs[1]);};
}

void delegate() @safe foo() {
        return test(new Object, new Object);
}

void main() {
        auto it = foo(); // but if we build the array elsewhere
        it(); // this triggers a failure
}
```

--
July 28, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
A simpler version of the same problem:

---
@safe
int delegate() test(scope int* p)
{
    return () { return *p; };
}
---

`p` is placed in a dynamically allocated closure, which then escapes via the returned delegate.

The fix is to not allow scope variables to be put in a dynamic closure.

--
July 28, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
Furthermore, a variable cannot be inferred as `scope` if it is referenced in a dynamic closure.

--
July 28, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=22095

--
August 12, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|array variadic apparently   |scope parameters escaping
                   |doesn't get copied in       |via closure
                   |closure                     |

--
August 12, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #14363 "fix Issue 8538 - scope parameters escaping via closure" fixing this issue:

- fix Issue 8538 - scope parameters escaping via closure

https://github.com/dlang/dmd/pull/14363

--
August 12, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang-bugzilla@thecybershad
                   |                            |ow.net

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
*** Issue 22095 has been marked as a duplicate of this issue. ***

--
August 12, 2022
https://issues.dlang.org/show_bug.cgi?id=8538

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=20956

--
December 13
https://issues.dlang.org/show_bug.cgi?id=8538

--- Comment #6 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18459

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--