file: app.d
~~~~~~~~~~~~~~~~~~~~~
void main() {
A a = A( true);
}
@safe
struct A {
bool *lala;
this( bool i) {
lala = &aVar;
}
bool aVar = true;
}
~~~~~~~~~~~~~~~~~~~~~
$ dmd --version
DMD64 D Compiler v2.077.1
...
$
$ dmd app.d
app.d(13): Error: address of variable this assigned to this with longer lifetime
$
The error message makes sense, but it may take a while to see the problem. Maybe it would be worth mentioning that `this` is a value type who can be copied.
Comment #1 by robert.schadek — 2024-12-13T18:55:35Z