On Friday, 17 July 2015 at 16:40:56 UTC, Jonathan M Davis wrote:

However, it has way too many holes in it still, because we've blacklisted rather than whitelisted

Not being a fan of constantly writing these attributes, I had been thinking a month or so ago that it would be cool if you could just specify defaults for the function attributes on a module-by-module basis. However, it's pretty easy to just set something similar up using the existing language features.

import std.traits;

@safe
{
        int foo(int x)
        {
                return x * 2;
        }
        int bar(int x) @system
        {
                return x * 2;
        }
}

void main()
{
        static assert(functionAttributes!foo & FunctionAttribute.safe);
        static assert(functionAttributes!bar & FunctionAttribute.system);
}

It even generates the correct documentation that foo is @safe and bar is @system.

I think this might be similar to Martin Nowak's point about @unsafe { } guards, but I'm not entirely sure what he meant.

Reply via email to