On Sun, May 16, 2021 at 06:33:04PM +0000, Alain De Vos via Digitalmars-d-learn wrote: > On Sunday, 16 May 2021 at 18:27:40 UTC, H. S. Teoh wrote: [...] > > ---------snip--------- > > import std.stdio:writeln; > > > > int [] fun() @safe { // N.B.: need @safe > > int[3]s=[1,2,3]; > > int[] r=s; > > return r; > > } > > > > void main() @safe { // N.B.: need @safe > > writeln(fun()[0]); > > } > > ---------snip--------- > > > > > > LDC output: > > > > ---------snip--------- > > $ ldc2 -dip1000 /tmp/test.d > > /tmp/test.d(6): Error: scope variable `r` may not be returned > > ---------snip--------- [...] > So I put everywhere @safe ?
Or put `@safe:` at the top of the file. > When not ? Sometimes when you need to perform a system operation that you know is safe, but the compiler cannot prove is safe. Or you need to call a @system function (e.g. a C library). T -- Маленькие детки - маленькие бедки.