make @safe "non-escapable"?
Era Scarecrow
rtcvb32 at yahoo.com
Wed Feb 6 13:44:06 PST 2013
On Wednesday, 6 February 2013 at 18:26:17 UTC, 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.
Agreed, although you can always tighten the code rather than
limit it. @trusted would be the in between cases.
So this would be the behavior?
@system {
int test1() {} //@system
int test1() @safe {} //of course!
int test1() @trusted {} //of course!
a = b;
}
@trusted { //disallowed for (bulk) function/type declarations
//intended only for bits of code or for functions:
//Otherwise an easy unchecked breeding ground for
bugs!
int test1() {} //error
int test1() @safe {} //error
int test1() @system {} //error
int test1() @trusted {} //error, yes it is, even if explicit
a = b;
}
@safe {
int test1() {} //@safe
int test1() @trusted {} //will happen from time to time.
int test1() @system {} //error, cannot weaken code's
restrictions
a = b; //only if safe
}
More information about the Digitalmars-d
mailing list