Bug 18128 – [scope] escaping reference to class allocated on the stack

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-12-25T20:24:16Z
Last change time
2018-01-03T17:53:46Z
Keywords
safe
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2017-12-25T20:24:16Z
class A { int i; } void inc(A a) @safe { a.i += 1; // Line 6 } auto makeA() @safe { // Line 9 import std.algorithm : move; scope a = new A(); // allocates object on the stack instead of the heap return move(a); // should give an error } void main() @safe { auto a = makeA(); a.inc(); // Line 17 }
Comment #1 by code — 2018-01-03T17:53:46Z
That's already fixed with 2.078.0, `move` was recently annotated as T move(T)(return scope ref T source) see issue 17730. *** This issue has been marked as a duplicate of issue 17730 ***