Thread overview
[Issue 17977] [DIP1000] destructor allows escaping reference to a temporary struct instance
[Issue 17977] [scope] escaping reference to a temporary struct instance
Nov 10, 2017
Walter Bright
Mar 03, 2018
Walter Bright
Aug 07
Dennis
5 days ago
Dlang Bot
5 days ago
Dlang Bot
November 10, 2017
https://issues.dlang.org/show_bug.cgi?id=17977

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=12625

--
March 03, 2018
https://issues.dlang.org/show_bug.cgi?id=17977

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--
August 07
https://issues.dlang.org/show_bug.cgi?id=17977

Dennis <dkorpel@live.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |Vision
                 CC|                            |dkorpel@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@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.

--
5 days ago
https://issues.dlang.org/show_bug.cgi?id=17977

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel updated dlang/dmd pull request #13349 "Fix issue 17977 - destructor allows escaping reference to a temporary struct instance" fixing this issue:

- Fix issue 17977 - destructor allows escaping reference to a temporary struct instance

https://github.com/dlang/dmd/pull/13349

--
5 days ago
https://issues.dlang.org/show_bug.cgi?id=17977

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #13349 "Fix issue 17977 - destructor allows escaping reference to a temporary struct instance" was merged into master:

- 18dbe73c01fa992a859b1b09de69a53c04259474 by dkorpel:
  Fix issue 17977 - destructor allows escaping reference to a temporary struct
instance

https://github.com/dlang/dmd/pull/13349

--