Thread overview
[Issue 22095] Closure not created or corrupted when accessing pointer in inline function
Jul 01, 2021
Vladimir Panteleev
Jul 01, 2021
kinke
Jul 01, 2021
Vladimir Panteleev
Jul 01, 2021
Vladimir Panteleev
Jul 28, 2022
Walter Bright
Aug 12, 2022
Walter Bright
July 01, 2021
https://issues.dlang.org/show_bug.cgi?id=22095

--- Comment #1 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
(In reply to Vladimir Panteleev from comment #0)
> The assection

The assertion fails, presumably because the memory referenced by the pointer is no longer valid.

--
July 01, 2021
https://issues.dlang.org/show_bug.cgi?id=22095

kinke <kinke@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke@gmx.net

--- Comment #2 from kinke <kinke@gmx.net> ---
> presumably because the memory referenced by the pointer is no longer valid.

Exactly, but that's to be expected, as it's not captured. The problem is rather that this isn't caught when making everything @safe with -dip1000 - the compiler should complain that the address of local `s` is assigned to a heap closure `pS` with longer lifetime.

--
July 01, 2021
https://issues.dlang.org/show_bug.cgi?id=22095

--- Comment #3 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
(In reply to kinke from comment #2)
> Exactly, but that's to be expected, as it's not captured. The problem is rather that this isn't caught when making everything @safe with -dip1000 - the compiler should complain that the address of local `s` is assigned to a heap closure `pS` with longer lifetime.

Not sure what you mean by this. s and pS should both be in the closure. As far as I can see, the code is valid even with @safe/-dip1000, and no warning should be emitted.

--
July 01, 2021
https://issues.dlang.org/show_bug.cgi?id=22095

--- Comment #4 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
Oh, does the compiler only put referenced variables in the closure? I thought it was the entire frame. Now this makes sense.

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

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

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
This looks like the same problem as https://issues.dlang.org/show_bug.cgi?id=8538

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

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> ---


*** This issue has been marked as a duplicate of issue 8538 ***

--