xxxxxxxxxx
import std.stdio;
:
struct S
{
:
int a;
~this()
{
a = 0;
}
ref val()
{
return a;
}
}
S bar()
{
return S(2);
}
int foo()
{
return bar.val; // The return value of val is saved locally as ref int and then the destructor of S is called (set the local cache to 0). Now the ref value is dereferenced and returned
}
void main()
{
assert(foo() == 2); // foo() is 0
}