Simplification of @trusted
RazvanN
razvan.nitu1305 at gmail.com
Wed Jun 16 11:38:54 UTC 2021
Currently, @trusted applies only to functions. This is most of
the times a pain when you want trusted code blocks inside
functions. Why not simplify it a bit by using trusted scope
blocks? E.g. this:
```d
void foo() @safe
{
() @trusted { ... }();
}
```
becomes this:
```d
void foo() @safe
{
@trusted
{
....
}
}
```
To make things easier, @trusted does not insert a scope (similar
to `static if`).
Of course, the feature would be additive (you can have both
trusted functions and code blocks).
That would also provide an elegant workaround if void
initialization is rejected in @safe code [1][2]. For example:
```d
void foo() @safe
{
@trusted
{
int[100] a = void;
}
...
}
```
What do you think?
Cheers,
RazvanN
[1] https://issues.dlang.org/show_bug.cgi?id=17566
[2] https://github.com/dlang/dlang.org/pull/2260
More information about the Digitalmars-d
mailing list