Jump to page: 1 2
Thread overview
[Issue 22977] [dip1000] can escape scope pointer returned by nested function
Jun 21, 2022
Dlang Bot
Aug 15, 2022
Walter Bright
Aug 27, 2022
Walter Bright
Aug 28, 2022
Walter Bright
Aug 28, 2022
Dennis
Aug 29, 2022
Dlang Bot
Aug 29, 2022
Walter Bright
Aug 29, 2022
Walter Bright
Oct 26, 2022
Walter Bright
Dec 17, 2022
Iain Buclaw
Jul 22
Dennis
June 21, 2022
https://issues.dlang.org/show_bug.cgi?id=22977

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

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

--- Comment #1 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #14236 "Fix 22977 - can escape scope pointer returned by nested function" fixing this issue:

- Fix 22977 - can escape scope pointer returned by nested function

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

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

Walter Bright <bugzilla@digitalmars.com> changed:

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

--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> ---
Probably the most sensible way to deal with this is to allow non-static nested functions to have `return` and `scope` attributes, and then treat uplevel variable references as if they were parameters marked with those attributes.

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

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
Interestingly, if `scope return` is added to `fn()`:

 int* gPtr;

 void main() @safe
 {
    scope int* sPtr;
    int* fn() scope return { return sPtr; }
    gPtr = fn();
 }

The correct error is generated:

 Error: reference to stack allocated value returned by `fn()` assigned to
non-scope `gPtr`

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

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
It appears that the problem is the nested function is not inferring `return scope` when returning a scope variable from its closure.

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

--- Comment #5 from Dennis <dkorpel@live.nl> ---
(In reply to Walter Bright from comment #4)
> It appears that the problem is the nested function is not inferring `return scope` when returning a scope variable from its closure.

Indeed, the linked PR (https://github.com/dlang/dmd/pull/14236) tries to fix this, but it is currently blocked by buildkite projects.

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

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #14391 "fix Issue 22977 - [dip1000] can escape scope pointer returned by nest…" fixing this issue:

- fix Issue 22977 - [dip1000] can escape scope pointer returned by nested function

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

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

--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> ---
And now we have two fixes! Let's compare and make the best of both.

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

--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> ---
Dennis, your's is better.

--
October 26, 2022
https://issues.dlang.org/show_bug.cgi?id=22977

Walter Bright <bugzilla@digitalmars.com> changed:

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

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
« First   ‹ Prev
1 2