Return value in BetterC mode.

ANtlord antlord92 at gmail.com
Sat Feb 17 07:58:40 UTC 2018


Hello!
Yesterday I found an interesting issue for myself while I was 
implementing unique pointer for my project in BetterC. When I was 
trying to return new instance from a `move` method I got calling 
of destructor the instance. When the instance is out of scope the 
calling is happens again. I also see that addresses of an 
instance that calls destructor are same.

That thing doesn't happen when I don't use BetterC mode. Is that 
bug or feature?
Please checkout code https://run.dlang.io/is/m1TRnT and try it in 
BetterC mode and in usual mode.

But if I return result of a constructor directly instead of 
saving the result to variable and returning the variable from the 
`move` method I don't see double calling of the same destructor.

I. e.
```
auto newObject = Box(this);
return newObject;
```
is replaced by
```
return Box(this);
```

So... is that bug or feature?


More information about the Digitalmars-d-learn mailing list