[Issue 2483] DMD allows assignment to a scope variable
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 22 06:10:30 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2483
Denis <verylonglogin.reg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |verylonglogin.reg at gmail.com
Version|1.037 |D1 & D2
--- Comment #1 from Denis <verylonglogin.reg at gmail.com> 2012-01-22 17:10:28 MSK ---
This bug leads to not calling destructor for the stack object and deleting the
last heap object instead:
---
import std.stdio;
scope class C {
int n;
this(int n) { writefln(" this(%s) at %s", this.n = n, cast(void*)this); }
~this() { writefln("~this(%s) at %s", n, cast(void*)this); }
}
void main() {
int i;
writefln("Stack is at %s", &i);
writefln("Heap is at %s", (new void[1]).ptr);
{
scope C c = new C(1); // at stack, never destroyed
c = new C(2); // at heap, destroyed on collect
c = new C(3); // ditto
c = new C(4); // at heap, destroyed on scope exit
}
writeln("after scope");
}
---
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list