D not considered memory safe

Timon Gehr timon.gehr at gmx.ch
Tue Jul 9 00:37:13 UTC 2024


On 7/9/24 01:21, Walter Bright wrote:
> On 7/6/2024 9:10 PM, Steven Schveighoffer wrote:
>> Typing @safe: is also incorrect. You will cause your templates to fail 
>> to compile.
> 
> ??
> 

Templates are inferred by default:

```d
auto call(alias a)(){ a(); }

@safe void foo(){}
@system void bar(){}

@safe void fun(){ call!fun(); }
@system void gun(){ call!bar(); }
```

If you annotate `call` with `@safe`, some of those calls will no longer 
work. It removes functionality even though it was already compatible 
with `@safe` code.

`@safe:` will put `@safe` on all your function templates, which will 
make them not work in `@system` contexts even if they worked before.

The issue is that it applies the attribute, when what is needed is a way 
to change the default attribute.


More information about the Digitalmars-d mailing list