Thread overview
[Issue 20956] [DIP1000] @safe defeated by closure capturing ref parameter
Jun 19, 2020
Mathias LANG
Jan 04, 2022
Dennis
Aug 12, 2022
Walter Bright
Aug 12, 2022
Dlang Bot
Dec 17, 2022
Iain Buclaw
June 19, 2020
https://issues.dlang.org/show_bug.cgi?id=20956

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
January 04, 2022
https://issues.dlang.org/show_bug.cgi?id=20956

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dkorpel@live.nl

--- Comment #1 from Dennis <dkorpel@live.nl> ---
Reduced a bit more:
```
@safe:
alias DG = void delegate() @safe;

void main()
{
    DG dg = getDg(42);
    stompStack();
    dg();
}

DG getDg(int val)
{
    return forwardDg(val);
}

DG forwardDg(ref int c)
{
    return () {assert(c == 42);};
}

void stompStack()
{
    int[256] oops = int.max;
}
```
Also, it fails both with or without -dip1000. I think closing over a ref
parameter should be an error (at least in `@safe` code), because it's really
hard for `forwardDg` to create a closure including the stack frame of `getDg`:
it has to be done at runtime, since you can't statically know where the `ref`
parameter came from.

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

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=8538

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

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

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

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright updated dlang/dmd pull request #14364 "fix Issue 20956 - [DIP1000] @safe defeated by closure capturing ref p…" fixing this issue:

- fix Issue 20956 - [DIP1000] @safe defeated by closure capturing ref parameter

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

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=20956

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--