[Issue 17977] [DIP1000] destructor allows escaping reference to a temporary struct instance
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Aug 7 18:50:58 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=17977
Dennis <dkorpel at live.nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |Vision
CC| |dkorpel at live.nl
Summary|[scope] escaping reference |[DIP1000] destructor allows
|to a temporary struct |escaping reference to a
|instance |temporary struct instance
--- Comment #1 from Dennis <dkorpel at live.nl> ---
The issue description looks incomplete, but I gather this is an accepts-invalid
bug in DIP1000 and the comment shows the expected error? Currently I see
nothing wrong: `List()` is not scope, and `front()` does not return by ref, so
there's no references escaping here. I tried fixing and reducing the code, and
I think this is the actual issue:
```
// compile with -preview=dip1000
@safe:
struct List {
int* data;
~this();
int* front() return;
}
void test() {
auto elem = List().front;
}
```
Without the destructor, there's an error:
> onlineapp.d(11): Error: address of struct literal `List(null)` assigned
> to longer lived variable `elem`
Commenting it out makes it go away, which is wrong.
--
More information about the Digitalmars-d-bugs
mailing list