[Issue 6931] scope parameter storage class not checked at all
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Jan 22 06:47:30 PST 2012
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=6931
Denis <verylonglogin.reg at gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg at gmail.com
--- Comment #1 from Denis <verylonglogin.reg at gmail.com> 2012-01-22 17:47:29 MSK ---
If we will look at destruction & allocation:
---
import std.stdio;
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);
    {
        C cHeap = new C(0); // will be destroyed on scope exit
        scope C c0 = cHeap;
        // C(1)-C(4) will be allocated in heap
        // C(1), C(2), and C(4) will be destroyed on scope exit
        // C(3) will be destroyed on garbage collection
        scope C c1 = cast(C)cast(void*)new C(1);
        scope C c2 = true ? new C(2) : null;
        scope C c3 = (new C(3), new C(4));
    }
    writefln("after scope");
}
---
As a result even if `C` is a `scope class` the program will compile without
`cHeap` and `c0`, but every `C` instance will be allocated in heap and C(3)
will be destroyed on garbage collection.
-- 
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