On Sunday, 11 September 2016 at 07:46:09 UTC, Manu wrote:
I'm having a lot of trouble debugging @nogc functions. I have a number of debug functions that use GC, but I can't call them from @nogc code... should debug{} allow @nogc calls, the same as impure calls?

We could with something like this in Phobos:

void assumeNogc(alias Func, T...)(T xs) @nogc {
        import std.traits;
        static auto assumeNogcPtr(T)(T f) if (
                isFunctionPointer!T || isDelegate!T
        ) {
            enum attrs = functionAttributes!T | FunctionAttribute.nogc;
return cast(SetFunctionAttributes!(T, functionLinkage!T, attrs)) f;
        };
        assumeNogcPtr(&Func!T)(xs);
};


void main() @nogc
{
        import std.stdio;
        assumeNogc!writefln("foo %s", 42);
}

Source: https://dpaste.dzfl.pl/8c5ec90c5b39

Reply via email to