Why is dtor called for lazy parameter?
Andrey Zherikov
andrey.zherikov at gmail.com
Fri Sep 18 14:14:31 UTC 2020
On Friday, 18 September 2020 at 13:28:39 UTC, Simen Kjærås wrote:
> Indeed. As we can see from the output, first do_lazy() is
> called from test.main, then create() is called (this happens
> inside do_lazy, as s is lazy). When create() returns, the
> scoped!S you created goes out of scope and is destroyed.
It seems that dtor is called at exit from lazy delegate, not at
exit form create():
======
create()
.do_something()
.do_lazy()
.do_something();
======
Output:
======
-> void test.main()
-> test.do_lazy(lazy S s)
-> test.create()
1 S test.S.this(int n)
<- test.create()
-> 1 test.do_something(S s)
<- 1 test.do_something(S s)
1 void test.S.~this()
===-1
<- test.do_lazy(lazy S s)
-> 1703096 test.do_something(S s)
<- 1703096 test.do_something(S s)
<- void test.main()
======
This doesn't even allow me to copy the value of 's' in do_lazy().
More information about the Digitalmars-d-learn
mailing list