www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is is a Bug or just me?

reply foerdi <dlang foerdi.net> writes:
Hi d community,

I got a strange behavior since dmd 2.090 (dmd 2.089 is the last 
working version).

See this reduced code: https://run.dlang.io/is/yoyHXC

I would expect that foo() returns 2.
My guess in foo is: The return value of val is saved locally as a 
ref int and then the destructor of S is called (set the local 
cache to 0). Now the ref value is dereferenced and returned.

Now I am unsure if this is a bug or an undefined behavior that I 
don't know.
If this is a bug, then I don't know how to call it for the bug 
tracker.

I hope you can help me with this problem.

PS: This is only tested on my Linux system and on run.dlang.io.

- foerdi
May 08 2020
next sibling parent reply kinke <noone nowhere.com> writes:
On Friday, 8 May 2020 at 14:16:10 UTC, foerdi wrote:
 Now I am unsure if this is a bug or an undefined behavior that 
 I don't know.
This is a regression, and a potentially pretty bad one, so thx for tracking it down!
 If this is a bug, then I don't know how to call it for the bug 
 tracker.
Maybe something like 'return statement might access memory from destructed temporary'.
May 08 2020
parent foerdi <dlang foerdi.net> writes:
On Friday, 8 May 2020 at 14:32:33 UTC, kinke wrote:
 On Friday, 8 May 2020 at 14:16:10 UTC, foerdi wrote:
 Now I am unsure if this is a bug or an undefined behavior that 
 I don't know.
This is a regression, and a potentially pretty bad one, so thx for tracking it down!
 If this is a bug, then I don't know how to call it for the bug 
 tracker.
Maybe something like 'return statement might access memory from destructed temporary'.
Thanks, I filed a regression: https://issues.dlang.org/show_bug.cgi?id=20809
May 08 2020
prev sibling parent bauss <jj_1337 live.dk> writes:
On Friday, 8 May 2020 at 14:16:10 UTC, foerdi wrote:
 Hi d community,

 I got a strange behavior since dmd 2.090 (dmd 2.089 is the last 
 working version).

 See this reduced code: https://run.dlang.io/is/yoyHXC

 I would expect that foo() returns 2.
 My guess in foo is: The return value of val is saved locally as 
 a ref int and then the destructor of S is called (set the local 
 cache to 0). Now the ref value is dereferenced and returned.

 Now I am unsure if this is a bug or an undefined behavior that 
 I don't know.
 If this is a bug, then I don't know how to call it for the bug 
 tracker.

 I hope you can help me with this problem.

 PS: This is only tested on my Linux system and on run.dlang.io.

 - foerdi
Gets even weirder because this fixes it LOL??? int foo() out { } do { return bar.val; } What the??
May 09 2020