May 16, 2021
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

-- 
Маленькие детки - маленькие бедки.
May 16, 2021
On Sunday, 16 May 2021 at 18:30:49 UTC, Alain De Vos wrote:
> Is there a list of compiler flags not shown ?

ldc2 -help-hidden
May 17, 2021
Thanks. Alot of info,but the flag dip1000 is not show in help hidden.

The solution seems to be compiling with flag dip1000 and putting @safe on top on the file then all the errors are catched by the compiler.
May 17, 2021
I now compile with the following flags,
```
# DIP25 , return ref
# DIP1000 , scoped pointers
# --boundscheck=on , perform array bounds check
# --safe-stack-layout , enable safe stack layout
#--D , generate documentation,
#--g , symbolic  debug info
#--d-debug ,it enables all debug checks (i.e. asserts, boundschecks, contracts and invariants) as well as acting as -d-debug=1.
#--w , treat warning as error
#--de: halt on deprecated
ldc2 --dip1000 --dip25 --safe-stack-layout --boundscheck=on --D --g --w --de --d-debug test.d
```
May 22, 2021
On Sunday, 16 May 2021 at 18:27:40 UTC, H. S. Teoh wrote:
> On Sun, May 16, 2021 at 05:24:40PM +0000, Alain De Vos via Digitalmars-d-learn wrote:
>> On Sunday, 16 May 2021 at 16:58:15 UTC, H. S. Teoh wrote:
>> > On Sun, May 16, 2021 at 04:40:53PM +0000, Alain De Vos via Digitalmars-d-learn wrote:
>> > > This works also,
>> > > 
>> > > ```
>> > > import std.stdio:writeln;
>> > > 
>> > > int [] fun(){
>> > > 	int[3]s=[1,2,3];
>> > > 	int[] r=s;
>> > > 	return r;
>> > > }
>> > > 
>> > > void main(){
>> > > 	writeln(fun()[0]);
>> > > }
>> > > ```
>> > 
>> > https://issues.dlang.org/show_bug.cgi?id=15932
>> > 
>> > Though I believe if you compile with -dip25 -dip1000 the compiler should emit an error for the above code.  If not, please file a bug against -dip1000.
> [...]
>> I use ldc2. No dip flags here.
>
> ---------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---------
>
>
> T

Trying @safe is painfull in practice.
Large parge of functions are not @safe and call functions which are not @safe.
Only tiny end-subroutines i can put @safe.
1 2
Next ›   Last »