pointer escaping return scope bug?
Nick Treleaven
nick at geany.org
Sat Nov 19 15:02:54 UTC 2022
On Saturday, 19 November 2022 at 14:52:23 UTC, ag0aep6g wrote:
> That's essentially just a function that returns its pointer
> parameter. So the program boils down to this:
>
> ----
> @safe:
> int* fp(return scope int* p) { return p; }
> void main()
> {
> int* p;
> {
> auto lf = new int;
> p = fp(lf);
> }
> assert(p != null); // address escaped
> }
> ----
>
> Which is fine, as far as I can tell. `lf` is not `scope`. And
> when you pass it through `fp`, the result is still not `scope`.
> So escaping it is allowed.
>
> You do get an error when you make `lf` `scope` (explicitly or
> implicitly). So everything seems to be in order.
OK, so how do I make `lf` implicitly scope?
More information about the Digitalmars-d-learn
mailing list