make @safe "non-escapable"?

Robert jfanatiker at gmx.at
Wed Feb 6 10:26:05 PST 2013


Making the following code illegal:

import std.stdio;
@safe {
int test1() @system {
    int* p=new int;
    *p++=8;
    return 7;
}
}

So if you mark code with @safe you can not mark parts of it to be
@system. This would make things possible like compile time import of
configurations, which would currently impossible in a safe way.

For importing the config file you would simply do:

@safe {
 mixin(import("app.cfg"));
}

Guaranteeing that the code in app.cfg has to be safe.

I thought of some wrapper like safeImport() which searches the code for
@system or @trusted and rejects the code if one of them is found. But
this is quite hard to do it right, especially with mixin's. So it's
probably best if the compiler handles this.

What do you think. Should I file a bug report?

Best regards,

Robert






More information about the Digitalmars-d mailing list