On 01/08/2026 3:10 AM, H. S. Teoh wrote:
On Fri, Jul 31, 2026 at 02:53:23PM +0000, user1234 via Digitalmars-d-learn
wrote:
On Friday, 31 July 2026 at 13:52:12 UTC, Vindex9 wrote:
Is this code normal? Why can't it be marked with `@safe`? Can only
`idup` be used for `@safe` in such cases?
```d
string fn() @trusted pure {
char[] arr;
// some manipulations...
return cast(string) arr;
}
```
Where is the line between cases where the `@trusted` tag can be used and
cases where the `@system` tag can be used?
[...]
If the function is pure, you should be able to just return char[] and
the caller will be able to assign it to string. No need for a cast.
Just specify the return type as `char[]`.
T
```d
string foo(ref char[] val) pure {
char[] temp;
temp ~= '2';
val = temp;
return cast(string)temp;
}
```
And this is why it isn't special cased and allowed to happen.
Pure in D isn't very strong.