Bug 20880 – [DIP1000] Temporaries escape innards absent destructor

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-29T21:09:07Z
Last change time
2021-05-25T18:13:08Z
Assigned to
No Owner
Creator
Stanislav Blinov

Comments

Comment #0 by stanislav.blinov — 2020-05-29T21:09:07Z
This behavior is, at the very least, inconsistent. Furthermore, with dtor uncommented, resulting error message for the second test is somewhat cryptic. // dmd -dip1000 @safe: struct S { private int* ptr; // Uncomment following line to make both tests fail to compile //~this() {} int* get() return { return ptr; } } // With dtor commented, this fails to compile (as expected) unittest { S s; // NOTE: lambda is unnecessary, it is here solely // to document expected behavior of the second test int* outlive = { S temporary; return temporary.get(); } (); } // With dtor commented, this compiles unittest { int* outlive = S().get(); }
Comment #1 by snarwin+bugzilla — 2021-05-25T18:13:08Z
As of DMD 2.096.1, both unittests fail to compile, with the following error messages: --- bug.d(18): Error: returning `temporary.get()` escapes a reference to local variable `temporary` bug.d(24): Error: address of struct literal `S(null)` assigned to longer lived variable `outlive` ---