make @safe "non-escapable"?
Timon Gehr
timon.gehr at gmx.ch
Wed Feb 6 10:38:54 PST 2013
On 02/06/2013 07:26 PM, Robert wrote:
> 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?
> ...
I think so, yes.
More information about the Digitalmars-d
mailing list