On Friday, 16 November 2018 at 13:21:39 UTC, Stanislav Blinov wrote:
At 'point 1', you just take by value. If `t` ends up being a closure, D will allocate. That's where it breaks the @nogc. Solution:

auto assumeNoGC(T)(return scope T t) { /* ... */ }

Now you take (and return) a `scope` t, in that case when `t` is a closure D won't allocate it on the GC heap.

At 'point 2' you make an un-@safe cast, that's where it breaks @safe. Given that the whole deal is just a debugging hack, you could mark the whole function @trusted:

auto assumeNoGC(T)(return scope T t) @trusted { /* ... */ }

Sawweet! Thanks, that made the printing possible!

"scope" is const from what I understand right? It works without scope as well. So just "return T".

Cheers,
- Ali

Reply via email to