On Wed, May 11, 2022 at 03:34:12PM +0000, Paul Backus via Digitalmars-d-learn wrote: > On Wednesday, 11 May 2022 at 15:10:28 UTC, Tejas wrote: > > That'll be true the day when `@safe` becomes the default... Until > > then, I'll atleast do `@safe:` on top of every module :) > > `@safe:` is actually a bad idea if you're writing templated code, > because it turns inference of `@system` into a compile-time error:
Yeah, for templated code, what you want is a @safe unittest that ensures that the code is @safe when whatever you instantiate it with is @safe: auto myTemplateFunc(Args...)(Args args) /* N.B.: no attributes */ { return ...; } @safe unittest { // This ensures that myTemplateFunc is callable from // @safe when instantiated with @safe arguments. auto result = myTemplateFunc(... /* @safe arguments */); } This way, it's possible to instantiate myTemplateFunc with @system arguments (you get a @system instantiation). T -- Life is unfair. Ask too much from it, and it may decide you don't deserve what you have now either.