DIP 1028---Make @safe the Default---Community Review Round 1
jmh530
john.michael.hall at gmail.com
Thu Jan 2 15:02:07 UTC 2020
On Thursday, 2 January 2020 at 14:37:02 UTC, Dominikus Dittes
Scherkl wrote:
> [snip]
>
> Yes, yes!
> But this tool should not slap @system on every function, but
> only on those that don't compile with the new default - the
> rest was already @safe but the proper annotation was missing,
> so this is the benefit we get. Don't waste it!
You should probably also check that the unittests still pass
too...especially if the behavior of the function can change
depending on whether something is @safe or not. For instance, in
the code below, if you add in @system for foo and baz, then the
unittests still compile, but if you make foo and baz @safe, then
the unittests no longer pass.
import std;
int foo(int x) {
static if (isSafe!baz) {
return baz(x);
} else {
return bar(x);
}
}
@safe int bar(int x) {
return x + 1;
}
int baz(int x) {
return x + 2;
}
unittest {
int x = 5;
int y = foo(x);
assert(y == 6);
}
More information about the Digitalmars-d
mailing list