[Issue 15832] Crashing program when a helper template function is used to create a template struct

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Mar 26 03:01:12 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15832

--- Comment #2 from Atila Neves <atila.neves at gmail.com> ---
You're right, it's not a bug. I should probably not file things late at night
when I can't think anymore. The ref thing should've been obvious.

However, even with ref, the explanation isn't quite right: the delegate created
in the constructor doesn't reference garbage - the GC should keep the memory
alive. It just references the old slice. The issue is that the delegate
references a slice that gets copied when `mock` exits. It's fine as long as the
pointer in the copied slice gets reallocated, but that's exactly what I was
doing.

I guess I was also surprised (because of C++) that the Mock struct got copied
at all. I'm so used to RVO I don't think about it anymore.

--


More information about the Digitalmars-d-bugs mailing list