Comment #0 by default_357-line — 2023-08-30T07:53:41Z
Consider this code:
@trusted:
extern(C) int printf(const char*, ...);
@safe:
struct S {
int i;
this(int i) { this.i = i; printf(" this(%i)\n", i); }
~this() { printf(" ~this(%i)\n", i); }
}
void delegate() @safe foo() {
S s = S(5);
return { printf("access s %i after destruction\n", s.i); };
}
void main() {
foo()();
}
The closure in `foo` accesses `s` after the `s` destructor has run. This can be an issue if `S` frees resources in the destructor.
Comment #1 by robert.schadek — 2024-12-13T19:30:40Z