Re: stack out of scope ?

2021-05-22 Thread Alain De Vos via Digitalmars-d-learn
On Sunday, 16 May 2021 at 18:27:40 UTC, H. S. Teoh wrote: On Sun, May 16, 2021 at 05:24:40PM +, 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 +, Alain De Vos via > Digitalmars-d-learn wrote: >

Re: stack out of scope ?

2021-05-17 Thread Alain De Vos via Digitalmars-d-learn
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.

Re: stack out of scope ?

2021-05-17 Thread Alain De Vos via Digitalmars-d-learn
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.

Re: stack out of scope ?

2021-05-16 Thread Kyle via Digitalmars-d-learn
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

Re: stack out of scope ?

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 16, 2021 at 06:33:04PM +, 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 > >

Re: stack out of scope ?

2021-05-16 Thread Alain De Vos via Digitalmars-d-learn
On Sunday, 16 May 2021 at 18:27:40 UTC, H. S. Teoh wrote: On Sun, May 16, 2021 at 05:24:40PM +, 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 +, Alain De Vos via > Digitalmars-d-learn wrote: >

Re: stack out of scope ?

2021-05-16 Thread Alain De Vos via Digitalmars-d-learn
Is there a list of compiler flags not shown ?

Re: stack out of scope ?

2021-05-16 Thread Alain De Vos via Digitalmars-d-learn
the flag dip1000 was not shown in the help file. And indeed for the second program compiling with dip1000 results in, test.d(6): Error: scope variable r may not be returned But the first program still compiles and runs without problem, even with dip1000.

Re: stack out of scope ?

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 16, 2021 at 05:24:40PM +, 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 +, Alain De Vos via > > Digitalmars-d-learn wrote: > > > This works also, > > > > > > ``` > > > import

Re: stack out of scope ?

2021-05-16 Thread ag0aep6g via Digitalmars-d-learn
On 16.05.21 19:24, Alain De Vos wrote: On Sunday, 16 May 2021 at 16:58:15 UTC, H. S. Teoh wrote: [...] 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. T I use ldc2. No dip flags here.

Re: stack out of scope ?

2021-05-16 Thread Alain De Vos via Digitalmars-d-learn
On Sunday, 16 May 2021 at 16:58:15 UTC, H. S. Teoh wrote: On Sun, May 16, 2021 at 04:40:53PM +, 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(){

Re: stack out of scope ?

2021-05-16 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/16/21 12:32 PM, Alain De Vos wrote: Why doesn't this program dups core ? Is s not recycled ? ``` import std.stdio:writeln; void main(){ //I point to the heap int[] p=[1,2,3]; {     int[3]s=[1,2,3];     //I point to the stack     p=s; } //Why do I still live ?

Re: stack out of scope ?

2021-05-16 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, May 16, 2021 at 04:40:53PM +, 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]); > } > ```

Re: stack out of scope ?

2021-05-16 Thread Alain De Vos via Digitalmars-d-learn
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]); } ```