digitalmars.D.bugs - [Issue 4214] New: Rebinding of scoped class references
- d-bugmail puremagic.com (44/44) May 20 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4214
- d-bugmail puremagic.com (8/8) May 20 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4214
- d-bugmail puremagic.com (15/15) Jan 22 2012 http://d.puremagic.com/issues/show_bug.cgi?id=4214
http://d.puremagic.com/issues/show_bug.cgi?id=4214 Summary: Rebinding of scoped class references Product: D Version: future Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc This is a D2 program: import std.stdio: printf; class Foo { int x; this(int xx) { this.x = xx; } ~this() { printf("Foo(%d) destructor\n", this.x); } } void main() { scope Foo f1 = new Foo(1); Foo f2 = new Foo(2); f1 = f2; } With DMD v2.046 it compiles and at runtime it prints just: Foo(2) destructor If the Foo(1) object was meant to be deallocated at the end of the scope of main(), this program can cause problems. I can see two solutions: 1) Disallow the overwriting (rebinding) of references of scoped objects. This can be acceptable. 2) The right semantics of the code I have written there seems that both F(1) and F(2) objects have to be allocated with main() ends. So the compiler can look if inside main() the f1 is written over. If it's never written over in main(), then it can act normally. Otherwise at runtime at the end of the scope of main() the runtime can look at the f1 reference, if it refers to the object actually allocated on the stack, then it can act normally. If it points elsewhere then the runtime can call the destructor of both the object on the stack and the object referenced. I am not sure if this can be done. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 20 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4214 Sorry, I meant: 2) The right semantics of the code I have written there seems to be: both F(1) and F(2) objects need to be deallocated when main() ends. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 20 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4214 Denis <verylonglogin.reg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |verylonglogin.reg gmail.com Resolution| |DUPLICATE --- http://d-p-l.org/attribute.html#scope "Assignment to a scope, other than initialization, is not allowed." *** This issue has been marked as a duplicate of issue 2483 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 22 2012